rename 2d tool classes to be consistent with 3d classes

This commit is contained in:
wmayer
2016-11-21 14:29:51 +01:00
parent 9fe280ed63
commit 2d8e70085e
42 changed files with 950 additions and 951 deletions

View File

@@ -84,9 +84,9 @@ public:
/** Checks for intersection. */
inline bool operator && (const BoundBox3<_Precision> &rcBB) const;
/** Checks for intersection. */
inline bool Intersect (const BoundBox2D &rcBB) const;
inline bool Intersect (const BoundBox2d &rcBB) const;
/** Checks for intersection. */
inline bool operator && (const BoundBox2D &rcBB) const;
inline bool operator && (const BoundBox2d &rcBB) const;
/** Computes the intersection between two bounding boxes.
* The result is also a bounding box.
*/
@@ -112,7 +112,7 @@ public:
/** Checks if this 2D box lies inside the box.
* @note It's up to the client programmer to make sure that both bounding boxes are valid.
*/
inline bool IsInBox (const BoundBox2D &rcbb) const;
inline bool IsInBox (const BoundBox2d &rcbb) const;
/** Checks whether the bounding box is valid. */
bool IsValid (void) const;
//@}
@@ -167,7 +167,7 @@ public:
*/
Vector3<_Precision> ClosestPoint (const Vector3<_Precision> &rclPt) const;
/** Projects the box onto a plane and returns a 2D box. */
BoundBox2D ProjectBox(const ViewProjMethod *rclP) const;
BoundBox2d ProjectBox(const ViewProjMethod *rclP) const;
/** Transform the corners of this box with the given matrix and create a new bounding box.
* @note It's up to the client programmer to make sure that this bounding box is valid.
*/
@@ -299,17 +299,17 @@ bool BoundBox3<_Precision>::operator && (const BoundBox3<_Precision> &rcBB) cons
}
template <class _Precision>
inline bool BoundBox3<_Precision>::Intersect (const BoundBox2D &rcBB) const
inline bool BoundBox3<_Precision>::Intersect (const BoundBox2d &rcBB) const
{
if (rcBB.fMaxX < this->MinX || rcBB.fMinX > this->MaxX)
if (rcBB.MaxX < this->MinX || rcBB.MinX > this->MaxX)
return false;
if (rcBB.fMaxY < this->MinY || rcBB.fMinY > this->MaxY)
if (rcBB.MaxY < this->MinY || rcBB.MinY > this->MaxY)
return false;
return true;
}
template <class _Precision>
inline bool BoundBox3<_Precision>::operator && (const BoundBox2D &rcBB) const
inline bool BoundBox3<_Precision>::operator && (const BoundBox2d &rcBB) const
{
return Intersect(rcBB);
}
@@ -391,11 +391,11 @@ inline bool BoundBox3<_Precision>::IsInBox (const BoundBox3<_Precision> &rcBB) c
}
template <class _Precision>
inline bool BoundBox3<_Precision>::IsInBox (const BoundBox2D &rcBB) const
inline bool BoundBox3<_Precision>::IsInBox (const BoundBox2d &rcBB) const
{
if (rcBB.fMinX < this->MinX || rcBB.fMaxX > this->MaxX)
if (rcBB.MinX < this->MinX || rcBB.MaxX > this->MaxX)
return false;
if (rcBB.fMinY < this->MinY || rcBB.fMaxY > this->MaxY)
if (rcBB.MinY < this->MinY || rcBB.MaxY > this->MaxY)
return false;
return true;
}
@@ -872,14 +872,14 @@ inline Vector3<_Precision> BoundBox3<_Precision>::ClosestPoint (const Vector3<_P
}
template <class _Precision>
inline BoundBox2D BoundBox3<_Precision>::ProjectBox(const ViewProjMethod *pclP) const
inline BoundBox2d BoundBox3<_Precision>::ProjectBox(const ViewProjMethod *pclP) const
{
BoundBox2D clBB2D;
BoundBox2d clBB2D;
clBB2D.SetVoid();
for (int i = 0; i < 8; i++) {
Vector3<_Precision> clTrsPt = (*pclP)(CalcPoint(i));
clBB2D.Add(Vector2D(clTrsPt.x, clTrsPt.y));
clBB2D.Add(Vector2d(clTrsPt.x, clTrsPt.y));
}
return clBB2D;

View File

@@ -33,7 +33,7 @@
using namespace Base;
double Vector2D::GetAngle (const Vector2D &rclVect) const
double Vector2d::GetAngle (const Vector2d &rclVect) const
{
double fDivid, fNum;
@@ -54,83 +54,83 @@ double Vector2D::GetAngle (const Vector2D &rclVect) const
return -FLOAT_MAX; // division by zero
}
void Vector2D::ProjectToLine (const Vector2D &rclPt, const Vector2D &rclLine)
void Vector2d::ProjectToLine (const Vector2d &rclPt, const Vector2d &rclLine)
{
double l = rclLine.Length();
double t1 = (rclPt * rclLine) / l;
Vector2D clNormal = rclLine;
Vector2d clNormal = rclLine;
clNormal.Normalize();
clNormal.Scale(t1);
*this = clNormal;
}
/********************************************************/
/** BOUNDBOX2D ********************************************/
/** BOUNDBOX2d ********************************************/
bool BoundBox2D::Intersect(const Line2D &rclLine) const
bool BoundBox2d::Intersect(const Line2d &rclLine) const
{
Line2D clThisLine;
Vector2D clVct;
Line2d clThisLine;
Vector2d clVct;
// first line
clThisLine.clV1.fX = fMinX;
clThisLine.clV1.fY = fMinY;
clThisLine.clV2.fX = fMaxX;
clThisLine.clV2.fY = fMinY;
clThisLine.clV1.x = MinX;
clThisLine.clV1.y = MinY;
clThisLine.clV2.x = MaxX;
clThisLine.clV2.y = MinY;
if (clThisLine.IntersectAndContain (rclLine, clVct))
return true;
// second line
clThisLine.clV1 = clThisLine.clV2;
clThisLine.clV2.fX = fMaxX;
clThisLine.clV2.fY = fMaxY;
clThisLine.clV2.x = MaxX;
clThisLine.clV2.y = MaxY;
if (clThisLine.IntersectAndContain (rclLine, clVct))
return true;
// third line
clThisLine.clV1 = clThisLine.clV2;
clThisLine.clV2.fX = fMinX;
clThisLine.clV2.fY = fMaxY;
clThisLine.clV2.x = MinX;
clThisLine.clV2.y = MaxY;
if (clThisLine.IntersectAndContain (rclLine, clVct))
return true;
// fourth line
clThisLine.clV1 = clThisLine.clV2;
clThisLine.clV2.fX = fMinX;
clThisLine.clV2.fY = fMinY;
clThisLine.clV2.x = MinX;
clThisLine.clV2.y = MinY;
if (clThisLine.IntersectAndContain (rclLine, clVct))
return true;
return false;
}
bool BoundBox2D::Intersect(const BoundBox2D &rclBB) const
bool BoundBox2d::Intersect(const BoundBox2d &rclBB) const
{
//// compare bb2-points to this
//if (Contains (Vector2D (rclBB.fMinX, rclBB.fMinY))) return true;
//if (Contains (Vector2D (rclBB.fMaxX, rclBB.fMinY))) return true;
//if (Contains (Vector2D (rclBB.fMaxX, rclBB.fMaxY))) return true;
//if (Contains (Vector2D (rclBB.fMinX, rclBB.fMaxY))) return true;
//if (Contains (Vector2d (rclBB.fMinX, rclBB.fMinY))) return true;
//if (Contains (Vector2d (rclBB.fMaxX, rclBB.fMinY))) return true;
//if (Contains (Vector2d (rclBB.fMaxX, rclBB.fMaxY))) return true;
//if (Contains (Vector2d (rclBB.fMinX, rclBB.fMaxY))) return true;
//
//// compare this-points to bb2
//if (rclBB.Contains (Vector2D (fMinX, fMinY))) return true;
//if (rclBB.Contains (Vector2D (fMaxX, fMinY))) return true;
//if (rclBB.Contains (Vector2D (fMaxX, fMaxY))) return true;
//if (rclBB.Contains (Vector2D (fMinX, fMaxY))) return true;
//if (rclBB.Contains (Vector2d (fMinX, fMinY))) return true;
//if (rclBB.Contains (Vector2d (fMaxX, fMinY))) return true;
//if (rclBB.Contains (Vector2d (fMaxX, fMaxY))) return true;
//if (rclBB.Contains (Vector2d (fMinX, fMaxY))) return true;
if (fMinX < rclBB.fMaxX &&
rclBB.fMinX < fMaxX &&
fMinY < rclBB.fMaxY &&
rclBB.fMinY < fMaxY )
if (MinX < rclBB.MaxX &&
rclBB.MinX < MaxX &&
MinY < rclBB.MaxY &&
rclBB.MinY < MaxY )
return true;
else // no intersection
return false;
}
bool BoundBox2D::Intersect(const Polygon2D &rclPoly) const
bool BoundBox2d::Intersect(const Polygon2d &rclPoly) const
{
unsigned long i;
Line2D clLine;
Line2d clLine;
// points contained in boundbox
for (i = 0; i < rclPoly.GetCtVectors(); i++)
@@ -138,10 +138,10 @@ bool BoundBox2D::Intersect(const Polygon2D &rclPoly) const
return true; /***** RETURN INTERSECTION *********/
// points contained in polygon
if (rclPoly.Contains (Vector2D (fMinX, fMinY)) ||
rclPoly.Contains (Vector2D (fMaxX, fMinY)) ||
rclPoly.Contains (Vector2D (fMaxX, fMaxY)) ||
rclPoly.Contains (Vector2D (fMinX, fMaxY)))
if (rclPoly.Contains (Vector2d (MinX, MinY)) ||
rclPoly.Contains (Vector2d (MaxX, MinY)) ||
rclPoly.Contains (Vector2d (MaxX, MaxY)) ||
rclPoly.Contains (Vector2d (MinX, MaxY)))
return true; /***** RETURN INTERSECTION *********/
// test intersections of bound-lines
@@ -165,73 +165,73 @@ bool BoundBox2D::Intersect(const Polygon2D &rclPoly) const
return false;
}
bool BoundBox2D::Contains (const Vector2D &rclV) const
bool BoundBox2d::Contains (const Vector2d &rclV) const
{
return
(rclV.fX >= fMinX) && (rclV.fX <= fMaxX) &&
(rclV.fY >= fMinY) && (rclV.fY <= fMaxY);
(rclV.x >= MinX) && (rclV.x <= MaxX) &&
(rclV.y >= MinY) && (rclV.y <= MaxY);
}
/********************************************************/
/** LINE2D **********************************************/
BoundBox2D Line2D::CalcBoundBox (void) const
BoundBox2d Line2d::CalcBoundBox (void) const
{
BoundBox2D clBB;
clBB.fMinX = std::min<double> (clV1.fX, clV2.fX);
clBB.fMinY = std::min<double> (clV1.fY, clV2.fY);
clBB.fMaxX = std::max<double> (clV1.fX, clV2.fX);
clBB.fMaxY = std::max<double> (clV1.fY, clV2.fY);
BoundBox2d clBB;
clBB.MinX = std::min<double> (clV1.x, clV2.x);
clBB.MinY = std::min<double> (clV1.y, clV2.y);
clBB.MaxX = std::max<double> (clV1.x, clV2.x);
clBB.MaxY = std::max<double> (clV1.y, clV2.y);
return clBB;
}
bool Line2D::Intersect (const Line2D& rclLine, Vector2D &rclV) const
bool Line2d::Intersect (const Line2d& rclLine, Vector2d &rclV) const
{
double m1, m2, b1, b2;
// calc coefficients
if (fabs (clV2.fX - clV1.fX) > 1e-10)
m1 = (clV2.fY - clV1.fY) / (clV2.fX - clV1.fX);
if (fabs (clV2.x - clV1.x) > 1e-10)
m1 = (clV2.y - clV1.y) / (clV2.x - clV1.x);
else
m1 = FLOAT_MAX;
if (fabs (rclLine.clV2.fX - rclLine.clV1.fX) > 1e-10)
m2 = (rclLine.clV2.fY - rclLine.clV1.fY) / (rclLine.clV2.fX - rclLine.clV1.fX);
if (fabs (rclLine.clV2.x - rclLine.clV1.x) > 1e-10)
m2 = (rclLine.clV2.y - rclLine.clV1.y) / (rclLine.clV2.x - rclLine.clV1.x);
else
m2 = FLOAT_MAX;
if (m1 == m2) /****** RETURN ERR (parallel lines) *************/
return false;
b1 = clV1.fY - m1 * clV1.fX;
b2 = rclLine.clV1.fY - m2 * rclLine.clV1.fX;
b1 = clV1.y - m1 * clV1.x;
b2 = rclLine.clV1.y - m2 * rclLine.clV1.x;
// calc intersection
if (m1 == FLOAT_MAX)
{
rclV.fX = clV1.fX;
rclV.fY = m2 * rclV.fX + b2;
rclV.x = clV1.x;
rclV.y = m2 * rclV.x + b2;
}
else
if (m2 == FLOAT_MAX)
{
rclV.fX = rclLine.clV1.fX;
rclV.fY = m1 * rclV.fX + b1;
rclV.x = rclLine.clV1.x;
rclV.y = m1 * rclV.x + b1;
}
else
{
rclV.fX = (b2 - b1) / (m1 - m2);
rclV.fY = m1 * rclV.fX + b1;
rclV.x = (b2 - b1) / (m1 - m2);
rclV.y = m1 * rclV.x + b1;
}
return true; /*** RETURN true (intersection) **********/
}
bool Line2D::Intersect (const Vector2D &rclV, double eps) const
bool Line2d::Intersect (const Vector2d &rclV, double eps) const
{
double dxc = rclV.fX - clV1.fX;
double dyc = rclV.fY - clV1.fY;
double dxc = rclV.x - clV1.x;
double dyc = rclV.y - clV1.y;
double dxl = clV2.fX - clV1.fX;
double dyl = clV2.fY - clV1.fY;
double dxl = clV2.x - clV1.x;
double dyl = clV2.y - clV1.y;
double cross = dxc * dyl - dyc * dxl;
@@ -247,14 +247,14 @@ bool Line2D::Intersect (const Vector2D &rclV, double eps) const
return true;
}
Vector2D Line2D::FromPos (double fDistance) const
Vector2d Line2d::FromPos (double fDistance) const
{
Vector2D clDir(clV2 - clV1);
Vector2d clDir(clV2 - clV1);
clDir.Normalize();
return Vector2D(clV1.fX + (clDir.fX * fDistance), clV1.fY + (clDir.fY * fDistance));
return Vector2d(clV1.x + (clDir.x * fDistance), clV1.y + (clDir.y * fDistance));
}
bool Line2D::IntersectAndContain (const Line2D& rclLine, Vector2D &rclV) const
bool Line2d::IntersectAndContain (const Line2d& rclLine, Vector2d &rclV) const
{
bool rc = Intersect (rclLine, rclV);
if (rc)
@@ -263,18 +263,18 @@ bool Line2D::IntersectAndContain (const Line2D& rclLine, Vector2D &rclV) const
}
/********************************************************/
/** POLYGON2D ********************************************/
/** POLYGON2d ********************************************/
BoundBox2D Polygon2D::CalcBoundBox (void) const
BoundBox2d Polygon2d::CalcBoundBox (void) const
{
unsigned long i;
BoundBox2D clBB;
BoundBox2d clBB;
for (i = 0; i < _aclVct.size(); i++)
{
clBB.fMinX = std::min<double> (clBB.fMinX, _aclVct[i].fX);
clBB.fMinY = std::min<double> (clBB.fMinY, _aclVct[i].fY);
clBB.fMaxX = std::max<double> (clBB.fMaxX, _aclVct[i].fX);
clBB.fMaxY = std::max<double> (clBB.fMaxY, _aclVct[i].fY);
clBB.MinX = std::min<double> (clBB.MinX, _aclVct[i].x);
clBB.MinY = std::min<double> (clBB.MinY, _aclVct[i].y);
clBB.MaxX = std::max<double> (clBB.MaxX, _aclVct[i].x);
clBB.MaxY = std::max<double> (clBB.MaxY, _aclVct[i].y);
}
return clBB;
}
@@ -314,7 +314,7 @@ static short _CalcTorsion (double *pfLine, double fX, double fY)
return 0;
}
bool Polygon2D::Contains (const Vector2D &rclV) const
bool Polygon2d::Contains (const Vector2d &rclV) const
{
// Ermittelt mit dem Verfahren der Windungszahl, ob ein Punkt innerhalb
// eines Polygonzugs enthalten ist.
@@ -333,29 +333,29 @@ bool Polygon2D::Contains (const Vector2D &rclV) const
if (i == GetCtVectors() - 1)
{
// Polygon automatisch schliessen
pfTmp[0] = _aclVct[i].fX;
pfTmp[1] = _aclVct[i].fY;
pfTmp[2] = _aclVct[0].fX;
pfTmp[3] = _aclVct[0].fY;
pfTmp[0] = _aclVct[i].x;
pfTmp[1] = _aclVct[i].y;
pfTmp[2] = _aclVct[0].x;
pfTmp[3] = _aclVct[0].y;
}
else
{
// uebernehmen Punkt i und i+1
pfTmp[0] = _aclVct[i].fX;
pfTmp[1] = _aclVct[i].fY;
pfTmp[2] = _aclVct[i + 1].fX;
pfTmp[3] = _aclVct[i + 1].fY;
pfTmp[0] = _aclVct[i].x;
pfTmp[1] = _aclVct[i].y;
pfTmp[2] = _aclVct[i + 1].x;
pfTmp[3] = _aclVct[i + 1].y;
}
// Schnitt-Test durchfuehren und Windungszaehler berechnen
sTorsion += _CalcTorsion (pfTmp, rclV.fX, rclV.fY);
sTorsion += _CalcTorsion (pfTmp, rclV.x, rclV.y);
}
// Windungszaehler auswerten
return sTorsion != 0;
}
void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rclResultPolygonList) const
void Polygon2d::Intersect (const Polygon2d &rclPolygon, std::list<Polygon2d> &rclResultPolygonList) const
{
// trimmen des uebergebenen Polygons mit dem aktuellen, Ergebnis ist eine Liste von Polygonen (Untermenge des uebergebenen Polygons)
// das eigene (Trim-) Polygon ist geschlossen
@@ -366,7 +366,7 @@ void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rc
// position of first points (in or out of polygon)
bool bInner = Contains(rclPolygon[0]);
Polygon2D clResultPolygon;
Polygon2d clResultPolygon;
if (bInner == true) // add first point if inner trim-polygon
clResultPolygon.Add(rclPolygon[0]);
@@ -375,19 +375,19 @@ void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rc
size_t ulTrimCt = GetCtVectors();
for (size_t ulVec = 0; ulVec < (ulPolyCt-1); ulVec++)
{
Vector2D clPt0 = rclPolygon[ulVec];
Vector2D clPt1 = rclPolygon[ulVec+1];
Line2D clLine(clPt0, clPt1);
Vector2d clPt0 = rclPolygon[ulVec];
Vector2d clPt1 = rclPolygon[ulVec+1];
Line2d clLine(clPt0, clPt1);
// try to intersect with each line of the trim-polygon
std::set<double> afIntersections; // set of intersections (sorted by line parameter)
Vector2D clTrimPt2; // second line point
Vector2d clTrimPt2; // second line point
for (size_t i = 0; i < ulTrimCt; i++)
{
clTrimPt2 = At((i + 1) % ulTrimCt);
Line2D clToTrimLine(At(i), clTrimPt2);
Line2d clToTrimLine(At(i), clTrimPt2);
Vector2D clV;
Vector2d clV;
if (clLine.IntersectAndContain(clToTrimLine, clV) == true)
{
// save line parameter of intersection point
@@ -401,7 +401,7 @@ void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rc
for (std::set<double>::iterator pF = afIntersections.begin(); pF != afIntersections.end(); ++pF)
{
// intersection point
Vector2D clPtIS = clLine.FromPos(*pF);
Vector2d clPtIS = clLine.FromPos(*pF);
if (bInner == true)
{
clResultPolygon.Add(clPtIS);
@@ -431,16 +431,16 @@ void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rc
rclResultPolygonList.push_back(clResultPolygon);
}
bool Polygon2D::Intersect (const Vector2D &rclV, double eps) const
bool Polygon2d::Intersect (const Vector2d &rclV, double eps) const
{
if (_aclVct.size() < 2)
return false;
size_t numPts = GetCtVectors();
for (size_t i = 0; i < numPts; i++) {
Vector2D clPt0 = (*this)[i];
Vector2D clPt1 = (*this)[(i+1)%numPts];
Line2D clLine(clPt0, clPt1);
Vector2d clPt0 = (*this)[i];
Vector2d clPt1 = (*this)[(i+1)%numPts];
Line2d clLine(clPt0, clPt1);
if (clLine.Intersect(rclV, eps))
return true;
}

View File

@@ -35,247 +35,246 @@
namespace Base {
class Vector2D;
class BoundBox2D;
class Line2D;
class Polygon2D;
class Vector2d;
class BoundBox2d;
class Line2d;
class Polygon2d;
/**
* The vector class for 2D calculations.
*/
class BaseExport Vector2D
class BaseExport Vector2d
{
public:
double fX, fY;
double x, y;
inline Vector2D (void);
inline Vector2D (float x, float y);
inline Vector2D (double x, double y);
inline Vector2D (const Vector2D &rclVct);
inline Vector2d (void);
inline Vector2d (float x, float y);
inline Vector2d (double x, double y);
inline Vector2d (const Vector2d &rclVct);
// methods
inline double Length (void) const;
// operators
inline Vector2D& operator= (const Vector2D &rclVct);
inline double operator* (const Vector2D &rclVct) const;
inline bool operator== (const Vector2D &rclVct) const;
inline Vector2D operator+ (const Vector2D &rclVct) const;
inline Vector2D operator- (const Vector2D &rclVct) const;
inline Vector2D operator/ (double c) const;
inline Vector2d& operator= (const Vector2d &rclVct);
inline double operator* (const Vector2d &rclVct) const;
inline bool operator== (const Vector2d &rclVct) const;
inline Vector2d operator+ (const Vector2d &rclVct) const;
inline Vector2d operator- (const Vector2d &rclVct) const;
inline Vector2d operator/ (double c) const;
inline void Set (double fPX, double fPY);
inline void Scale (double fS);
inline void Normalize (void);
double GetAngle (const Vector2D &rclVect) const;
void ProjectToLine (const Vector2D &rclPt, const Vector2D &rclLine);
double GetAngle (const Vector2d &rclVect) const;
void ProjectToLine (const Vector2d &rclPt, const Vector2d &rclLine);
};
/** BoundBox2D ********************************************/
/** BoundBox2d ********************************************/
/**
* Two dimensional bounding box.
*/
class BaseExport BoundBox2D
class BaseExport BoundBox2d
{
public:
double fMinX, fMinY, fMaxX, fMaxY;
double MinX, MinY, MaxX, MaxY;
inline BoundBox2D (void);
inline BoundBox2D (const BoundBox2D &rclBB);
inline BoundBox2D (double fX1, double fY1, double fX2, double fY2);
inline BoundBox2d (void);
inline BoundBox2d (const BoundBox2d &rclBB);
inline BoundBox2d (double fX1, double fY1, double fX2, double fY2);
inline bool IsValid (void);
// operators
inline BoundBox2D& operator= (const BoundBox2D& rclBB);
inline bool operator== (const BoundBox2D& rclBB) const;
bool Intersect(const Line2D &rclLine) const;
bool Intersect(const BoundBox2D &rclBB) const;
bool Intersect(const Polygon2D &rclPoly) const;
inline void Add(const Vector2D &rclVct);
inline BoundBox2d& operator= (const BoundBox2d& rclBB);
inline bool operator== (const BoundBox2d& rclBB) const;
bool Intersect(const Line2d &rclLine) const;
bool Intersect(const BoundBox2d &rclBB) const;
bool Intersect(const Polygon2d &rclPoly) const;
inline void Add(const Vector2d &rclVct);
void SetVoid (void) { fMinX = fMinY = DOUBLE_MAX; fMaxX = fMaxY = -DOUBLE_MAX; }
void SetVoid (void) { MinX = MinY = DOUBLE_MAX; MaxX = MaxY = -DOUBLE_MAX; }
// misc
bool Contains (const Vector2D &rclV) const;
bool Contains (const Vector2d &rclV) const;
};
/** Line2D ********************************************/
/** Line2d ********************************************/
/**
* 2D line class.
*/
class BaseExport Line2D
class BaseExport Line2d
{
public:
Vector2D clV1, clV2;
Vector2d clV1, clV2;
Line2D (void) {}
inline Line2D (const Line2D &rclLine);
inline Line2D (const Vector2D &rclV1, const Vector2D &rclV2);
Line2d (void) {}
inline Line2d (const Line2d &rclLine);
inline Line2d (const Vector2d &rclV1, const Vector2d &rclV2);
// methods
inline double Length (void) const;
BoundBox2D CalcBoundBox (void) const;
BoundBox2d CalcBoundBox (void) const;
// operators
inline Line2D& operator= (const Line2D& rclLine);
inline bool operator== (const Line2D& rclLine) const;
inline Line2d& operator= (const Line2d& rclLine);
inline bool operator== (const Line2d& rclLine) const;
// misc
inline bool Contains (const Vector2D &rclV) const;
bool Intersect (const Line2D& rclLine, Vector2D &rclV) const;
bool Intersect (const Vector2D &rclV, double eps) const;
bool IntersectAndContain (const Line2D& rclLine, Vector2D &rclV) const;
Vector2D FromPos (double fDistance) const;
inline bool Contains (const Vector2d &rclV) const;
bool Intersect (const Line2d& rclLine, Vector2d &rclV) const;
bool Intersect (const Vector2d &rclV, double eps) const;
bool IntersectAndContain (const Line2d& rclLine, Vector2d &rclV) const;
Vector2d FromPos (double fDistance) const;
};
/** Polygon2D ********************************************/
/** Polygon2d ********************************************/
/**
* 2D polygon class.
*/
class BaseExport Polygon2D
class BaseExport Polygon2d
{
public:
Polygon2D (void) {}
inline Polygon2D (const Polygon2D &rclPoly);
virtual ~Polygon2D () {}
Polygon2d (void) {}
inline Polygon2d (const Polygon2d &rclPoly);
virtual ~Polygon2d () {}
inline Polygon2D& operator = (const Polygon2D &rclP);
inline Polygon2d& operator = (const Polygon2d &rclP);
// admin-interface
inline size_t GetCtVectors (void) const;
inline bool Add (const Vector2D &rclVct);
inline Vector2D& operator[] (size_t ulNdx) const;
inline Vector2D& At (size_t ulNdx) const;
inline bool Add (const Vector2d &rclVct);
inline Vector2d& operator[] (size_t ulNdx) const;
inline Vector2d& At (size_t ulNdx) const;
inline bool Delete (size_t ulNdx);
inline void DeleteAll (void);
// misc
BoundBox2D CalcBoundBox (void) const;
bool Contains (const Vector2D &rclV) const;
void Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rclResultPolygonList) const;
bool Intersect (const Vector2D &rclV, double eps) const;
BoundBox2d CalcBoundBox (void) const;
bool Contains (const Vector2d &rclV) const;
void Intersect (const Polygon2d &rclPolygon, std::list<Polygon2d> &rclResultPolygonList) const;
bool Intersect (const Vector2d &rclV, double eps) const;
private:
std::vector<Vector2D> _aclVct;
std::vector<Vector2d> _aclVct;
};
/** INLINES ********************************************/
inline Vector2D::Vector2D (void)
: fX(0.0), fY(0.0)
inline Vector2d::Vector2d (void)
: x(0.0), y(0.0)
{
}
inline Vector2D::Vector2D (float x, float y)
: fX (x), fY (y)
inline Vector2d::Vector2d (float x, float y)
: x(x), y(y)
{
}
inline Vector2D::Vector2D (double x, double y)
: fX(x),
fY(y)
inline Vector2d::Vector2d (double x, double y)
: x(x), y(y)
{
}
inline Vector2D::Vector2D (const Vector2D &rclVct)
: fX(rclVct.fX), fY(rclVct.fY)
inline Vector2d::Vector2d (const Vector2d &rclVct)
: x(rclVct.x), y(rclVct.y)
{
}
inline double Vector2D::Length (void) const
inline double Vector2d::Length (void) const
{
return sqrt ((fX * fX) + (fY * fY));
return sqrt ((x * x) + (y * y));
}
inline Vector2D& Vector2D::operator= (const Vector2D &rclVct)
inline Vector2d& Vector2d::operator= (const Vector2d &rclVct)
{
fX = rclVct.fX;
fY = rclVct.fY;
x = rclVct.x;
y = rclVct.y;
return *this;
}
inline bool Vector2D::operator== (const Vector2D &rclVct) const
inline bool Vector2d::operator== (const Vector2d &rclVct) const
{
return (fX == rclVct.fX) && (fY == rclVct.fY);
return (x == rclVct.x) && (y == rclVct.y);
}
inline Vector2D Vector2D::operator+ (const Vector2D &rclVct) const
inline Vector2d Vector2d::operator+ (const Vector2d &rclVct) const
{
return Vector2D(fX + rclVct.fX, fY + rclVct.fY);
return Vector2d(x + rclVct.x, y + rclVct.y);
}
inline Vector2D Vector2D::operator- (const Vector2D &rclVct) const
inline Vector2d Vector2d::operator- (const Vector2d &rclVct) const
{
return Vector2D(fX - rclVct.fX, fY - rclVct.fY);
return Vector2d(x - rclVct.x, y - rclVct.y);
}
inline double Vector2D::operator* (const Vector2D &rclVct) const
inline double Vector2d::operator* (const Vector2d &rclVct) const
{
return (fX * rclVct.fX) + (fY * rclVct.fY);
return (x * rclVct.x) + (y * rclVct.y);
}
inline Vector2D Vector2D::operator/ (double c) const
inline Vector2d Vector2d::operator/ (double c) const
{
return Vector2D(fX / c, fY / c);
return Vector2d(x / c, y / c);
}
inline void Vector2D::Scale (double fS)
inline void Vector2d::Scale (double fS)
{
fX *= fS;
fY *= fS;
x *= fS;
y *= fS;
}
inline void Vector2D::Normalize (void)
inline void Vector2d::Normalize (void)
{
double fLen = Length();
if (fLen != 0.0f)
{
fX /= fLen;
fY /= fLen;
x /= fLen;
y /= fLen;
}
}
inline void Vector2D::Set (double fPX, double fPY)
inline void Vector2d::Set (double fPX, double fPY)
{
fX = fPX;
fY = fPY;
x = fPX;
y = fPY;
}
inline Polygon2D::Polygon2D (const Polygon2D &rclPoly)
inline Polygon2d::Polygon2d (const Polygon2d &rclPoly)
{
*this = rclPoly;
}
inline Polygon2D& Polygon2D::operator = (const Polygon2D &rclP)
inline Polygon2d& Polygon2d::operator = (const Polygon2d &rclP)
{
_aclVct = rclP._aclVct;
return *this;
}
inline void Polygon2D::DeleteAll (void)
inline void Polygon2d::DeleteAll (void)
{
_aclVct.clear();
}
inline size_t Polygon2D::GetCtVectors (void) const
inline size_t Polygon2d::GetCtVectors (void) const
{
return _aclVct.size ();
}
inline bool Polygon2D::Add (const Vector2D &rclVct)
inline bool Polygon2d::Add (const Vector2d &rclVct)
{
_aclVct.push_back (rclVct);
return true;
}
inline bool Polygon2D::Delete (size_t ulNdx)
inline bool Polygon2d::Delete (size_t ulNdx)
{
if ( ulNdx < _aclVct.size() )
{
std::vector<Vector2D>::iterator it = _aclVct.begin() + ulNdx;
std::vector<Vector2d>::iterator it = _aclVct.begin() + ulNdx;
_aclVct.erase ( it );
return true;
}
@@ -283,101 +282,101 @@ inline bool Polygon2D::Delete (size_t ulNdx)
return false;
}
inline Vector2D& Polygon2D::operator[] (size_t ulNdx) const
inline Vector2d& Polygon2d::operator[] (size_t ulNdx) const
{
return (Vector2D&) _aclVct[ulNdx];
return (Vector2d&) _aclVct[ulNdx];
}
inline Vector2D& Polygon2D::At (size_t ulNdx) const
inline Vector2d& Polygon2d::At (size_t ulNdx) const
{
return (Vector2D&) _aclVct[ulNdx];
return (Vector2d&) _aclVct[ulNdx];
}
inline Line2D::Line2D (const Line2D &rclLine)
inline Line2d::Line2d (const Line2d &rclLine)
: clV1 (rclLine.clV1),
clV2 (rclLine.clV2)
{
}
inline Line2D::Line2D (const Vector2D &rclV1, const Vector2D &rclV2)
inline Line2d::Line2d (const Vector2d &rclV1, const Vector2d &rclV2)
: clV1 (rclV1), clV2 (rclV2)
{
}
inline double Line2D::Length (void) const
inline double Line2d::Length (void) const
{
return (clV2 - clV1).Length ();
}
inline Line2D& Line2D::operator= (const Line2D& rclLine)
inline Line2d& Line2d::operator= (const Line2d& rclLine)
{
clV1 = rclLine.clV1;
clV2 = rclLine.clV2;
return *this;
}
inline bool Line2D::operator== (const Line2D& rclLine) const
inline bool Line2d::operator== (const Line2d& rclLine) const
{
return (clV1 == rclLine.clV1) && (clV2 == rclLine.clV2);
}
inline bool Line2D::Contains (const Vector2D &rclV) const
inline bool Line2d::Contains (const Vector2d &rclV) const
{
return CalcBoundBox ().Contains (rclV);
}
inline BoundBox2D::BoundBox2D (void)
inline BoundBox2d::BoundBox2d (void)
{
fMinX = fMinY = DOUBLE_MAX;
fMaxX = fMaxY = - DOUBLE_MAX;
MinX = MinY = DOUBLE_MAX;
MaxX = MaxY = - DOUBLE_MAX;
}
inline BoundBox2D::BoundBox2D (const BoundBox2D &rclBB)
: fMinX (rclBB.fMinX),
fMinY (rclBB.fMinY),
fMaxX (rclBB.fMaxX),
fMaxY (rclBB.fMaxY)
inline BoundBox2d::BoundBox2d (const BoundBox2d &rclBB)
: MinX (rclBB.MinX),
MinY (rclBB.MinY),
MaxX (rclBB.MaxX),
MaxY (rclBB.MaxY)
{
}
inline BoundBox2D::BoundBox2D (double fX1, double fY1, double fX2, double fY2)
inline BoundBox2d::BoundBox2d (double fX1, double fY1, double fX2, double fY2)
{
fMinX = std::min<double>( fX1, fX2 );
fMaxX = std::max<double>( fX1, fX2 );
fMinY = std::min<double>( fY1, fY2 );
fMaxY = std::max<double>( fY1, fY2 );
MinX = std::min<double>( fX1, fX2 );
MaxX = std::max<double>( fX1, fX2 );
MinY = std::min<double>( fY1, fY2 );
MaxY = std::max<double>( fY1, fY2 );
}
inline bool BoundBox2D::IsValid (void)
inline bool BoundBox2d::IsValid (void)
{
return (fMaxX >= fMinX) && (fMaxY >= fMinY);
return (MaxX >= MinX) && (MaxY >= MinY);
}
inline BoundBox2D& BoundBox2D::operator= (const BoundBox2D& rclBB)
inline BoundBox2d& BoundBox2d::operator= (const BoundBox2d& rclBB)
{
fMinX = rclBB.fMinX;
fMinY = rclBB.fMinY;
fMaxX = rclBB.fMaxX;
fMaxY = rclBB.fMaxY;
MinX = rclBB.MinX;
MinY = rclBB.MinY;
MaxX = rclBB.MaxX;
MaxY = rclBB.MaxY;
return *this;
}
inline bool BoundBox2D::operator== (const BoundBox2D& rclBB) const
inline bool BoundBox2d::operator== (const BoundBox2d& rclBB) const
{
return
(fMinX == rclBB.fMinX) &&
(fMinY == rclBB.fMinY) &&
(fMaxX == rclBB.fMaxX) &&
(fMaxY == rclBB.fMaxY);
(MinX == rclBB.MinX) &&
(MinY == rclBB.MinY) &&
(MaxX == rclBB.MaxX) &&
(MaxY == rclBB.MaxY);
}
inline void BoundBox2D::Add(const Vector2D &rclVct)
inline void BoundBox2d::Add(const Vector2d &rclVct)
{
fMinX = std::min<double>(fMinX, rclVct.fX);
fMinY = std::min<double>(fMinY, rclVct.fY);
fMaxX = std::max<double>(fMaxX, rclVct.fX);
fMaxY = std::max<double>(fMaxY, rclVct.fY);
MinX = std::min<double>(MinX, rclVct.x);
MinY = std::min<double>(MinY, rclVct.y);
MaxX = std::max<double>(MaxX, rclVct.x);
MaxY = std::max<double>(MaxY, rclVct.y);
}
} // namespace Base