From c3bd10430bf75410f0d35581966c113861ffc430 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Sun, 24 Mar 2013 19:10:29 +0430 Subject: [PATCH] Moved Tools2D from float to double --- src/Base/Tools2D.cpp | 48 ++++++++++++++++----------------- src/Base/Tools2D.h | 64 ++++++++++++++++++++++---------------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/Base/Tools2D.cpp b/src/Base/Tools2D.cpp index 978b8cb46..8af9f88b4 100644 --- a/src/Base/Tools2D.cpp +++ b/src/Base/Tools2D.cpp @@ -23,7 +23,7 @@ #include "PreCompiled.h" -#ifndef _PreComp_ +#ifndef _PreComp_ # include # include #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 (clV1.fX, clV2.fX); - clBB.fMinY = std::min (clV1.fY, clV2.fY); - clBB.fMaxX = std::max (clV1.fX, clV2.fX); - clBB.fMaxY = std::max (clV1.fY, clV2.fY); + clBB.fMinX = std::min (clV1.fX, clV2.fX); + clBB.fMinY = std::min (clV1.fY, clV2.fY); + clBB.fMaxX = std::max (clV1.fX, clV2.fX); + clBB.fMaxY = std::max (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 (clBB.fMinX, _aclVct[i].fX); - clBB.fMinY = std::min (clBB.fMinY, _aclVct[i].fY); - clBB.fMaxX = std::max (clBB.fMaxX, _aclVct[i].fX); - clBB.fMaxY = std::max (clBB.fMaxY, _aclVct[i].fY); + clBB.fMinX = std::min (clBB.fMinX, _aclVct[i].fX); + clBB.fMinY = std::min (clBB.fMinY, _aclVct[i].fY); + clBB.fMaxX = std::max (clBB.fMaxX, _aclVct[i].fX); + clBB.fMaxY = std::max (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 &rc Line2D clLine(clPt0, clPt1); // try to intersect with each line of the trim-polygon - std::set afIntersections; // set of intersections (sorted by line parameter) + std::set 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 &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::iterator pF = afIntersections.begin(); pF != afIntersections.end(); pF++) + for (std::set::iterator pF = afIntersections.begin(); pF != afIntersections.end(); pF++) { // intersection point Vector2D clPtIS = clLine.FromPos(*pF); diff --git a/src/Base/Tools2D.h b/src/Base/Tools2D.h index 84c1c0bcd..527793392 100644 --- a/src/Base/Tools2D.h +++ b/src/Base/Tools2D.h @@ -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(fMinX, rclVct.fX); - fMinY = std::min(fMinY, rclVct.fY); - fMaxX = std::max(fMaxX, rclVct.fX); - fMaxY = std::max(fMaxY, rclVct.fY); + fMinX = std::min(fMinX, rclVct.fX); + fMinY = std::min(fMinY, rclVct.fY); + fMaxX = std::max(fMaxX, rclVct.fX); + fMaxY = std::max(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( fX1, fX2 ); - fMaxX = std::max( fX1, fX2 ); - fMinY = std::min( fY1, fY2 ); - fMaxY = std::max( fY1, fY2 ); + fMinX = std::min( fX1, fX2 ); + fMaxX = std::max( fX1, fX2 ); + fMinY = std::min( fY1, fY2 ); + fMaxY = std::max( fY1, fY2 ); } inline bool BoundBox2D::IsValid (void)