mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Upgraded visualization libraries
Major refactoring of color legend framework Added discrete log color legend p4#: 18989
This commit is contained in:
@@ -76,13 +76,3 @@ cvfVector4.cpp
|
||||
|
||||
add_library(${PROJECT_NAME} ${CEE_HEADER_FILES} ${CEE_SOURCE_FILES})
|
||||
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set ( EXTERNAL_LINK_LIBRARIES
|
||||
rt
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
target_link_libraries(LibCore ${EXTERNAL_LINK_LIBRARIES})
|
||||
|
||||
|
||||
@@ -174,7 +174,8 @@ namespace cvf {
|
||||
/// \class cvf::Base64
|
||||
/// \ingroup Core
|
||||
///
|
||||
///
|
||||
/// Base64 encoding and decoding for representing binary data in an ASCII string format by
|
||||
/// translating it into a radix-64 representation.
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
|
||||
@@ -27,16 +27,14 @@ namespace cvf {
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Base64 encoding and decoding for representing binary data in an ASCII string format by
|
||||
// translating it into a radix-64 representation.
|
||||
// Base64 encoding and decoding for representing binary data in an ASCII string
|
||||
//
|
||||
//==================================================================================================
|
||||
class Base64
|
||||
{
|
||||
public:
|
||||
static std::string encode(const cvf::UByteArray& data);
|
||||
static cvf::ref<cvf::UByteArray> decode(const std::string& encodedData);
|
||||
|
||||
static std::string encode(const cvf::UByteArray& data);
|
||||
static cvf::ref<cvf::UByteArray> decode(const std::string& encodedData);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -39,12 +39,15 @@ public:
|
||||
Matrix3(S m00, S m01, S m02, S m10, S m11, S m12, S m20, S m21, S m22);
|
||||
|
||||
template<typename T>
|
||||
explicit Matrix3(const T& other);
|
||||
explicit Matrix3(const Matrix3<T>& other);
|
||||
|
||||
inline Matrix3& operator=(const Matrix3& rhs);
|
||||
|
||||
bool equals(const Matrix3& mat) const;
|
||||
bool operator==(const Matrix3& rhs) const;
|
||||
bool operator!=(const Matrix3& rhs) const;
|
||||
|
||||
void multiply(const Matrix3& mat);
|
||||
const Matrix3 operator*(const Matrix3& rhs) const;
|
||||
|
||||
void setIdentity();
|
||||
@@ -52,10 +55,10 @@ public:
|
||||
void setZero();
|
||||
bool isZero() const;
|
||||
|
||||
inline S& operator()(int row, int col);
|
||||
inline S operator()(int row, int col) const;
|
||||
inline void setRowCol(int row, int col, S value);
|
||||
inline S rowCol(int row, int col) const;
|
||||
inline S& operator()(int row, int col);
|
||||
inline S operator()(int row, int col) const;
|
||||
|
||||
bool invert();
|
||||
const Matrix3 getInverted(bool* pInvertible = NULL) const;
|
||||
|
||||
@@ -89,7 +89,7 @@ Matrix3<S>::Matrix3(S m00, S m01, S m02, S m10, S m11, S m12, S m20, S m21, S m2
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
template<typename T>
|
||||
Matrix3<S>::Matrix3(const T& other)
|
||||
Matrix3<S>::Matrix3(const Matrix3<T>& other)
|
||||
{
|
||||
m_v[e00] = static_cast<S>(other.rowCol(0, 0));
|
||||
m_v[e01] = static_cast<S>(other.rowCol(0, 1));
|
||||
@@ -114,19 +114,28 @@ inline Matrix3<S>& Matrix3<S>::operator=(const Matrix3& obj)
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/// Check if matrices are equal using exact comparisons.
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
bool Matrix3<S>::equals(const Matrix3& mat) const
|
||||
{
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
if (m_v[i] != mat.m_v[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/// Comparison operator. Checks for equality using exact comparisons.
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
template <typename S>
|
||||
bool Matrix3<S>::operator==(const Matrix3& rhs) const
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 9; i++)
|
||||
{
|
||||
if (m_v[i] != rhs.m_v[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return this->equals(rhs);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +155,16 @@ bool Matrix3<S>::operator!=(const Matrix3& rhs) const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Multiplies this matrix M with the matrix \a mat, M = M*mat
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void Matrix3<S>::multiply(const Matrix3& mat)
|
||||
{
|
||||
*this = (*this)*mat;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -44,12 +44,15 @@ public:
|
||||
explicit Matrix4(const Matrix3<S>& other);
|
||||
|
||||
template<typename T>
|
||||
explicit Matrix4(const T& other);
|
||||
explicit Matrix4(const Matrix4<T>& other);
|
||||
|
||||
inline Matrix4& operator=(const Matrix4& rhs);
|
||||
|
||||
bool equals(const Matrix4& mat) const;
|
||||
bool operator==(const Matrix4& rhs) const;
|
||||
bool operator!=(const Matrix4& rhs) const;
|
||||
|
||||
void multiply(const Matrix4& mat);
|
||||
const Matrix4 operator*(const Matrix4& rhs) const;
|
||||
const Vector4<S> operator*(const Vector4<S>& rhs) const;
|
||||
|
||||
@@ -58,10 +61,10 @@ public:
|
||||
void setZero();
|
||||
bool isZero() const;
|
||||
|
||||
inline S& operator()(int row, int col);
|
||||
inline S operator()(int row, int col) const;
|
||||
inline void setRowCol(int row, int col, S value);
|
||||
inline S rowCol(int row, int col) const;
|
||||
inline S& operator()(int row, int col);
|
||||
inline S operator()(int row, int col) const;
|
||||
|
||||
void setRow(int row, const Vector4<S>& vector);
|
||||
Vector4<S> row(int row) const;
|
||||
@@ -89,6 +92,7 @@ public:
|
||||
inline const S* ptr() const;
|
||||
|
||||
static Matrix4 fromTranslation(const Vector3<S>& trans);
|
||||
static Matrix4 fromScaling(const Vector3<S>& scale);
|
||||
static Matrix4 fromRotation(Vector3<S> axis, S angle);
|
||||
static Matrix4 fromCoordSystemAxes(const Vector3<S>* xAxis, const Vector3<S>* yAxis, const Vector3<S>* zAxis);
|
||||
|
||||
@@ -107,6 +111,7 @@ private:
|
||||
S m_v[16];
|
||||
};
|
||||
|
||||
|
||||
template<typename S>
|
||||
Vector4<S> operator*(const Matrix4<S>& m, const Vector4<S>& v);
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ Matrix4<S>::Matrix4(const Matrix3<S>& other)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
template<typename T>
|
||||
Matrix4<S>::Matrix4(const T& other)
|
||||
Matrix4<S>::Matrix4(const Matrix4<T>& other)
|
||||
{
|
||||
m_v[e00] = static_cast<S>(other.rowCol(0, 0));
|
||||
m_v[e10] = static_cast<S>(other.rowCol(1, 0));
|
||||
@@ -163,19 +163,29 @@ inline Matrix4<S>& Matrix4<S>::operator=(const Matrix4& obj)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/// Check if matrices are equal using exact comparisons.
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
bool Matrix4<S>::equals(const Matrix4& mat) const
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
if (m_v[i] != mat.m_v[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/// Comparison operator. Checks for equality using exact comparisons.
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
template <typename S>
|
||||
bool Matrix4<S>::operator==(const Matrix4& rhs) const
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if (m_v[i] != rhs.m_v[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return this->equals(rhs);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +205,16 @@ bool Matrix4<S>::operator!=(const Matrix4& rhs) const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Multiplies this matrix M with the matrix \a mat, M = M*mat
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void Matrix4<S>::multiply(const Matrix4& mat)
|
||||
{
|
||||
*this = (*this)*mat;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -497,9 +517,9 @@ void Matrix4<S>::setTranslation(const Vector3<S>& trans)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/// Adds translation by pre-multiplying the matrix with a matrix containing the specified translation
|
||||
///
|
||||
/// Adds translation to this (transformation) matrix by pre multiplying the current matrix M with
|
||||
/// a matrix containing the specified translation. Calling this function has the effect of doing the
|
||||
/// multiplication T x M where T is a matrix that only contains translation.
|
||||
/// Adds translation to this (transformation) matrix by pre-multiplying the current matrix M with
|
||||
/// a matrix T containing only the specified translation.
|
||||
/// Calling this function has the effect of doing the multiplication M' = T x M
|
||||
///
|
||||
/// \param trans Specifies the X, Y and Z components of the translation.
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -526,9 +546,9 @@ void Matrix4<S>::translatePreMultiply(const Vector3<S>& trans)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/// Adds translation by post-multiplying the matrix with a matrix containing the specified translation
|
||||
///
|
||||
/// Adds translation to this (transformation) matrix by post multiplying the current matrix M with
|
||||
/// a matrix containing the specified translation. Calling this function has the effect of doing the
|
||||
/// multiplication M x T where T is a matrix that only contains translation.
|
||||
/// Adds translation to this (transformation) matrix by post-multiplying the current matrix M with
|
||||
/// a matrix T containing only the specified translation.
|
||||
/// Calling this function has the effect of doing the multiplication M' = M x T
|
||||
///
|
||||
/// \param trans Specifies the X, Y and Z coordinates of the translation.
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -770,6 +790,19 @@ Matrix4<S> Matrix4<S>::fromTranslation(const Vector3<S>& trans)
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/// Static member function that creates a transformation matrix containing only scaling
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
template <typename S>
|
||||
Matrix4<S> Matrix4<S>::fromScaling(const Vector3<S>& scale)
|
||||
{
|
||||
return Matrix4(scale.x(), 0, 0, 0,
|
||||
0, scale.y(), 0, 0,
|
||||
0, 0, scale.z(), 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace cvf {
|
||||
///
|
||||
/// Class defining a plane in space
|
||||
///
|
||||
/// The class describes a plane by the equation: \f$Ax + By + Cz + Dx = 0\f$
|
||||
/// The class describes a plane by the equation: \f$Ax + By + Cz + D = 0\f$
|
||||
/// The plane's normal is defined by the coefficients \f$[A, B, C]\f$
|
||||
///
|
||||
//==================================================================================================
|
||||
@@ -425,6 +425,114 @@ bool Plane::intersect(const Plane& other, Vec3d* point, Vec3d* direction) const
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Find intersection between a line segment and a plane
|
||||
///
|
||||
/// \param a Start of line segment
|
||||
/// \param b End of line segment
|
||||
/// \param intersection Returns intersection point if not NULL
|
||||
///
|
||||
/// \return True if line segment intersects the plane
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Plane::intersect(const Vec3d& a, const Vec3d& b, Vec3d* intersection) const
|
||||
{
|
||||
// From Real-Time Collision Detection by Christer Eriscon, published by Morgen Kaufmann Publishers, (c) 2005 Elsevier Inc
|
||||
|
||||
// Compute the t value for the directed line ab intersecting the plane
|
||||
Vec3d ab = b - a;
|
||||
double t = (-m_D - (normal() * a)) / (normal() * ab);
|
||||
|
||||
// If t in [0..1] compute and return intersection point
|
||||
if (t >= 0.0 && t <= 1.0)
|
||||
{
|
||||
if (intersection)
|
||||
{
|
||||
*intersection = a + t * ab;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Classify where the point is located relative to the plane
|
||||
///
|
||||
/// \return Plane::FRONT if the point is located on the side the plane normal is pointing\n
|
||||
/// Plane::BACK if the point is located on the opposite side the plane normal is pointing\n
|
||||
/// Plane::ON if the point is located in the plane
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Plane::Side Plane::side(const Vec3d& point) const
|
||||
{
|
||||
double d = distanceSquared(point);
|
||||
|
||||
if (d > 0.0)
|
||||
{
|
||||
return FRONT;
|
||||
}
|
||||
else if (d < 0.0)
|
||||
{
|
||||
return BACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ON;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Classify where the points are located relative to the plane
|
||||
///
|
||||
/// \param points Points to test for location relative the plane
|
||||
///
|
||||
/// \return Plane::FRONT if points are either Plane::FRONT or Plane::ON\n
|
||||
/// Plane::BACK if points are either Plane::BACK or Plane::ON\n
|
||||
/// Plane::ON if all points are Plane::ON\n
|
||||
/// Plane::BOTH if points are located on both sides
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Plane::Side Plane::side(const Vec3dArray& points) const
|
||||
{
|
||||
// Code taken from
|
||||
// http://code.google.com/p/papervision3d/source/browse/trunk/as3/trunk/src/org/papervision3d/core/math/util/ClassificationUtil.as
|
||||
|
||||
cvf::uint frontCount = 0;
|
||||
cvf::uint backCount = 0;
|
||||
|
||||
for (size_t i = 0; i < points.size(); i++)
|
||||
{
|
||||
Side s = side(points[i]);
|
||||
|
||||
if (s == FRONT)
|
||||
{
|
||||
frontCount++;
|
||||
}
|
||||
else if (s == BACK)
|
||||
{
|
||||
backCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (frontCount > 0 && backCount == 0)
|
||||
{
|
||||
return FRONT;
|
||||
}
|
||||
else if (frontCount == 0 && backCount > 0)
|
||||
{
|
||||
return BACK;
|
||||
}
|
||||
else if (frontCount > 0 && backCount > 0)
|
||||
{
|
||||
return BOTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ON;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "cvfObject.h"
|
||||
#include "cvfVector3.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cvfArray.h"
|
||||
|
||||
|
||||
namespace cvf {
|
||||
@@ -33,6 +34,9 @@ namespace cvf {
|
||||
//=================================================================================================
|
||||
class Plane : public Object
|
||||
{
|
||||
public:
|
||||
enum Side { FRONT, BACK, ON, BOTH };
|
||||
|
||||
public:
|
||||
Plane();
|
||||
Plane(double A, double B, double C, double D);
|
||||
@@ -68,6 +72,10 @@ public:
|
||||
Vec3d projectPoint(const Vec3d& point) const;
|
||||
|
||||
bool intersect(const Plane& other, Vec3d* point, Vec3d* direction = NULL) const;
|
||||
bool intersect(const Vec3d& a, const Vec3d& b, Vec3d* intersection) const;
|
||||
|
||||
Side side(const Vec3d& point) const;
|
||||
Side side(const Vec3dArray& points) const;
|
||||
|
||||
private:
|
||||
double m_A; // Plane equation coefficients
|
||||
|
||||
@@ -202,7 +202,8 @@ void Quat<S>::toAxisAngle(Vector3<S>* rotationAxis, S* angle) const
|
||||
Quat nQ(*this);
|
||||
nQ.normalize();
|
||||
|
||||
S cos_a = nQ.m_w;
|
||||
// Clamp to acos' input domain
|
||||
S cos_a = Math::clamp(nQ.m_w, static_cast<S>(-1), static_cast<S>(1));
|
||||
*angle = 2*Math::acos(cos_a);
|
||||
|
||||
S sin_a = Math::sqrt(1 - cos_a*cos_a);
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
void setHeight(T height);
|
||||
|
||||
bool isValid() const;
|
||||
void normalize();
|
||||
|
||||
void include(const Vector2<T>& coord);
|
||||
void include(const Rect& rect);
|
||||
@@ -57,8 +58,6 @@ public:
|
||||
bool contains(const Vector2<T>& coord) const;
|
||||
bool intersects(const Rect& rect) const;
|
||||
|
||||
void normalize();
|
||||
|
||||
void translate(const Vector2<T>& offset);
|
||||
|
||||
bool segmentIntersect(const Vec2d& p1, const Vec2d& p2, Vec2d* intersect1, Vec2d* intersect2);
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace cvf {
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -48,7 +49,6 @@ template <typename T>
|
||||
Rect<T>::Rect(T minX, T minY, T width, T height)
|
||||
{
|
||||
m_minPos.set(minX, minY);
|
||||
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
}
|
||||
@@ -186,7 +186,30 @@ void Rect<T>::setHeight(T height)
|
||||
template <typename T>
|
||||
bool Rect<T>::isValid() const
|
||||
{
|
||||
return m_width > 0.0 && m_height > 0.0;
|
||||
return (m_width > 0.0) && (m_height > 0.0);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Normalizes the rectangle
|
||||
///
|
||||
/// Ensures that the rectangle has a non-negative width and height. If width or height is negative,
|
||||
/// the corresponding min component will be moved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void Rect<T>::normalize()
|
||||
{
|
||||
if (m_width < 0.0)
|
||||
{
|
||||
m_width = -m_width;
|
||||
m_minPos.x() -= m_width;
|
||||
}
|
||||
|
||||
if (m_height < 0.0)
|
||||
{
|
||||
m_height = -m_height;
|
||||
m_minPos.y() -= m_height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,12 +263,16 @@ void Rect<T>::include(const Rect& rect)
|
||||
|
||||
T left = m_minPos.x();
|
||||
T right = m_minPos.x();
|
||||
if (m_width < 0)
|
||||
if (m_width < 0.0)
|
||||
{
|
||||
left += m_width;
|
||||
}
|
||||
else
|
||||
{
|
||||
right += m_width;
|
||||
}
|
||||
|
||||
if (rect.width() < 0)
|
||||
if (rect.width() < 0.0)
|
||||
{
|
||||
left = CVF_MIN(left, rect.min().x() + rect.width());
|
||||
right = CVF_MAX(right, rect.min().x());
|
||||
@@ -258,7 +285,7 @@ void Rect<T>::include(const Rect& rect)
|
||||
|
||||
T bottom = m_minPos.y();
|
||||
T top = m_minPos.y();
|
||||
if (m_height < 0)
|
||||
if (m_height < 0.0)
|
||||
{
|
||||
bottom += m_height;
|
||||
}
|
||||
@@ -267,7 +294,7 @@ void Rect<T>::include(const Rect& rect)
|
||||
top += m_height;
|
||||
}
|
||||
|
||||
if (rect.height() < 0)
|
||||
if (rect.height() < 0.0)
|
||||
{
|
||||
bottom = CVF_MIN(bottom, rect.min().y() + rect.height());
|
||||
top = CVF_MAX(top, rect.min().y());
|
||||
@@ -285,14 +312,16 @@ void Rect<T>::include(const Rect& rect)
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Check if the rectangle contains the specified coordinate
|
||||
///
|
||||
/// Returns true if the point is inside or on the edge of the rectangle; otherwise returns false.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
bool Rect<T>::contains(const Vector2<T>& coord) const
|
||||
{
|
||||
T left = m_minPos.x();
|
||||
T right = m_minPos.x();
|
||||
if (m_width < 0)
|
||||
if (m_width < 0.0)
|
||||
{
|
||||
left += m_width;
|
||||
}
|
||||
@@ -314,7 +343,7 @@ bool Rect<T>::contains(const Vector2<T>& coord) const
|
||||
|
||||
T bot = m_minPos.y();
|
||||
T top = m_minPos.y();
|
||||
if (m_height < 0)
|
||||
if (m_height < 0.0)
|
||||
{
|
||||
bot += m_height;
|
||||
}
|
||||
@@ -346,7 +375,7 @@ bool Rect<T>::intersects(const Rect& rect) const
|
||||
{
|
||||
T left1 = m_minPos.x();
|
||||
T right1 = m_minPos.x();
|
||||
if (m_width < 0)
|
||||
if (m_width < 0.0)
|
||||
{
|
||||
left1 += m_width;
|
||||
}
|
||||
@@ -363,7 +392,7 @@ bool Rect<T>::intersects(const Rect& rect) const
|
||||
|
||||
T left2 = rect.min().x();
|
||||
T right2 = rect.min().x();
|
||||
if (rect.width() < 0)
|
||||
if (rect.width() < 0.0)
|
||||
{
|
||||
left2 += rect.width();
|
||||
}
|
||||
@@ -385,7 +414,7 @@ bool Rect<T>::intersects(const Rect& rect) const
|
||||
|
||||
T bot1 = m_minPos.y();
|
||||
T top1 = m_minPos.y();
|
||||
if (m_height < 0)
|
||||
if (m_height < 0.0)
|
||||
{
|
||||
bot1 += m_height;
|
||||
}
|
||||
@@ -402,7 +431,7 @@ bool Rect<T>::intersects(const Rect& rect) const
|
||||
|
||||
T bot2 = rect.min().y();
|
||||
T top2 = rect.min().y();
|
||||
if (rect.height() < 0)
|
||||
if (rect.height() < 0.0)
|
||||
{
|
||||
bot2 += rect.height();
|
||||
}
|
||||
@@ -426,26 +455,6 @@ bool Rect<T>::intersects(const Rect& rect) const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void Rect<T>::normalize()
|
||||
{
|
||||
if (m_width < 0)
|
||||
{
|
||||
m_width = -m_width;
|
||||
m_minPos.x() -= m_width;
|
||||
}
|
||||
|
||||
if (m_height < 0)
|
||||
{
|
||||
m_height = -m_height;
|
||||
m_minPos.y() -= m_height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -462,8 +471,11 @@ void Rect<T>::translate(const Vector2<T>& offset)
|
||||
template <typename T>
|
||||
Rect<T> Rect<T>::fromMinMax(const Vector2<T>& min, const Vector2<T>& max)
|
||||
{
|
||||
Rect<T> rect(min, max.x() - min.x(), max.y() - min.y());
|
||||
// Enforce min/max - otherwise we'll get bogus results for unsigned types
|
||||
CVF_ASSERT(min.x() <= max.x());
|
||||
CVF_ASSERT(min.y() <= max.y());
|
||||
|
||||
Rect<T> rect(min, max.x() - min.x(), max.y() - min.y());
|
||||
return rect;
|
||||
}
|
||||
|
||||
@@ -519,7 +531,6 @@ bool Rect<T>::segmentIntersect(const Vec2d& p1, const Vec2d& p2, Vec2d* intersec
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -43,44 +43,45 @@ public:
|
||||
explicit Vector2(const T& other);
|
||||
|
||||
inline Vector2& operator=(const Vector2& rhs);
|
||||
|
||||
inline bool equals(const Vector2& other) const;
|
||||
inline bool operator==(const Vector2& rhs) const;
|
||||
inline bool operator!=(const Vector2& rhs) const;
|
||||
|
||||
inline void add(const Vector2& other);
|
||||
inline void subtract(const Vector2& other);
|
||||
inline const Vector2 operator+(const Vector2& rhs) const;
|
||||
inline const Vector2 operator-(const Vector2& rhs) const;
|
||||
inline const Vector2 operator*(S scalar) const;
|
||||
inline const Vector2 operator/(S scalar) const;
|
||||
|
||||
template<typename T>
|
||||
friend inline const Vector2<T> operator*(T scalar, const Vector2<T>& rhs);
|
||||
|
||||
inline const Vector2 operator-() const;
|
||||
|
||||
inline Vector2& operator+=(const Vector2& rhs);
|
||||
inline Vector2& operator-=(const Vector2& rhs);
|
||||
inline const Vector2 operator-() const;
|
||||
|
||||
inline void scale(S scalar);
|
||||
inline const Vector2 operator*(S scalar) const;
|
||||
inline const Vector2 operator/(S scalar) const;
|
||||
inline Vector2& operator*=(S scalar);
|
||||
inline Vector2& operator/=(S scalar);
|
||||
|
||||
inline S dot(const Vector2& other) const;
|
||||
inline S operator*(const Vector2& rhs) const; // Dot product
|
||||
|
||||
template<typename T>
|
||||
void set(const T& other);
|
||||
inline void set(S x, S y);
|
||||
inline void setZero();
|
||||
inline const S& x() const { return m_v[0]; } ///< Get the X element of the vector
|
||||
inline const S& y() const { return m_v[1]; } ///< Get the Y element of the vector
|
||||
inline S& x() { return m_v[0]; } ///< Get a reference to the X element of the vector. E.g. x() = 1;
|
||||
inline S& y() { return m_v[1]; } ///< Get a reference to the Y element of the vector. E.g. y() = 2;
|
||||
|
||||
inline const S& operator[](int index) const; // Get component 0 or 1. E.g. x = v[0];
|
||||
inline S& operator[](int index); // Set component 0 or 1. E.g. v[0] = x;
|
||||
|
||||
inline S operator*(const Vector2& rhs) const; // Dot product
|
||||
inline S* ptr() { return m_v; } ///< Get a raw pointer to the internal c array of type S.
|
||||
inline const S* ptr() const { return m_v; } ///< Get a const raw pointer to the internal c array of type S.
|
||||
|
||||
inline const S& x() const { return m_v[0]; } ///< Get the X element of the vector
|
||||
inline const S& y() const { return m_v[1]; } ///< Get the Y element of the vector
|
||||
inline S& x() { return m_v[0]; } ///< Get a reference to the X element of the vector. E.g. x() = 1;
|
||||
inline S& y() { return m_v[1]; } ///< Get a reference to the Y element of the vector. E.g. y() = 2;
|
||||
|
||||
inline S* ptr() { return m_v; } ///< Get a raw pointer to the internal c array of type S.
|
||||
inline const S* ptr() const { return m_v; } ///< Get a const raw pointer to the internal c array of type S.
|
||||
|
||||
inline void set(S x, S y);
|
||||
inline void setZero();
|
||||
inline bool isZero() const;
|
||||
inline bool isUndefined() const;
|
||||
|
||||
template<typename T>
|
||||
void set(const T& other);
|
||||
inline bool isZero() const;
|
||||
inline bool isUndefined() const;
|
||||
|
||||
bool normalize();
|
||||
const Vector2 getNormalized(bool* normalizationOK = NULL) const;
|
||||
@@ -95,10 +96,15 @@ public:
|
||||
static const Vector2 ZERO; ///< Null vector <0, 0>
|
||||
static const Vector2 UNDEFINED; ///< Undefined vector
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
friend inline const Vector2<T> operator*(T scalar, const Vector2<T>& rhs);
|
||||
|
||||
private:
|
||||
S m_v[2];
|
||||
};
|
||||
|
||||
|
||||
typedef Vector2<float> Vec2f; ///< A vector with float components
|
||||
typedef Vector2<double> Vec2d; ///< A vector with double components
|
||||
typedef Vector2<int> Vec2i; ///< A vector with int components
|
||||
|
||||
@@ -85,6 +85,16 @@ Vector2<S>& Vector2<S>::operator=(const Vector2& other)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Check if two vectors are equal. An exact match is required.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
bool Vector2<S>::equals(const Vector2& other) const
|
||||
{
|
||||
return (*this == other);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Check if two vectors are equal. An exact match is required.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -115,6 +125,26 @@ inline const Vector2<S> Vector2<S>::operator+(const Vector2& rhs) const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adds the vector \a other to this vector
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void Vector2<S>::add(const Vector2& other)
|
||||
{
|
||||
(*this) += other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Subtracts the vector \a other from this vector
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void cvf::Vector2<S>::subtract(const Vector2& other)
|
||||
{
|
||||
(*this) -= other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compute this-rhs and return the result.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -125,6 +155,16 @@ inline const Vector2<S> Vector2<S>::operator-(const Vector2& rhs) const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Scale this vector by the given scalar
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void Vector2<S>::scale(S scalar)
|
||||
{
|
||||
(*this) *= scalar;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Return this vector scaled by the given scalar
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -240,6 +280,16 @@ inline S& Vector2<S>::operator[](int index)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compute the dot product of this and \a other
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
S Vector2<S>::dot(const Vector2& other) const
|
||||
{
|
||||
return (*this)*other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compute the dot product of this and rhs and return the result (scalar)
|
||||
///
|
||||
|
||||
@@ -52,47 +52,49 @@ public:
|
||||
explicit Vector3(const T& other);
|
||||
|
||||
inline Vector3& operator=(const Vector3& rhs);
|
||||
|
||||
inline bool equals(const Vector3& other) const;
|
||||
inline bool operator==(const Vector3& rhs) const;
|
||||
inline bool operator!=(const Vector3& rhs) const;
|
||||
|
||||
inline void add(const Vector3& other);
|
||||
inline void subtract(const Vector3& other);
|
||||
inline const Vector3 operator+(const Vector3& rhs) const;
|
||||
inline const Vector3 operator-(const Vector3& rhs) const;
|
||||
inline const Vector3 operator*(S scalar) const;
|
||||
inline const Vector3 operator/(S scalar) const;
|
||||
|
||||
template<typename T>
|
||||
friend inline const Vector3<T> operator*(T scalar, const Vector3<T>& rhs);
|
||||
|
||||
inline const Vector3 operator-() const;
|
||||
|
||||
inline Vector3& operator+=(const Vector3& rhs);
|
||||
inline Vector3& operator-=(const Vector3& rhs);
|
||||
inline const Vector3 operator-() const;
|
||||
|
||||
inline void scale(S scalar);
|
||||
inline const Vector3 operator*(S scalar) const;
|
||||
inline const Vector3 operator/(S scalar) const;
|
||||
inline Vector3& operator*=(S scalar);
|
||||
inline Vector3& operator/=(S scalar);
|
||||
|
||||
inline S dot(const Vector3& other) const;
|
||||
inline S operator*(const Vector3& rhs) const; // Dot product
|
||||
|
||||
inline void cross(const Vector3& v1, const Vector3& v2);
|
||||
inline const Vector3 operator^(const Vector3& rhs) const; // Cross product
|
||||
|
||||
template<typename T>
|
||||
void set(const T& other);
|
||||
inline void set(S x, S y, S z);
|
||||
inline void setZero();
|
||||
inline const S& x() const { return m_v[0]; } ///< Get the X element of the vector
|
||||
inline const S& y() const { return m_v[1]; } ///< Get the Y element of the vector
|
||||
inline const S& z() const { return m_v[2]; } ///< Get the Z element of the vector
|
||||
inline S& x() { return m_v[0]; } ///< Get a reference to the X element of the vector. E.g. x() = 1;
|
||||
inline S& y() { return m_v[1]; } ///< Get a reference to the Y element of the vector. E.g. y() = 2;
|
||||
inline S& z() { return m_v[2]; } ///< Get a reference to the Z element of the vector. E.g. z() = 3;
|
||||
inline const S& operator[](int index) const; // Get component 0,1,2. E.g. x = v[0];
|
||||
inline S& operator[](int index); // Set component 0,1,2. E.g. v[0] = x;
|
||||
|
||||
inline S operator*(const Vector3& rhs) const; // Dot product
|
||||
inline const Vector3 operator^(const Vector3& rhs) const; // Cross product
|
||||
inline S* ptr() { return m_v; } ///< Get a raw pointer to the internal c array of type S.
|
||||
inline const S* ptr() const { return m_v; } ///< Get a const raw pointer to the internal c array of type S.
|
||||
|
||||
inline const S& x() const { return m_v[0]; } ///< Get the X element of the vector
|
||||
inline const S& y() const { return m_v[1]; } ///< Get the Y element of the vector
|
||||
inline const S& z() const { return m_v[2]; } ///< Get the Z element of the vector
|
||||
inline S& x() { return m_v[0]; } ///< Get a reference to the X element of the vector. E.g. x() = 1;
|
||||
inline S& y() { return m_v[1]; } ///< Get a reference to the Y element of the vector. E.g. y() = 2;
|
||||
inline S& z() { return m_v[2]; } ///< Get a reference to the Z element of the vector. E.g. z() = 3;
|
||||
|
||||
inline S* ptr() { return m_v; } ///< Get a raw pointer to the internal c array of type S.
|
||||
inline const S* ptr() const { return m_v; } ///< Get a const raw pointer to the internal c array of type S.
|
||||
|
||||
inline void set(S x, S y, S z);
|
||||
inline void setZero();
|
||||
inline bool isZero() const;
|
||||
inline bool isUndefined() const;
|
||||
|
||||
template<typename T>
|
||||
void set(const T& other);
|
||||
inline bool isZero() const;
|
||||
inline bool isUndefined() const;
|
||||
|
||||
bool normalize();
|
||||
const Vector3 getNormalized(bool* normalizationOK = NULL) const;
|
||||
@@ -122,10 +124,15 @@ public:
|
||||
static const Vector3 ZERO; ///< Null vector <0, 0, 0>
|
||||
static const Vector3 UNDEFINED; ///< Undefined vector
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
friend inline const Vector3<T> operator*(T scalar, const Vector3<T>& rhs);
|
||||
|
||||
private:
|
||||
S m_v[3];
|
||||
};
|
||||
|
||||
|
||||
typedef Vector3<float> Vec3f; ///< A vector with float components
|
||||
typedef Vector3<double> Vec3d; ///< A vector with double components
|
||||
typedef Vector3<int> Vec3i; ///< A vector with int components
|
||||
|
||||
@@ -115,6 +115,17 @@ Vector3<S>& Vector3<S>::operator=(const Vector3& other)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Check if two vectors are equal. An exact match is required.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
bool Vector3<S>::equals(const Vector3& other) const
|
||||
{
|
||||
return (*this == other);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Check if two vectors are equal. An exact match is required.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -135,6 +146,26 @@ inline bool Vector3<S>::operator!=(const Vector3& rhs) const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adds the vector \a other to this vector
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void cvf::Vector3<S>::add(const Vector3& other)
|
||||
{
|
||||
(*this) += other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Subtracts the vector \a other from this vector
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void cvf::Vector3<S>::subtract(const Vector3& other)
|
||||
{
|
||||
(*this) -= other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Returns the sum of this vector and the rhs vector
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -155,6 +186,16 @@ inline const Vector3<S> Vector3<S>::operator-(const Vector3& rhs) const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Scale this vector by the given scalar
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void Vector3<S>::scale(S scalar)
|
||||
{
|
||||
(*this) *= scalar;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Return this vector scaled by the given scalar
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -274,6 +315,16 @@ inline S& Vector3<S>::operator[](int index)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compute the dot product of this and \a other
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
S Vector3<S>::dot(const Vector3& other) const
|
||||
{
|
||||
return (*this)*other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compute the dot product of this and rhs and return the result (scalar)
|
||||
///
|
||||
@@ -289,6 +340,17 @@ inline S Vector3<S>::operator*(const Vector3& rhs) const
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Sets this vector to the cross product of vectors \a v1 and \a v2
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void cvf::Vector3<S>::cross(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
*this = v1 ^ v2;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compute the cross product of this and rhs and return the result (vector)
|
||||
///
|
||||
|
||||
@@ -43,50 +43,55 @@ public:
|
||||
explicit Vector4(const T& other);
|
||||
|
||||
inline Vector4& operator=(const Vector4& rhs);
|
||||
|
||||
inline bool equals(const Vector4& other) const;
|
||||
inline bool operator==(const Vector4& rhs) const;
|
||||
inline bool operator!=(const Vector4& rhs) const;
|
||||
|
||||
inline void add(const Vector4& other);
|
||||
inline void subtract(const Vector4& other);
|
||||
inline const Vector4 operator+(const Vector4& rhs) const;
|
||||
inline const Vector4 operator-(const Vector4& rhs) const;
|
||||
inline const Vector4 operator*(S scalar) const;
|
||||
inline const Vector4 operator/(S scalar) const;
|
||||
inline const Vector4 operator-() const;
|
||||
|
||||
inline Vector4& operator+=(const Vector4& rhs);
|
||||
inline Vector4& operator-=(const Vector4& rhs);
|
||||
inline const Vector4 operator-() const;
|
||||
|
||||
inline void scale(S scalar);
|
||||
inline const Vector4 operator*(S scalar) const;
|
||||
inline const Vector4 operator/(S scalar) const;
|
||||
inline Vector4& operator*=(S scalar);
|
||||
inline Vector4& operator/=(S scalar);
|
||||
|
||||
inline S dot(const Vector4& other) const;
|
||||
inline S operator*(const Vector4& rhs) const; // Dot product
|
||||
|
||||
template<typename T>
|
||||
void set(const T& other);
|
||||
inline void set(S x, S y, S z, S w);
|
||||
inline void setZero();
|
||||
inline const S& x() const { return m_v[0]; } ///< Get the X element of the vector
|
||||
inline const S& y() const { return m_v[1]; } ///< Get the Y element of the vector
|
||||
inline const S& z() const { return m_v[2]; } ///< Get the Z element of the vector
|
||||
inline const S& w() const { return m_v[3]; } ///< Get the W element of the vector
|
||||
inline S& x() { return m_v[0]; } ///< Get a reference to the X element of the vector. E.g. x() = 1;
|
||||
inline S& y() { return m_v[1]; } ///< Get a reference to the Y element of the vector. E.g. y() = 2;
|
||||
inline S& z() { return m_v[2]; } ///< Get a reference to the Z element of the vector. E.g. z() = 3;
|
||||
inline S& w() { return m_v[3]; } ///< Get a reference to the W element of the vector. E.g. w() = 3;
|
||||
|
||||
inline const S& operator[](int index) const; // Get component 0,1,2,3. E.g. x = v[0];
|
||||
inline S& operator[](int index); // Set component 0,1,2,3. E.g. v[0] = x;
|
||||
|
||||
inline S operator*(const Vector4& rhs) const; // Dot product
|
||||
inline S* ptr() { return m_v; } ///< Get a raw pointer to the internal c array of type S.
|
||||
inline const S* ptr() const { return m_v; } ///< Get a const raw pointer to the internal c array of type S.
|
||||
|
||||
inline const S& x() const { return m_v[0]; } ///< Get the X element of the vector
|
||||
inline const S& y() const { return m_v[1]; } ///< Get the Y element of the vector
|
||||
inline const S& z() const { return m_v[2]; } ///< Get the Z element of the vector
|
||||
inline const S& w() const { return m_v[3]; } ///< Get the W element of the vector
|
||||
inline S& x() { return m_v[0]; } ///< Get a reference to the X element of the vector. E.g. x() = 1;
|
||||
inline S& y() { return m_v[1]; } ///< Get a reference to the Y element of the vector. E.g. y() = 2;
|
||||
inline S& z() { return m_v[2]; } ///< Get a reference to the Z element of the vector. E.g. z() = 3;
|
||||
inline S& w() { return m_v[3]; } ///< Get a reference to the W element of the vector. E.g. w() = 3;
|
||||
inline bool isZero() const;
|
||||
|
||||
inline S* ptr() { return m_v; } ///< Get a raw pointer to the internal c array of type S.
|
||||
inline const S* ptr() const { return m_v; } ///< Get a const raw pointer to the internal c array of type S.
|
||||
bool normalize();
|
||||
const Vector4 getNormalized(bool* normalizationOK = NULL) const;
|
||||
|
||||
inline void set(S x, S y, S z, S w);
|
||||
inline void setZero();
|
||||
inline bool isZero() const;
|
||||
|
||||
template<typename T>
|
||||
void set(const T& other);
|
||||
|
||||
bool normalize();
|
||||
Vector4 normalized(bool* normalizationOK = NULL) const;
|
||||
|
||||
inline S length() const;
|
||||
inline S lengthSquared() const;
|
||||
bool setLength(S newLength);
|
||||
inline S length() const;
|
||||
inline S lengthSquared() const;
|
||||
bool setLength(S newLength);
|
||||
|
||||
public:
|
||||
static const Vector4 ZERO; ///< Null vector <0, 0, 0>
|
||||
@@ -96,6 +101,7 @@ private:
|
||||
S m_v[4];
|
||||
};
|
||||
|
||||
|
||||
typedef Vector4<float> Vec4f; ///< A vector with float components
|
||||
typedef Vector4<double> Vec4d; ///< A vector with double components
|
||||
typedef Vector4<int> Vec4i; ///< A vector with int components
|
||||
|
||||
@@ -102,6 +102,17 @@ Vector4<S>::Vector4(const Vector3<S>& other, S w)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Check if two vectors are equal. An exact match is required.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
bool Vector4<S>::equals(const Vector4& other) const
|
||||
{
|
||||
return (*this == other);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Check if two vectors are equal. An exact match is required.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -122,6 +133,26 @@ inline bool Vector4<S>::operator!=(const Vector4& rhs) const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Adds the vector \a other to this vector
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void cvf::Vector4<S>::add(const Vector4& other)
|
||||
{
|
||||
(*this) += other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Subtracts the vector \a other from this vector
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void cvf::Vector4<S>::subtract(const Vector4& other)
|
||||
{
|
||||
(*this) -= other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Returns the sum of this vector and the rhs vector
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -142,6 +173,17 @@ inline const Vector4<S> Vector4<S>::operator-(const Vector4& rhs) const
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Scale this vector by the given scalar
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
void Vector4<S>::scale(S scalar)
|
||||
{
|
||||
(*this) *= scalar;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Return this vector scaled by the given scalar
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -258,6 +300,16 @@ inline S& Vector4<S>::operator[](int index)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compute the dot product of this and \a other
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
S Vector4<S>::dot(const Vector4& other) const
|
||||
{
|
||||
return (*this)*other;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compute the dot product of this and rhs and return the result (scalar)
|
||||
///
|
||||
@@ -384,7 +436,7 @@ bool Vector4<S>::normalize()
|
||||
/// Returns a normalized version of the current vector. The vector is unchanged.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename S>
|
||||
Vector4<S> Vector4<S>::normalized(bool* normalizationOK) const
|
||||
const Vector4<S> Vector4<S>::getNormalized(bool* normalizationOK) const
|
||||
{
|
||||
S len = length();
|
||||
if (len > 0.0)
|
||||
|
||||
@@ -22,6 +22,6 @@
|
||||
|
||||
|
||||
#define CVF_MAJOR_VERSION "0" // Major version number
|
||||
#define CVF_MINOR_VERSION "1" // Minor version number
|
||||
#define CVF_MINOR_VERSION "9" // Minor version number
|
||||
#define CVF_SPECIAL_BUILD "" // Special build description
|
||||
#define CVF_BUILD_NUMBER "2" // Build number. Increase for each shipment
|
||||
#define CVF_BUILD_NUMBER "4" // Build number. Increase for each shipment
|
||||
|
||||
Reference in New Issue
Block a user