Moved Tools2D from float to double
This commit is contained in:
parent
97d6564f51
commit
c3bd10430b
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#ifndef _PreComp_
|
||||
# include <cstdlib>
|
||||
# include <set>
|
||||
#endif
|
||||
|
@ -33,22 +33,22 @@
|
|||
|
||||
using namespace Base;
|
||||
|
||||
float Vector2D::GetAngle (const Vector2D &rclVect) const
|
||||
double Vector2D::GetAngle (const Vector2D &rclVect) const
|
||||
{
|
||||
float fDivid, fNum;
|
||||
double fDivid, fNum;
|
||||
|
||||
fDivid = Length() * rclVect.Length();
|
||||
|
||||
if ((fDivid < -1e-10f) || (fDivid > 1e-10f))
|
||||
if ((fDivid < -1e-10) || (fDivid > 1e-10))
|
||||
{
|
||||
fNum = (*this * rclVect) / fDivid;
|
||||
if (fNum < -1)
|
||||
return F_PI;
|
||||
else
|
||||
if (fNum > 1)
|
||||
return 0.0F;
|
||||
return 0.0;
|
||||
else
|
||||
return float(acos(fNum));
|
||||
return acos(fNum);
|
||||
}
|
||||
else
|
||||
return -FLOAT_MAX; // division by zero
|
||||
|
@ -56,8 +56,8 @@ float Vector2D::GetAngle (const Vector2D &rclVect) const
|
|||
|
||||
void Vector2D::ProjToLine (const Vector2D &rclPt, const Vector2D &rclLine)
|
||||
{
|
||||
float l = rclLine.Length();
|
||||
float t1 = (rclPt * rclLine) / l;
|
||||
double l = rclLine.Length();
|
||||
double t1 = (rclPt * rclLine) / l;
|
||||
Vector2D clNormal = rclLine;
|
||||
clNormal.Normalize();
|
||||
clNormal.Scale(t1);
|
||||
|
@ -178,16 +178,16 @@ bool BoundBox2D::Contains (const Vector2D &rclV) const
|
|||
BoundBox2D Line2D::CalcBoundBox (void) const
|
||||
{
|
||||
BoundBox2D clBB;
|
||||
clBB.fMinX = std::min<float> (clV1.fX, clV2.fX);
|
||||
clBB.fMinY = std::min<float> (clV1.fY, clV2.fY);
|
||||
clBB.fMaxX = std::max<float> (clV1.fX, clV2.fX);
|
||||
clBB.fMaxY = std::max<float> (clV1.fY, clV2.fY);
|
||||
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);
|
||||
return clBB;
|
||||
}
|
||||
|
||||
bool Line2D::Intersect (const Line2D& rclLine, Vector2D &rclV) const
|
||||
{
|
||||
float m1, m2, b1, b2;
|
||||
double m1, m2, b1, b2;
|
||||
|
||||
// calc coefficients
|
||||
if (fabs (clV2.fX - clV1.fX) > 1e-10)
|
||||
|
@ -225,7 +225,7 @@ bool Line2D::Intersect (const Line2D& rclLine, Vector2D &rclV) const
|
|||
return true; /*** RETURN TRUE (intersection) **********/
|
||||
}
|
||||
|
||||
Vector2D Line2D::FromPos (float fDistance) const
|
||||
Vector2D Line2D::FromPos (double fDistance) const
|
||||
{
|
||||
Vector2D clDir(clV2 - clV1);
|
||||
clDir.Normalize();
|
||||
|
@ -249,18 +249,18 @@ BoundBox2D Polygon2D::CalcBoundBox (void) const
|
|||
BoundBox2D clBB;
|
||||
for (i = 0; i < _aclVct.size(); i++)
|
||||
{
|
||||
clBB.fMinX = std::min<float> (clBB.fMinX, _aclVct[i].fX);
|
||||
clBB.fMinY = std::min<float> (clBB.fMinY, _aclVct[i].fY);
|
||||
clBB.fMaxX = std::max<float> (clBB.fMaxX, _aclVct[i].fX);
|
||||
clBB.fMaxY = std::max<float> (clBB.fMaxY, _aclVct[i].fY);
|
||||
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);
|
||||
}
|
||||
return clBB;
|
||||
}
|
||||
|
||||
static short _CalcTorsion (float *pfLine, float fX, float fY)
|
||||
static short _CalcTorsion (double *pfLine, double fX, double fY)
|
||||
{
|
||||
short sQuad[2], i;
|
||||
float fResX;
|
||||
double fResX;
|
||||
|
||||
// Klassifizierung der beiden Polygonpunkte in Quadranten
|
||||
for (i = 0; i < 2; i++)
|
||||
|
@ -297,7 +297,7 @@ bool Polygon2D::Contains (const Vector2D &rclV) const
|
|||
// Ermittelt mit dem Verfahren der Windungszahl, ob ein Punkt innerhalb
|
||||
// eines Polygonzugs enthalten ist.
|
||||
// Summe aller Windungszahlen gibt an, ob ja oder nein.
|
||||
float pfTmp[4];
|
||||
double pfTmp[4];
|
||||
unsigned long i;
|
||||
short sTorsion = 0;
|
||||
|
||||
|
@ -358,7 +358,7 @@ void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rc
|
|||
Line2D clLine(clPt0, clPt1);
|
||||
|
||||
// try to intersect with each line of the trim-polygon
|
||||
std::set<float> afIntersections; // set of intersections (sorted by line parameter)
|
||||
std::set<double> afIntersections; // set of intersections (sorted by line parameter)
|
||||
Vector2D clTrimPt2; // second line point
|
||||
for (size_t i = 0; i < ulTrimCt; i++)
|
||||
{
|
||||
|
@ -369,14 +369,14 @@ void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rc
|
|||
if (clLine.IntersectAndContain(clToTrimLine, clV) == true)
|
||||
{
|
||||
// save line parameter of intersection point
|
||||
float fDist = (clV - clPt0).Length();
|
||||
double fDist = (clV - clPt0).Length();
|
||||
afIntersections.insert(fDist);
|
||||
}
|
||||
}
|
||||
|
||||
if (afIntersections.size() > 0) // intersections founded
|
||||
{
|
||||
for (std::set<float>::iterator pF = afIntersections.begin(); pF != afIntersections.end(); pF++)
|
||||
for (std::set<double>::iterator pF = afIntersections.begin(); pF != afIntersections.end(); pF++)
|
||||
{
|
||||
// intersection point
|
||||
Vector2D clPtIS = clLine.FromPos(*pF);
|
||||
|
|
|
@ -45,7 +45,7 @@ class Polygon2D;
|
|||
class BaseExport Vector2D
|
||||
{
|
||||
public:
|
||||
float fX, fY;
|
||||
double fX, fY;
|
||||
|
||||
inline Vector2D (void);
|
||||
inline Vector2D (float x, float y);
|
||||
|
@ -53,19 +53,19 @@ public:
|
|||
inline Vector2D (const Vector2D &rclVct);
|
||||
|
||||
// methods
|
||||
inline float Length (void) const;
|
||||
inline double Length (void) const;
|
||||
|
||||
// operators
|
||||
inline Vector2D& operator= (const Vector2D &rclVct);
|
||||
inline float operator* (const Vector2D &rclVct) const;
|
||||
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 void Set (float fPX, float fPY);
|
||||
inline void Scale (float fS);
|
||||
inline void Set (double fPX, double fPY);
|
||||
inline void Scale (double fS);
|
||||
inline void Normalize (void);
|
||||
float GetAngle (const Vector2D &rclVect) const;
|
||||
double GetAngle (const Vector2D &rclVect) const;
|
||||
void ProjToLine (const Vector2D &rclPt, const Vector2D &rclLine);
|
||||
};
|
||||
|
||||
|
@ -77,11 +77,11 @@ public:
|
|||
class BaseExport BoundBox2D
|
||||
{
|
||||
public:
|
||||
float fMinX, fMinY, fMaxX, fMaxY;
|
||||
double fMinX, fMinY, fMaxX, fMaxY;
|
||||
|
||||
inline BoundBox2D (void);
|
||||
inline BoundBox2D (const BoundBox2D &rclBB);
|
||||
inline BoundBox2D (float fX1, float fY1, float fX2, float fY2);
|
||||
inline BoundBox2D (double fX1, double fY1, double fX2, double fY2);
|
||||
inline bool IsValid (void);
|
||||
|
||||
// operators
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
bool operator|| (const Polygon2D &rclPoly) const;
|
||||
inline void operator &= (const Vector2D &rclVct);
|
||||
|
||||
void SetVoid (void) { fMinX = fMinY = FLOAT_MAX; fMaxX = fMaxY = -FLOAT_MAX; }
|
||||
void SetVoid (void) { fMinX = fMinY = DOUBLE_MAX; fMaxX = fMaxY = -DOUBLE_MAX; }
|
||||
|
||||
// misc
|
||||
bool Contains (const Vector2D &rclV) const;
|
||||
|
@ -113,7 +113,7 @@ public:
|
|||
inline Line2D (const Vector2D &rclV1, const Vector2D &rclV2);
|
||||
|
||||
// methods
|
||||
inline float Length (void) const;
|
||||
inline double Length (void) const;
|
||||
BoundBox2D CalcBoundBox (void) const;
|
||||
|
||||
// operators
|
||||
|
@ -124,7 +124,7 @@ public:
|
|||
inline bool Contains (const Vector2D &rclV) const;
|
||||
bool Intersect (const Line2D& rclLine, Vector2D &rclV) const;
|
||||
bool IntersectAndContain (const Line2D& rclLine, Vector2D &rclV) const;
|
||||
Vector2D FromPos (float fDistance) const;
|
||||
Vector2D FromPos (double fDistance) const;
|
||||
};
|
||||
|
||||
/** Polygon2D ********************************************/
|
||||
|
@ -162,14 +162,14 @@ private:
|
|||
|
||||
inline void BoundBox2D::operator &= (const Vector2D &rclVct)
|
||||
{
|
||||
fMinX = std::min<float>(fMinX, rclVct.fX);
|
||||
fMinY = std::min<float>(fMinY, rclVct.fY);
|
||||
fMaxX = std::max<float>(fMaxX, rclVct.fX);
|
||||
fMaxY = std::max<float>(fMaxY, rclVct.fY);
|
||||
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);
|
||||
}
|
||||
|
||||
inline Vector2D::Vector2D (void)
|
||||
: fX(0.0f), fY(0.0f)
|
||||
: fX(0.0), fY(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -179,8 +179,8 @@ inline Vector2D::Vector2D (float x, float y)
|
|||
}
|
||||
|
||||
inline Vector2D::Vector2D (double x, double y)
|
||||
: fX(float(x)),
|
||||
fY(float(y))
|
||||
: fX(x),
|
||||
fY(y)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -189,9 +189,9 @@ inline Vector2D::Vector2D (const Vector2D &rclVct)
|
|||
{
|
||||
}
|
||||
|
||||
inline float Vector2D::Length (void) const
|
||||
inline double Vector2D::Length (void) const
|
||||
{
|
||||
return (float)sqrt ((fX * fX) + (fY * fY));
|
||||
return sqrt ((fX * fX) + (fY * fY));
|
||||
}
|
||||
|
||||
inline Vector2D& Vector2D::operator= (const Vector2D &rclVct)
|
||||
|
@ -216,12 +216,12 @@ inline Vector2D Vector2D::operator- (const Vector2D &rclVct) const
|
|||
return Vector2D(fX - rclVct.fX, fY - rclVct.fY);
|
||||
}
|
||||
|
||||
inline float Vector2D::operator* (const Vector2D &rclVct) const
|
||||
inline double Vector2D::operator* (const Vector2D &rclVct) const
|
||||
{
|
||||
return (fX * rclVct.fX) + (fY * rclVct.fY);
|
||||
}
|
||||
|
||||
inline void Vector2D::Scale (float fS)
|
||||
inline void Vector2D::Scale (double fS)
|
||||
{
|
||||
fX *= fS;
|
||||
fY *= fS;
|
||||
|
@ -229,7 +229,7 @@ inline void Vector2D::Scale (float fS)
|
|||
|
||||
inline void Vector2D::Normalize (void)
|
||||
{
|
||||
float fLen = Length();
|
||||
double fLen = Length();
|
||||
if (fLen != 0.0f)
|
||||
{
|
||||
fX /= fLen;
|
||||
|
@ -237,7 +237,7 @@ inline void Vector2D::Normalize (void)
|
|||
}
|
||||
}
|
||||
|
||||
inline void Vector2D::Set (float fPX, float fPY)
|
||||
inline void Vector2D::Set (double fPX, double fPY)
|
||||
{
|
||||
fX = fPX;
|
||||
fY = fPY;
|
||||
|
@ -304,7 +304,7 @@ inline Line2D::Line2D (const Vector2D &rclV1, const Vector2D &rclV2)
|
|||
{
|
||||
}
|
||||
|
||||
inline float Line2D::Length (void) const
|
||||
inline double Line2D::Length (void) const
|
||||
{
|
||||
return (clV2 - clV1).Length ();
|
||||
}
|
||||
|
@ -328,8 +328,8 @@ inline bool Line2D::Contains (const Vector2D &rclV) const
|
|||
|
||||
inline BoundBox2D::BoundBox2D (void)
|
||||
{
|
||||
fMinX = fMinY = FLOAT_MAX;
|
||||
fMaxX = fMaxY = - FLOAT_MAX;
|
||||
fMinX = fMinY = DOUBLE_MAX;
|
||||
fMaxX = fMaxY = - DOUBLE_MAX;
|
||||
}
|
||||
|
||||
inline BoundBox2D::BoundBox2D (const BoundBox2D &rclBB)
|
||||
|
@ -340,12 +340,12 @@ inline BoundBox2D::BoundBox2D (const BoundBox2D &rclBB)
|
|||
{
|
||||
}
|
||||
|
||||
inline BoundBox2D::BoundBox2D (float fX1, float fY1, float fX2, float fY2)
|
||||
inline BoundBox2D::BoundBox2D (double fX1, double fY1, double fX2, double fY2)
|
||||
{
|
||||
fMinX = std::min<float>( fX1, fX2 );
|
||||
fMaxX = std::max<float>( fX1, fX2 );
|
||||
fMinY = std::min<float>( fY1, fY2 );
|
||||
fMaxY = std::max<float>( fY1, 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 );
|
||||
}
|
||||
|
||||
inline bool BoundBox2D::IsValid (void)
|
||||
|
|
Loading…
Reference in New Issue
Block a user