diff options
55 files changed, 7384 insertions, 7452 deletions
diff --git a/basegfx/inc/basegfx/curve/b2dbeziertools.hxx b/basegfx/inc/basegfx/curve/b2dbeziertools.hxx index f9d72cb47873..c3fa31095e10 100644 --- a/basegfx/inc/basegfx/curve/b2dbeziertools.hxx +++ b/basegfx/inc/basegfx/curve/b2dbeziertools.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dbeziertools.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: thb $ $Date: 2003-11-12 12:09:50 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,169 +71,160 @@ namespace basegfx { - namespace polygon - { - class B2DPolygon; - } + class B2DPolygon; + class B2DCubicBezier; + class B2DQuadraticBezier; - namespace curve - { + /** Subdivide given cubic bezier segment. - class B2DCubicBezier; - class B2DQuadraticBezier; + This function adaptively subdivides the given bezier + segment into as much straight line segments as necessary, + such that the maximal orthogonal distance from any of the + segments to the true curve is less than the given error + value. - /** Subdivide given cubic bezier segment. + @param rPoly + Output polygon. The subdivided bezier segment is added to + this polygon via B2DPolygon::append(). - This function adaptively subdivides the given bezier - segment into as much straight line segments as necessary, - such that the maximal orthogonal distance from any of the - segments to the true curve is less than the given error - value. + @param rCurve + The cubic bezier curve to subdivide - @param rPoly - Output polygon. The subdivided bezier segment is added to - this polygon via B2DPolygon::append(). + @param distanceBound + Bound on the maximal distance of the approximation to the + true curve. - @param rCurve - The cubic bezier curve to subdivide - - @param distanceBound - Bound on the maximal distance of the approximation to the - true curve. - - @return the number of line segments created - */ - sal_Int32 adaptiveSubdivideByDistance( polygon::B2DPolygon& rPoly, - const B2DCubicBezier& rCurve, - double distanceBound ); + @return the number of line segments created + */ + sal_Int32 adaptiveSubdivideByDistance( B2DPolygon& rPoly, + const B2DCubicBezier& rCurve, + double distanceBound ); - /** Subdivide given cubic bezier segment. + /** Subdivide given cubic bezier segment. - This function adaptively subdivides the given bezier - segment into as much quadratic bezier curve segments as - necessary, such that the maximal orthogonal distance from - any of the segments to the true curve is less than the - given error value. + This function adaptively subdivides the given bezier + segment into as much quadratic bezier curve segments as + necessary, such that the maximal orthogonal distance from + any of the segments to the true curve is less than the + given error value. - @param rPoly - Output polygon. The subdivided bezier segments are added to - this polygon via B2DPolygon::append(). + @param rPoly + Output polygon. The subdivided bezier segments are added to + this polygon via B2DPolygon::append(). - @param rCurve - The cubic bezier curve to subdivide + @param rCurve + The cubic bezier curve to subdivide - @param distanceBound - Bound on the maximal distance of the approximation to the - true curve. + @param distanceBound + Bound on the maximal distance of the approximation to the + true curve. - @return the number of quadratic curve segments created - */ - sal_Int32 adaptiveDegreeReductionByDistance( polygon::B2DPolygon& rPoly, - const B2DCubicBezier& rCurve, - double distanceBound ); + @return the number of quadratic curve segments created + */ + sal_Int32 adaptiveDegreeReductionByDistance( B2DPolygon& rPoly, + const B2DCubicBezier& rCurve, + double distanceBound ); - /** Subdivide given cubic bezier segment. + /** Subdivide given cubic bezier segment. - This function adaptively subdivides the given bezier - segment into as much straight line segments as necessary, - such that the maximal angle change between any adjacent - lines is less than the given error value. + This function adaptively subdivides the given bezier + segment into as much straight line segments as necessary, + such that the maximal angle change between any adjacent + lines is less than the given error value. - @param rPoly - Output polygon. The subdivided bezier segment is added to - this polygon via B2DPolygon::append(). + @param rPoly + Output polygon. The subdivided bezier segment is added to + this polygon via B2DPolygon::append(). - @param rCurve - The cubic bezier curve to subdivide + @param rCurve + The cubic bezier curve to subdivide - @param angleBound - Bound on the maximal angle difference between two adjacent - polygon lines, in degrees. + @param angleBound + Bound on the maximal angle difference between two adjacent + polygon lines, in degrees. - @return the number of line segments created - */ - sal_Int32 adaptiveSubdivideByAngle( polygon::B2DPolygon& rPoly, - const B2DCubicBezier& rCurve, - double angleBound ); + @return the number of line segments created + */ + sal_Int32 adaptiveSubdivideByAngle( B2DPolygon& rPoly, + const B2DCubicBezier& rCurve, + double angleBound ); - /** Subdivide given cubic bezier segment. + /** Subdivide given cubic bezier segment. - This function adaptively subdivides the given bezier - segment into as much quadratic bezier curve segments as - necessary, such that the maximal angle difference of the - control vectors of any generated quadratic bezier segment - is less than the given error value. + This function adaptively subdivides the given bezier + segment into as much quadratic bezier curve segments as + necessary, such that the maximal angle difference of the + control vectors of any generated quadratic bezier segment + is less than the given error value. - @param rPoly - Output polygon. The subdivided bezier segments are added to - this polygon via B2DPolygon::append(). + @param rPoly + Output polygon. The subdivided bezier segments are added to + this polygon via B2DPolygon::append(). - @param rCurve - The cubic bezier curve to subdivide + @param rCurve + The cubic bezier curve to subdivide - @param distanceBound - Bound on the maximal angle difference between the control - vectors of any of the generated quadratic bezier - segments. The angle must be given in degrees. + @param distanceBound + Bound on the maximal angle difference between the control + vectors of any of the generated quadratic bezier + segments. The angle must be given in degrees. - @return the number of quadratic curve segments created - */ - sal_Int32 adaptiveDegreeReductionByAngle( polygon::B2DPolygon& rPoly, - const B2DCubicBezier& rCurve, - double angleBound ); + @return the number of quadratic curve segments created + */ + sal_Int32 adaptiveDegreeReductionByAngle( B2DPolygon& rPoly, + const B2DCubicBezier& rCurve, + double angleBound ); - /** Subdivide given quadratic bezier segment. + /** Subdivide given quadratic bezier segment. - This function adaptively subdivides the given bezier - segment into as much straight line segments as necessary, - such that the maximal orthogonal distance from any of the - segments to the true curve is less than the given error - value. + This function adaptively subdivides the given bezier + segment into as much straight line segments as necessary, + such that the maximal orthogonal distance from any of the + segments to the true curve is less than the given error + value. - @param rPoly - Output polygon. The subdivided bezier segment is added to - this polygon via B2DPolygon::append(). + @param rPoly + Output polygon. The subdivided bezier segment is added to + this polygon via B2DPolygon::append(). - @param rCurve - The cubic bezier curve to subdivide + @param rCurve + The cubic bezier curve to subdivide - @param distanceBound - Bound on the maximal distance of the approximation to the - true curve + @param distanceBound + Bound on the maximal distance of the approximation to the + true curve - @return the number of line segments created - */ - sal_Int32 adaptiveSubdivideByDistance( polygon::B2DPolygon& rPoly, - const B2DQuadraticBezier& rCurve, - double distanceBound ); - - /** Subdivide given quadratic bezier segment. + @return the number of line segments created + */ + sal_Int32 adaptiveSubdivideByDistance( B2DPolygon& rPoly, + const B2DQuadraticBezier& rCurve, + double distanceBound ); - This function adaptively subdivides the given bezier - segment into as much straight line segments as necessary, - such that the maximal angle change between any adjacent - lines is less than the given error value. + /** Subdivide given quadratic bezier segment. - @param rPoly - Output polygon. The subdivided bezier segment is added to - this polygon via B2DPolygon::append(). + This function adaptively subdivides the given bezier + segment into as much straight line segments as necessary, + such that the maximal angle change between any adjacent + lines is less than the given error value. - @param rCurve - The cubic bezier curve to subdivide + @param rPoly + Output polygon. The subdivided bezier segment is added to + this polygon via B2DPolygon::append(). - @param angleBound - Bound on the maximal angle difference between two adjacent - polygon lines, in degrees. + @param rCurve + The cubic bezier curve to subdivide - @return the number of line segments created - */ - sal_Int32 adaptiveSubdivideByAngle( polygon::B2DPolygon& rPoly, - const B2DQuadraticBezier& rCurve, - double angleBound ); + @param angleBound + Bound on the maximal angle difference between two adjacent + polygon lines, in degrees. - } + @return the number of line segments created + */ + sal_Int32 adaptiveSubdivideByAngle( B2DPolygon& rPoly, + const B2DQuadraticBezier& rCurve, + double angleBound ); } #endif // _BGFX_CURVE_B2DBEZIERTOOLS_HXX2 diff --git a/basegfx/inc/basegfx/curve/b2dcubicbezier.hxx b/basegfx/inc/basegfx/curve/b2dcubicbezier.hxx index 9761367bdd1b..83b18f9c75c5 100644 --- a/basegfx/inc/basegfx/curve/b2dcubicbezier.hxx +++ b/basegfx/inc/basegfx/curve/b2dcubicbezier.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dcubicbezier.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-06 16:30:23 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,50 +70,47 @@ namespace basegfx { - namespace curve + class B2DCubicBezier { - class B2DCubicBezier - { - ::basegfx::point::B2DPoint maStartPoint; - ::basegfx::point::B2DPoint maEndPoint; - ::basegfx::point::B2DPoint maControlPointA; - ::basegfx::point::B2DPoint maControlPointB; + ::basegfx::B2DPoint maStartPoint; + ::basegfx::B2DPoint maEndPoint; + ::basegfx::B2DPoint maControlPointA; + ::basegfx::B2DPoint maControlPointB; - public: - B2DCubicBezier(); - B2DCubicBezier(const B2DCubicBezier& rBezier); - B2DCubicBezier(const ::basegfx::point::B2DPoint& rStart, const ::basegfx::point::B2DPoint& rEnd); - B2DCubicBezier(const ::basegfx::point::B2DPoint& rStart, const ::basegfx::point::B2DPoint& rControlPointA, - const ::basegfx::point::B2DPoint& rControlPointB, const ::basegfx::point::B2DPoint& rEnd); - ~B2DCubicBezier(); + public: + B2DCubicBezier(); + B2DCubicBezier(const B2DCubicBezier& rBezier); + B2DCubicBezier(const ::basegfx::B2DPoint& rStart, const ::basegfx::B2DPoint& rEnd); + B2DCubicBezier(const ::basegfx::B2DPoint& rStart, const ::basegfx::B2DPoint& rControlPointA, + const ::basegfx::B2DPoint& rControlPointB, const ::basegfx::B2DPoint& rEnd); + ~B2DCubicBezier(); - // assignment operator - B2DCubicBezier& operator=(const B2DCubicBezier& rBezier); + // assignment operator + B2DCubicBezier& operator=(const B2DCubicBezier& rBezier); - // compare operators - sal_Bool operator==(const B2DCubicBezier& rBezier) const; - sal_Bool operator!=(const B2DCubicBezier& rBezier) const; + // compare operators + sal_Bool operator==(const B2DCubicBezier& rBezier) const; + sal_Bool operator!=(const B2DCubicBezier& rBezier) const; - // test if vectors are used - sal_Bool isBezier() const; + // test if vectors are used + sal_Bool isBezier() const; - // test if contained bezier is trivial and reset vectors accordingly - void testAndSolveTrivialBezier(); + // test if contained bezier is trivial and reset vectors accordingly + void testAndSolveTrivialBezier(); - // data interface - ::basegfx::point::B2DPoint getStartPoint() const { return maStartPoint; } - void setStartPoint(const ::basegfx::point::B2DPoint& rValue) { maStartPoint = rValue; } + // data interface + ::basegfx::B2DPoint getStartPoint() const { return maStartPoint; } + void setStartPoint(const ::basegfx::B2DPoint& rValue) { maStartPoint = rValue; } - ::basegfx::point::B2DPoint getEndPoint() const { return maEndPoint; } - void setEndPoint(const ::basegfx::point::B2DPoint& rValue) { maEndPoint = rValue; } + ::basegfx::B2DPoint getEndPoint() const { return maEndPoint; } + void setEndPoint(const ::basegfx::B2DPoint& rValue) { maEndPoint = rValue; } - ::basegfx::point::B2DPoint getControlPointA() const { return maControlPointA; } - void setControlPointA(const ::basegfx::point::B2DPoint& rValue) { maControlPointA = rValue; } + ::basegfx::B2DPoint getControlPointA() const { return maControlPointA; } + void setControlPointA(const ::basegfx::B2DPoint& rValue) { maControlPointA = rValue; } - ::basegfx::point::B2DPoint getControlPointB() const { return maControlPointB; } - void setControlPointB(const ::basegfx::point::B2DPoint& rValue) { maControlPointB = rValue; } - }; - } // end of namespace curve + ::basegfx::B2DPoint getControlPointB() const { return maControlPointB; } + void setControlPointB(const ::basegfx::B2DPoint& rValue) { maControlPointB = rValue; } + }; } // end of namespace basegfx #endif // _BGFX_CURVE_B2DCUBICBEZIER_HXX diff --git a/basegfx/inc/basegfx/curve/b2dquadraticbezier.hxx b/basegfx/inc/basegfx/curve/b2dquadraticbezier.hxx index 95f7eeda845a..6f81f26d97a7 100644 --- a/basegfx/inc/basegfx/curve/b2dquadraticbezier.hxx +++ b/basegfx/inc/basegfx/curve/b2dquadraticbezier.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dquadraticbezier.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-06 16:30:23 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,43 +70,40 @@ namespace basegfx { - namespace curve + class B2DQuadraticBezier { - class B2DQuadraticBezier - { - ::basegfx::point::B2DPoint maStartPoint; - ::basegfx::point::B2DPoint maEndPoint; - ::basegfx::point::B2DPoint maControlPoint; + ::basegfx::B2DPoint maStartPoint; + ::basegfx::B2DPoint maEndPoint; + ::basegfx::B2DPoint maControlPoint; - public: - B2DQuadraticBezier(); - B2DQuadraticBezier(const B2DQuadraticBezier& rBezier); - B2DQuadraticBezier(const ::basegfx::point::B2DPoint& rStart, const ::basegfx::point::B2DPoint& rEnd); - B2DQuadraticBezier(const ::basegfx::point::B2DPoint& rStart, - const ::basegfx::point::B2DPoint& rControlPoint, const ::basegfx::point::B2DPoint& rEnd); - ~B2DQuadraticBezier(); + public: + B2DQuadraticBezier(); + B2DQuadraticBezier(const B2DQuadraticBezier& rBezier); + B2DQuadraticBezier(const ::basegfx::B2DPoint& rStart, const ::basegfx::B2DPoint& rEnd); + B2DQuadraticBezier(const ::basegfx::B2DPoint& rStart, + const ::basegfx::B2DPoint& rControlPoint, const ::basegfx::B2DPoint& rEnd); + ~B2DQuadraticBezier(); - // assignment operator - B2DQuadraticBezier& operator=(const B2DQuadraticBezier& rBezier); + // assignment operator + B2DQuadraticBezier& operator=(const B2DQuadraticBezier& rBezier); - // compare operators - sal_Bool operator==(const B2DQuadraticBezier& rBezier) const; - sal_Bool operator!=(const B2DQuadraticBezier& rBezier) const; + // compare operators + sal_Bool operator==(const B2DQuadraticBezier& rBezier) const; + sal_Bool operator!=(const B2DQuadraticBezier& rBezier) const; - // test if control point is placed on the edge - sal_Bool isBezier() const; + // test if control point is placed on the edge + sal_Bool isBezier() const; - // data interface - ::basegfx::point::B2DPoint getStartPoint() const { return maStartPoint; } - void setStartPoint(const ::basegfx::point::B2DPoint& rValue) { maStartPoint = rValue; } + // data interface + ::basegfx::B2DPoint getStartPoint() const { return maStartPoint; } + void setStartPoint(const ::basegfx::B2DPoint& rValue) { maStartPoint = rValue; } - ::basegfx::point::B2DPoint getEndPoint() const { return maEndPoint; } - void setEndPoint(const ::basegfx::point::B2DPoint& rValue) { maEndPoint = rValue; } + ::basegfx::B2DPoint getEndPoint() const { return maEndPoint; } + void setEndPoint(const ::basegfx::B2DPoint& rValue) { maEndPoint = rValue; } - ::basegfx::point::B2DPoint getControlPoint() const { return maControlPoint; } - void setControlPoint(const ::basegfx::point::B2DPoint& rValue) { maControlPoint = rValue; } - }; - } // end of namespace curve + ::basegfx::B2DPoint getControlPoint() const { return maControlPoint; } + void setControlPoint(const ::basegfx::B2DPoint& rValue) { maControlPoint = rValue; } + }; } // end of namespace basegfx #endif // _BGFX_CURVE_B2DQUADRATICBEZIER_HXX diff --git a/basegfx/inc/basegfx/matrix/b2dhommatrix.hxx b/basegfx/inc/basegfx/matrix/b2dhommatrix.hxx index 7ff8dfec5ed3..f574e062f5c1 100644 --- a/basegfx/inc/basegfx/matrix/b2dhommatrix.hxx +++ b/basegfx/inc/basegfx/matrix/b2dhommatrix.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dhommatrix.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: thb $ $Date: 2003-11-12 12:12:40 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:47 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,127 +68,121 @@ namespace basegfx { - namespace tuple - { - // predeclaration - class B2DTuple; - } // end of namespace tuple + // predeclaration + class B2DTuple; + + // forward declaration + class Impl2DHomMatrix; - namespace matrix + class B2DHomMatrix { - // forward declaration - class Impl2DHomMatrix; + private: + Impl2DHomMatrix* mpM; - class B2DHomMatrix - { - private: - Impl2DHomMatrix* mpM; + void implPrepareChange(); - void implPrepareChange(); + public: + B2DHomMatrix(); + B2DHomMatrix(const B2DHomMatrix& rMat); + ~B2DHomMatrix(); - public: - B2DHomMatrix(); - B2DHomMatrix(const B2DHomMatrix& rMat); - ~B2DHomMatrix(); + double get(sal_uInt16 nRow, sal_uInt16 nColumn) const; + void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue); - double get(sal_uInt16 nRow, sal_uInt16 nColumn) const; - void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue); + // Auf Einheitsmatrix zuruecksetzen + sal_Bool isIdentity() const; + void identity(); - // Auf Einheitsmatrix zuruecksetzen - sal_Bool isIdentity() const; - void identity(); + // Invertierung + sal_Bool isInvertible() const; + sal_Bool invert(); - // Invertierung - sal_Bool isInvertible() const; - sal_Bool invert(); + // Normalisierung + sal_Bool isNormalized() const; + void normalize(); - // Normalisierung - sal_Bool isNormalized() const; - void normalize(); + // Determinante + double determinant() const; - // Determinante - double determinant() const; + // Trace + double trace() const; - // Trace - double trace() const; + // Transpose + void transpose(); - // Transpose - void transpose(); + // Rotation + void rotate(double fRadiant); - // Rotation - void rotate(double fRadiant); + // Translation + void translate(double fX, double fY); - // Translation - void translate(double fX, double fY); + // Skalierung + void scale(double fX, double fY); - // Skalierung - void scale(double fX, double fY); + // Shearing-Matrices + void shearX(double fSx); + void shearY(double fSy); - // Shearing-Matrices - void shearX(double fSx); - void shearY(double fSy); + // Addition, Subtraktion + B2DHomMatrix& operator+=(const B2DHomMatrix& rMat); + B2DHomMatrix& operator-=(const B2DHomMatrix& rMat); - // Addition, Subtraktion - B2DHomMatrix& operator+=(const B2DHomMatrix& rMat); - B2DHomMatrix& operator-=(const B2DHomMatrix& rMat); + // Vergleichsoperatoren + sal_Bool operator==(const B2DHomMatrix& rMat) const; + sal_Bool operator!=(const B2DHomMatrix& rMat) const; - // Vergleichsoperatoren - sal_Bool operator==(const B2DHomMatrix& rMat) const; - sal_Bool operator!=(const B2DHomMatrix& rMat) const; + // Multiplikation, Division mit Konstante + B2DHomMatrix& operator*=(double fValue); + B2DHomMatrix& operator/=(double fValue); - // Multiplikation, Division mit Konstante - B2DHomMatrix& operator*=(double fValue); - B2DHomMatrix& operator/=(double fValue); + // Matritzenmultiplikation von links auf die lokale + B2DHomMatrix& operator*=(const B2DHomMatrix& rMat); - // Matritzenmultiplikation von links auf die lokale - B2DHomMatrix& operator*=(const B2DHomMatrix& rMat); + // assignment operator + B2DHomMatrix& operator=(const B2DHomMatrix& rMat); - // assignment operator - B2DHomMatrix& operator=(const B2DHomMatrix& rMat); + // Help routine to decompose given homogen 3x3 matrix to components. A correction of + // the components is done to avoid inaccuracies. + // Zerlegung + sal_Bool decompose(B2DTuple& rScale, B2DTuple& rTranslate, double& rRotate, double& rShearX) const; + }; - // Help routine to decompose given homogen 3x3 matrix to components. A correction of - // the components is done to avoid inaccuracies. - // Zerlegung - sal_Bool decompose(tuple::B2DTuple& rScale, tuple::B2DTuple& rTranslate, double& rRotate, double& rShearX) const; - }; + // Addition, Subtraktion + inline B2DHomMatrix operator+(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) + { + B2DHomMatrix aSum(rMatA); + aSum += rMatB; + return aSum; + } - // Addition, Subtraktion - inline B2DHomMatrix operator+(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) - { - B2DHomMatrix aSum(rMatA); - aSum += rMatB; - return aSum; - } - - inline B2DHomMatrix operator-(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) - { - B2DHomMatrix aDiv(rMatA); - aDiv -= rMatB; - return aDiv; - } + inline B2DHomMatrix operator-(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) + { + B2DHomMatrix aDiv(rMatA); + aDiv -= rMatB; + return aDiv; + } - // Multiplikation, Division mit Konstante - inline B2DHomMatrix operator*(const B2DHomMatrix& rMat, double fValue) - { - B2DHomMatrix aNew(rMat); - aNew *= fValue; - return aNew; - } - - inline B2DHomMatrix operator/(const B2DHomMatrix& rMat, double fValue) - { - B2DHomMatrix aNew(rMat); - aNew *= 1.0 / fValue; - return aNew; - } - - inline B2DHomMatrix operator*(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) - { - B2DHomMatrix aMul(rMatB); - aMul *= rMatA; - return aMul; - } - } // end of namespace matrix + // Multiplikation, Division mit Konstante + inline B2DHomMatrix operator*(const B2DHomMatrix& rMat, double fValue) + { + B2DHomMatrix aNew(rMat); + aNew *= fValue; + return aNew; + } + + inline B2DHomMatrix operator/(const B2DHomMatrix& rMat, double fValue) + { + B2DHomMatrix aNew(rMat); + aNew *= 1.0 / fValue; + return aNew; + } + + inline B2DHomMatrix operator*(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) + { + B2DHomMatrix aMul(rMatB); + aMul *= rMatA; + return aMul; + } } // end of namespace basegfx #endif // _BGFX_MATRIX_B2DHOMMATRIX_HXX diff --git a/basegfx/inc/basegfx/matrix/b3dhommatrix.hxx b/basegfx/inc/basegfx/matrix/b3dhommatrix.hxx index f16b81c930d7..e2751a76c3cd 100644 --- a/basegfx/inc/basegfx/matrix/b3dhommatrix.hxx +++ b/basegfx/inc/basegfx/matrix/b3dhommatrix.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dhommatrix.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: thb $ $Date: 2003-11-12 12:12:40 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,136 +68,130 @@ namespace basegfx { - namespace tuple - { - // predeclaration - class B3DTuple; - } // end of namespace tuple + // predeclaration + class B3DTuple; + + // forward declaration + class Impl3DHomMatrix; - namespace matrix + class B3DHomMatrix { - // forward declaration - class Impl3DHomMatrix; + private: + Impl3DHomMatrix* mpM; - class B3DHomMatrix - { - private: - Impl3DHomMatrix* mpM; + void implPrepareChange(); - void implPrepareChange(); + public: + B3DHomMatrix(); + B3DHomMatrix(const B3DHomMatrix& rMat); + ~B3DHomMatrix(); - public: - B3DHomMatrix(); - B3DHomMatrix(const B3DHomMatrix& rMat); - ~B3DHomMatrix(); + double get(sal_uInt16 nRow, sal_uInt16 nColumn) const; + void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue); - double get(sal_uInt16 nRow, sal_uInt16 nColumn) const; - void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue); + sal_Bool isIdentity() const; + /// Reset to the identity matrix + void identity(); - sal_Bool isIdentity() const; - /// Reset to the identity matrix - void identity(); + sal_Bool isInvertible() const; + /// Invert the matrix (if possible) + sal_Bool invert(); - sal_Bool isInvertible() const; - /// Invert the matrix (if possible) - sal_Bool invert(); + sal_Bool isNormalized() const; + /// Normalize (i.e. force w=1) the matrix + void normalize(); - sal_Bool isNormalized() const; - /// Normalize (i.e. force w=1) the matrix - void normalize(); + /// Calc the matrix determinant + double determinant() const; - /// Calc the matrix determinant - double determinant() const; + /// Calc the matrix trace + double trace() const; - /// Calc the matrix trace - double trace() const; + /// Transpose the matrix + void transpose(); - /// Transpose the matrix - void transpose(); + /// Rotation + void rotate(double fAngleX,double fAngleY,double fAngleZ); - /// Rotation - void rotate(double fAngleX,double fAngleY,double fAngleZ); + /// Translation + void translate(double fX, double fY, double fZ); - /// Translation - void translate(double fX, double fY, double fZ); + /// Scaling + void scale(double fX, double fY, double fZ); - /// Scaling - void scale(double fX, double fY, double fZ); + // Shearing-Matrices + void shearXY(double fSx, double fSy); + void shearYZ(double fSy, double fSz); + void shearXZ(double fSx, double fSz); - // Shearing-Matrices - void shearXY(double fSx, double fSy); - void shearYZ(double fSy, double fSz); - void shearXZ(double fSx, double fSz); + // Projection matrices, used for converting between eye and + // clip coordinates + void frustum(double fLeft = -1.0, double fRight = 1.0, + double fBottom = -1.0, double fTop = 1.0, + double fNear = 0.001, double fFar = 1.0); - // Projection matrices, used for converting between eye and - // clip coordinates - void frustum(double fLeft = -1.0, double fRight = 1.0, - double fBottom = -1.0, double fTop = 1.0, - double fNear = 0.001, double fFar = 1.0); + void ortho(double fLeft = -1.0, double fRight = 1.0, + double fBottom = -1.0, double fTop = 1.0, + double fNear = 0.0, double fFar = 1.0); - void ortho(double fLeft = -1.0, double fRight = 1.0, - double fBottom = -1.0, double fTop = 1.0, - double fNear = 0.0, double fFar = 1.0); + // addition, subtraction + B3DHomMatrix& operator+=(const B3DHomMatrix& rMat); + B3DHomMatrix& operator-=(const B3DHomMatrix& rMat); - // addition, subtraction - B3DHomMatrix& operator+=(const B3DHomMatrix& rMat); - B3DHomMatrix& operator-=(const B3DHomMatrix& rMat); + // comparison + sal_Bool operator==(const B3DHomMatrix& rMat) const; + sal_Bool operator!=(const B3DHomMatrix& rMat) const; - // comparison - sal_Bool operator==(const B3DHomMatrix& rMat) const; - sal_Bool operator!=(const B3DHomMatrix& rMat) const; + // multiplication, division by constant value + B3DHomMatrix& operator*=(double fValue); + B3DHomMatrix& operator/=(double fValue); - // multiplication, division by constant value - B3DHomMatrix& operator*=(double fValue); - B3DHomMatrix& operator/=(double fValue); + // matrix multiplication (from the left) + B3DHomMatrix& operator*=(const B3DHomMatrix& rMat); - // matrix multiplication (from the left) - B3DHomMatrix& operator*=(const B3DHomMatrix& rMat); + // assignment operator + B3DHomMatrix& operator=(const B3DHomMatrix& rMat); - // assignment operator - B3DHomMatrix& operator=(const B3DHomMatrix& rMat); + // decomposition + sal_Bool decompose(B3DTuple& rScale, B3DTuple& rTranslate, B3DTuple& rRotate, B3DTuple& rShear) const; + }; - // decomposition - sal_Bool decompose(tuple::B3DTuple& rScale, tuple::B3DTuple& rTranslate, tuple::B3DTuple& rRotate, tuple::B3DTuple& rShear) const; - }; + // addition, subtraction + inline B3DHomMatrix operator+(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) + { + B3DHomMatrix aSum(rMatA); + aSum += rMatB; + return aSum; + } - // addition, subtraction - inline B3DHomMatrix operator+(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) - { - B3DHomMatrix aSum(rMatA); - aSum += rMatB; - return aSum; - } - - inline B3DHomMatrix operator-(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) - { - B3DHomMatrix aDiv(rMatA); - aDiv -= rMatB; - return aDiv; - } + inline B3DHomMatrix operator-(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) + { + B3DHomMatrix aDiv(rMatA); + aDiv -= rMatB; + return aDiv; + } - // multiplication, division by constant value - inline B3DHomMatrix operator*(const B3DHomMatrix& rMat, double fValue) - { - B3DHomMatrix aNew(rMat); - aNew *= fValue; - return aNew; - } - - inline B3DHomMatrix operator/(const B3DHomMatrix& rMat, double fValue) - { - B3DHomMatrix aNew(rMat); - aNew *= 1.0 / fValue; - return aNew; - } - - inline B3DHomMatrix operator*(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) - { - B3DHomMatrix aMul(rMatB); - aMul *= rMatA; - return aMul; - } - } // end of namespace matrix + // multiplication, division by constant value + inline B3DHomMatrix operator*(const B3DHomMatrix& rMat, double fValue) + { + B3DHomMatrix aNew(rMat); + aNew *= fValue; + return aNew; + } + + inline B3DHomMatrix operator/(const B3DHomMatrix& rMat, double fValue) + { + B3DHomMatrix aNew(rMat); + aNew *= 1.0 / fValue; + return aNew; + } + + inline B3DHomMatrix operator*(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) + { + B3DHomMatrix aMul(rMatB); + aMul *= rMatA; + return aMul; + } } // end of namespace basegfx #endif // _BGFX_MATRIX_B3DHOMMATRIX_HXX diff --git a/basegfx/inc/basegfx/numeric/ftools.hxx b/basegfx/inc/basegfx/numeric/ftools.hxx index 4a8287ff164c..9ae52843cfe0 100644 --- a/basegfx/inc/basegfx/numeric/ftools.hxx +++ b/basegfx/inc/basegfx/numeric/ftools.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ftools.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:39:52 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:50 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -100,80 +100,77 @@ namespace basegfx { - namespace numeric + class fTools { - class fTools + static double mfSmallValue; + + public: + static double getSmallValue() { return mfSmallValue; } + static void setSmallValue(const double& rfNew) { mfSmallValue = rfNew; } + + + static sal_Bool equalZero(const double& rfVal) + { + return (fabs(rfVal) <= getSmallValue()); + } + + static sal_Bool equalZero(const double& rfVal, const double& rfSmallValue) + { + return (fabs(rfVal) <= rfSmallValue); + } + + + static sal_Bool equal(const double& rfValA, const double& rfValB) + { + return (fabs(rfValB - rfValA) <= getSmallValue()); + } + + static sal_Bool less(const double& rfValA, const double& rfValB) + { + return (rfValA < rfValB && !equal(rfValA, rfValB)); + } + + static sal_Bool lessOrEqual(const double& rfValA, const double& rfValB) + { + return (rfValA < rfValB || equal(rfValA, rfValB)); + } + + static sal_Bool more(const double& rfValA, const double& rfValB) + { + return (rfValA > rfValB && !equal(rfValA, rfValB)); + } + + static sal_Bool moreOrEqual(const double& rfValA, const double& rfValB) + { + return (rfValA > rfValB || equal(rfValA, rfValB)); + } + + + static sal_Bool equal(const double& rfValA, const double& rfValB, const double& rfSmallValue) + { + return (fabs(rfValB - rfValA) <= rfSmallValue); + } + + static sal_Bool less(const double& rfValA, const double& rfValB, const double& rfSmallValue) + { + return (rfValA < rfValB && !equal(rfValA, rfValB, rfSmallValue)); + } + + static sal_Bool lessOrEqual(const double& rfValA, const double& rfValB, const double& rfSmallValue) + { + return (rfValA < rfValB || equal(rfValA, rfValB, rfSmallValue)); + } + + static sal_Bool more(const double& rfValA, const double& rfValB, const double& rfSmallValue) + { + return (rfValA > rfValB && !equal(rfValA, rfValB, rfSmallValue)); + } + + static sal_Bool moreOrEqual(const double& rfValA, const double& rfValB, const double& rfSmallValue) { - static double mfSmallValue; - - public: - static double getSmallValue() { return mfSmallValue; } - static void setSmallValue(const double& rfNew) { mfSmallValue = rfNew; } - - - static sal_Bool equalZero(const double& rfVal) - { - return (fabs(rfVal) <= getSmallValue()); - } - - static sal_Bool equalZero(const double& rfVal, const double& rfSmallValue) - { - return (fabs(rfVal) <= rfSmallValue); - } - - - static sal_Bool equal(const double& rfValA, const double& rfValB) - { - return (fabs(rfValB - rfValA) <= getSmallValue()); - } - - static sal_Bool less(const double& rfValA, const double& rfValB) - { - return (rfValA < rfValB && !equal(rfValA, rfValB)); - } - - static sal_Bool lessOrEqual(const double& rfValA, const double& rfValB) - { - return (rfValA < rfValB || equal(rfValA, rfValB)); - } - - static sal_Bool more(const double& rfValA, const double& rfValB) - { - return (rfValA > rfValB && !equal(rfValA, rfValB)); - } - - static sal_Bool moreOrEqual(const double& rfValA, const double& rfValB) - { - return (rfValA > rfValB || equal(rfValA, rfValB)); - } - - - static sal_Bool equal(const double& rfValA, const double& rfValB, const double& rfSmallValue) - { - return (fabs(rfValB - rfValA) <= rfSmallValue); - } - - static sal_Bool less(const double& rfValA, const double& rfValB, const double& rfSmallValue) - { - return (rfValA < rfValB && !equal(rfValA, rfValB, rfSmallValue)); - } - - static sal_Bool lessOrEqual(const double& rfValA, const double& rfValB, const double& rfSmallValue) - { - return (rfValA < rfValB || equal(rfValA, rfValB, rfSmallValue)); - } - - static sal_Bool more(const double& rfValA, const double& rfValB, const double& rfSmallValue) - { - return (rfValA > rfValB && !equal(rfValA, rfValB, rfSmallValue)); - } - - static sal_Bool moreOrEqual(const double& rfValA, const double& rfValB, const double& rfSmallValue) - { - return (rfValA > rfValB || equal(rfValA, rfValB, rfSmallValue)); - } - }; - } // end of namespace numeric + return (rfValA > rfValB || equal(rfValA, rfValB, rfSmallValue)); + } + }; } // end of namespace basegfx #endif _BGFX_NUMERIC_FTOOLS_HXX diff --git a/basegfx/inc/basegfx/point/b2dhompoint.hxx b/basegfx/inc/basegfx/point/b2dhompoint.hxx index 3b145bf4e444..911e61a884fd 100644 --- a/basegfx/inc/basegfx/point/b2dhompoint.hxx +++ b/basegfx/inc/basegfx/point/b2dhompoint.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dhompoint.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-06 16:30:23 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,209 +68,206 @@ namespace basegfx { - namespace point + /** Basic homogen Point class with two double values and one homogen factor + + This class provides access to homogen coordinates in 2D. + For this purpose all the operators which need to do specific + action due to their homogenity are implemented here. + The only caveat are member methods which are declared as const + but do change the content. These are documented for that reason. + The class is designed to provide homogenous coordinates without + direct access to the homogen part (mfW). This is also the reason + for leaving out the [] operators which return references to members. + + @see B2DTuple + */ + class B2DHomPoint { - /** Basic homogen Point class with two double values and one homogen factor - - This class provides access to homogen coordinates in 2D. - For this purpose all the operators which need to do specific - action due to their homogenity are implemented here. - The only caveat are member methods which are declared as const - but do change the content. These are documented for that reason. - The class is designed to provide homogenous coordinates without - direct access to the homogen part (mfW). This is also the reason - for leaving out the [] operators which return references to members. - - @see B2DTuple + protected: + /// This member contains the coordinate part of the point + ::basegfx::B2DTuple maTuple; + + /// This Member holds the homogenous part of the point + double mfW; + + /** Test if this homogen point does have a homogenous part + + @return Returns sal_True if this point has no homogenous part */ - class B2DHomPoint - { - protected: - /// This member contains the coordinate part of the point - ::basegfx::tuple::B2DTuple maTuple; - - /// This Member holds the homogenous part of the point - double mfW; - - /** Test if this homogen point does have a homogenous part - - @return Returns sal_True if this point has no homogenous part - */ - sal_Bool implIsHomogenized() const; - - /** Remove homogenous part of this Point - - This method does necessary calculations to remove - the evtl. homogenous part of this Point. This may - change all members. - */ - void implHomogenize(); + sal_Bool implIsHomogenized() const; - /** Test and on demand remove homogenous part - - This method tests if this Point does have a homogenous part - and then evtl. takes actions to remove that part. - - @attention Even when this method is const it may change all - members of this instance. This is due to the fact that changing - the homogenous part of a homogenous point does from a mathematical - point of view not change the point at all. - */ - void implTestAndHomogenize() const; + /** Remove homogenous part of this Point + + This method does necessary calculations to remove + the evtl. homogenous part of this Point. This may + change all members. + */ + void implHomogenize(); + + /** Test and on demand remove homogenous part + + This method tests if this Point does have a homogenous part + and then evtl. takes actions to remove that part. + + @attention Even when this method is const it may change all + members of this instance. This is due to the fact that changing + the homogenous part of a homogenous point does from a mathematical + point of view not change the point at all. + */ + void implTestAndHomogenize() const; - public: - /** Create a homogen point + public: + /** Create a homogen point - @param fVal - This parameter is used to initialize the coordinate - part of the Point. The homogenous part is initialized to 1.0. - */ - B2DHomPoint(double fVal = 0.0) - : maTuple(fVal), - mfW(1.0) - {} + @param fVal + This parameter is used to initialize the coordinate + part of the Point. The homogenous part is initialized to 1.0. + */ + B2DHomPoint(double fVal = 0.0) + : maTuple(fVal), + mfW(1.0) + {} - /** Create a homogen point + /** Create a homogen point - @param fX - This parameter is used to initialize the X-coordinate - of the Point. The homogenous part is initialized to 1.0. + @param fX + This parameter is used to initialize the X-coordinate + of the Point. The homogenous part is initialized to 1.0. - @param fY - This parameter is used to initialize the Y-coordinate - of the Point. The homogenous part is initialized to 1.0. - */ - B2DHomPoint(double fX, double fY) - : maTuple(fX, fY), - mfW(1.0) - {} + @param fY + This parameter is used to initialize the Y-coordinate + of the Point. The homogenous part is initialized to 1.0. + */ + B2DHomPoint(double fX, double fY) + : maTuple(fX, fY), + mfW(1.0) + {} - /** Create a copy of a 2D Point + /** Create a copy of a 2D Point - @param rVec - The 2D point which will be copied. The homogenous part - is initialized to 1.0. - */ - B2DHomPoint(const B2DPoint& rVec) - : maTuple(rVec), - mfW(1.0) - {} + @param rVec + The 2D point which will be copied. The homogenous part + is initialized to 1.0. + */ + B2DHomPoint(const B2DPoint& rVec) + : maTuple(rVec), + mfW(1.0) + {} - /** Create a copy of a homogen point + /** Create a copy of a homogen point - @param rVec - The homogen point which will be copied. The homogenous part - is copied, too. - */ - B2DHomPoint(const B2DHomPoint& rVec) - : maTuple(rVec.maTuple.getX(), rVec.maTuple.getY()), - mfW(rVec.mfW) - {} + @param rVec + The homogen point which will be copied. The homogenous part + is copied, too. + */ + B2DHomPoint(const B2DHomPoint& rVec) + : maTuple(rVec.maTuple.getX(), rVec.maTuple.getY()), + mfW(rVec.mfW) + {} - ~B2DHomPoint() - {} + ~B2DHomPoint() + {} - /** Get a 2D point from this homogenous point + /** Get a 2D point from this homogenous point - This method normalizes this homogen point if necessary and - returns the corresponding 2D point for this homogen point. + This method normalizes this homogen point if necessary and + returns the corresponding 2D point for this homogen point. - @attention Even when this method is const it may change all - members of this instance. - */ - B2DPoint getB2DPoint() const; + @attention Even when this method is const it may change all + members of this instance. + */ + B2DPoint getB2DPoint() const; - /** Get X-coordinate + /** Get X-coordinate - This method normalizes this homogen point if necessary and - returns the corresponding X-coordinate for this homogen point. + This method normalizes this homogen point if necessary and + returns the corresponding X-coordinate for this homogen point. - @attention Even when this method is const it may change all - members of this instance. - */ - double getX() const; + @attention Even when this method is const it may change all + members of this instance. + */ + double getX() const; - /** Get Y-coordinate + /** Get Y-coordinate - This method normalizes this homogen point if necessary and - returns the corresponding Y-coordinate for this homogen point. + This method normalizes this homogen point if necessary and + returns the corresponding Y-coordinate for this homogen point. - @attention Even when this method is const it may change all - members of this instance. - */ - double getY() const; + @attention Even when this method is const it may change all + members of this instance. + */ + double getY() const; - /** Set X-coordinate of the homogen point. + /** Set X-coordinate of the homogen point. - This method sets the X-coordinate of the homogen point. If - the point does have a homogenous part this is taken into account. + This method sets the X-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. - @param fX - The to-be-set X-coordinate without homogenous part. - */ - void setX(double fX); + @param fX + The to-be-set X-coordinate without homogenous part. + */ + void setX(double fX); - /** Set Y-coordinate of the homogen point. + /** Set Y-coordinate of the homogen point. - This method sets the Y-coordinate of the homogen point. If - the point does have a homogenous part this is taken into account. + This method sets the Y-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. - @param fY - The to-be-set Y-coordinate without homogenous part. - */ - void setY(double fY); + @param fY + The to-be-set Y-coordinate without homogenous part. + */ + void setY(double fY); - // operators - ////////////////////////////////////////////////////////////////////// + // operators + ////////////////////////////////////////////////////////////////////// - B2DHomPoint& operator+=( const B2DHomPoint& rPnt ); + B2DHomPoint& operator+=( const B2DHomPoint& rPnt ); - B2DHomPoint& operator-=( const B2DHomPoint& rPnt ); + B2DHomPoint& operator-=( const B2DHomPoint& rPnt ); - B2DHomPoint& operator*=(double t); + B2DHomPoint& operator*=(double t); - B2DHomPoint& operator*=( const matrix::B2DHomMatrix& rMat ); + B2DHomPoint& operator*=( const B2DHomMatrix& rMat ); - B2DHomPoint& operator/=(double t); + B2DHomPoint& operator/=(double t); - B2DHomPoint& operator-(void); + B2DHomPoint& operator-(void); - sal_Bool operator==( const B2DHomPoint& rPnt ) const; + sal_Bool operator==( const B2DHomPoint& rPnt ) const; - sal_Bool operator!=( const B2DHomPoint& rPnt ) const; + sal_Bool operator!=( const B2DHomPoint& rPnt ) const; - B2DHomPoint& operator=( const B2DHomPoint& rPnt ); - }; + B2DHomPoint& operator=( const B2DHomPoint& rPnt ); + }; - // external operators - ////////////////////////////////////////////////////////////////////////// + // external operators + ////////////////////////////////////////////////////////////////////////// - B2DHomPoint min(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); + B2DHomPoint min(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); - B2DHomPoint max(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); + B2DHomPoint max(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); - B2DHomPoint abs(const B2DHomPoint& rVec); + B2DHomPoint abs(const B2DHomPoint& rVec); - B2DHomPoint interpolate(B2DHomPoint& rOld1, B2DHomPoint& rOld2, double t); + B2DHomPoint interpolate(B2DHomPoint& rOld1, B2DHomPoint& rOld2, double t); - B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2); + B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2); - B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2, B2DHomPoint& rOld3); + B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2, B2DHomPoint& rOld3); - B2DHomPoint operator+(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); + B2DHomPoint operator+(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); - B2DHomPoint operator-(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); + B2DHomPoint operator-(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); - B2DHomPoint operator*(const B2DHomPoint& rVec, double t); + B2DHomPoint operator*(const B2DHomPoint& rVec, double t); - B2DHomPoint operator*(double t, const B2DHomPoint& rVec); + B2DHomPoint operator*(double t, const B2DHomPoint& rVec); - B2DHomPoint operator*( const matrix::B2DHomMatrix& rMat, const B2DHomPoint& rPoint ); + B2DHomPoint operator*( const B2DHomMatrix& rMat, const B2DHomPoint& rPoint ); - B2DHomPoint operator/(const B2DHomPoint& rVec, double t); + B2DHomPoint operator/(const B2DHomPoint& rVec, double t); - B2DHomPoint operator/(double t, const B2DHomPoint& rVec); - } // end of namespace point + B2DHomPoint operator/(double t, const B2DHomPoint& rVec); } // end of namespace basegfx #endif // _BGFX_POINT_B2DHOMPOINT_HXX diff --git a/basegfx/inc/basegfx/point/b2dpoint.hxx b/basegfx/inc/basegfx/point/b2dpoint.hxx index eb5f042f69e8..ed07229f4e59 100644 --- a/basegfx/inc/basegfx/point/b2dpoint.hxx +++ b/basegfx/inc/basegfx/point/b2dpoint.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpoint.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:39:54 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,104 +68,98 @@ namespace basegfx { - namespace matrix - { - // predeclaration - class B2DHomMatrix; - } // end of namespace matrix; + // predeclaration + class B2DHomMatrix; + + /** Base Point class with two double values + + This class derives all operators and common handling for + a 2D data class from B2DTuple. All necessary extensions + which are special for points will be added here. - namespace point + @see B2DTuple + */ + class B2DPoint : public ::basegfx::B2DTuple { - /** Base Point class with two double values + public: + /** Create a 2D Point + + @param fVal + This parameter is used to initialize the coordinate + part of the 2D Point. + */ + B2DPoint(double fVal = 0.0) + : B2DTuple(fVal) + {} + + /** Create a 2D Point + + @param fX + This parameter is used to initialize the X-coordinate + of the 2D Point. + + @param fY + This parameter is used to initialize the Y-coordinate + of the 2D Point. + */ + B2DPoint(double fX, double fY) + : B2DTuple(fX, fY) + {} + + /** Create a copy of a 2D Point + + @param rPoint + The 2D Point which will be copied. + */ + B2DPoint(const B2DPoint& rPoint) + : B2DTuple(rPoint) + {} - This class derives all operators and common handling for - a 2D data class from B2DTuple. All necessary extensions - which are special for points will be added here. + /** constructor with tuple to allow copy-constructing + from B2DTuple-based classes + */ + B2DPoint(const ::basegfx::B2DTuple& rTuple) + : B2DTuple(rTuple) + {} + + ~B2DPoint() + {} + + /** *=operator to allow usage from B2DPoint, too + */ + B2DPoint& operator*=( const B2DPoint& rPnt ) + { + mfX *= rPnt.mfX; + mfY *= rPnt.mfY; + return *this; + } + + /** *=operator to allow usage from B2DPoint, too + */ + B2DPoint& operator*=(double t) + { + mfX *= t; + mfY *= t; + return *this; + } + + /** assignment operator to allow assigning the results + of B2DTuple calculations + */ + B2DPoint& operator=( const ::basegfx::B2DTuple& rPoint ); + + /** Transform point by given transformation matrix. - @see B2DTuple + The translational components of the matrix are, in + contrast to B2DVector, applied. */ - class B2DPoint : public ::basegfx::tuple::B2DTuple + B2DPoint& operator*=( const ::basegfx::B2DHomMatrix& rMat ); + + static const B2DPoint& getEmptyPoint() { - public: - /** Create a 2D Point - - @param fVal - This parameter is used to initialize the coordinate - part of the 2D Point. - */ - B2DPoint(double fVal = 0.0) - : B2DTuple(fVal) - {} - - /** Create a 2D Point - - @param fX - This parameter is used to initialize the X-coordinate - of the 2D Point. - - @param fY - This parameter is used to initialize the Y-coordinate - of the 2D Point. - */ - B2DPoint(double fX, double fY) - : B2DTuple(fX, fY) - {} - - /** Create a copy of a 2D Point - - @param rPoint - The 2D Point which will be copied. - */ - B2DPoint(const B2DPoint& rPoint) - : B2DTuple(rPoint) - {} - - /** constructor with tuple to allow copy-constructing - from B2DTuple-based classes - */ - B2DPoint(const ::basegfx::tuple::B2DTuple& rTuple) - : B2DTuple(rTuple) - {} - - ~B2DPoint() - {} - - /** *=operator to allow usage from B2DPoint, too - */ - B2DPoint& operator*=( const B2DPoint& rPnt ) - { - mfX *= rPnt.mfX; - mfY *= rPnt.mfY; - return *this; - } - - /** *=operator to allow usage from B2DPoint, too - */ - B2DPoint& operator*=(double t) - { - mfX *= t; - mfY *= t; - return *this; - } - - /** assignment operator to allow assigning the results - of B2DTuple calculations - */ - B2DPoint& operator=( const ::basegfx::tuple::B2DTuple& rPoint ); - - /** Transform point by given transformation matrix. - - The translational components of the matrix are, in - contrast to B2DVector, applied. - */ - B2DPoint& operator*=( const ::basegfx::matrix::B2DHomMatrix& rMat ); - - static const B2DPoint& getEmptyPoint() - { - return (const B2DPoint&) ::basegfx::tuple::B2DTuple::getEmptyTuple(); - } - }; - } // end of namespace point + return (const B2DPoint&) ::basegfx::B2DTuple::getEmptyTuple(); + } + }; } // end of namespace basegfx #endif // _BGFX_POINT_B2DPOINT_HXX diff --git a/basegfx/inc/basegfx/point/b3dhompoint.hxx b/basegfx/inc/basegfx/point/b3dhompoint.hxx index 7cd82c364a7f..08079b90a983 100644 --- a/basegfx/inc/basegfx/point/b3dhompoint.hxx +++ b/basegfx/inc/basegfx/point/b3dhompoint.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dhompoint.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-10 11:45:47 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,379 +68,376 @@ namespace basegfx { - namespace point + /** Basic homogen Point class with three double values and one homogen factor + + This class provides access to homogen coordinates in 3D. + For this purpose all the operators which need to do specific + action due to their homogenity are implemented here. + The only caveat are member methods which are declared as const + but do change the content. These are documented for that reason. + The class is designed to provide homogenous coordinates without + direct access to the homogen part (mfW). This is also the reason + for leaving out the [] operators which return references to members. + + @see B3DTuple + */ + class B3DHomPoint { - /** Basic homogen Point class with three double values and one homogen factor - - This class provides access to homogen coordinates in 3D. - For this purpose all the operators which need to do specific - action due to their homogenity are implemented here. - The only caveat are member methods which are declared as const - but do change the content. These are documented for that reason. - The class is designed to provide homogenous coordinates without - direct access to the homogen part (mfW). This is also the reason - for leaving out the [] operators which return references to members. - - @see B3DTuple - */ - class B3DHomPoint - { - protected: - /// This member contains the coordinate part of the point - ::basegfx::tuple::B3DTuple maTuple; + protected: + /// This member contains the coordinate part of the point + ::basegfx::B3DTuple maTuple; - /// This Member holds the homogenous part of the point - double mfW; + /// This Member holds the homogenous part of the point + double mfW; - /** Test if this homogen point does have a homogenous part + /** Test if this homogen point does have a homogenous part - @return Returns sal_True if this point has no homogenous part - */ - sal_Bool implIsHomogenized() const - { - const double fOne(1.0); - return ::basegfx::numeric::fTools::equal(mfW, fOne); - } + @return Returns sal_True if this point has no homogenous part + */ + sal_Bool implIsHomogenized() const + { + const double fOne(1.0); + return ::basegfx::fTools::equal(mfW, fOne); + } - /** Remove homogenous part of this Point + /** Remove homogenous part of this Point - This method does necessary calculations to remove - the evtl. homogenous part of this Point. This may - change all members. - */ - void implHomogenize(); + This method does necessary calculations to remove + the evtl. homogenous part of this Point. This may + change all members. + */ + void implHomogenize(); - /** Test and on demand remove homogenous part + /** Test and on demand remove homogenous part - This method tests if this Point does have a homogenous part - and then evtl. takes actions to remove that part. + This method tests if this Point does have a homogenous part + and then evtl. takes actions to remove that part. - @attention Even when this method is const it may change all - members of this instance. This is due to the fact that changing - the homogenous part of a homogenous point does from a mathematical - point of view not change the point at all. - */ - void implTestAndHomogenize() const - { - if(!implIsHomogenized()) - ((B3DHomPoint*)this)->implHomogenize(); - } + @attention Even when this method is const it may change all + members of this instance. This is due to the fact that changing + the homogenous part of a homogenous point does from a mathematical + point of view not change the point at all. + */ + void implTestAndHomogenize() const + { + if(!implIsHomogenized()) + ((B3DHomPoint*)this)->implHomogenize(); + } - public: - /** Create a homogen point - - @param fVal - This parameter is used to initialize the coordinate - part of the Point. The homogenous part is initialized to 1.0. - */ - B3DHomPoint(double fVal = 0.0) - : maTuple(fVal), - mfW(1.0) - {} - - /** Create a homogen point - - @param fX - This parameter is used to initialize the X-coordinate - of the Point. The homogenous part is initialized to 1.0. - - @param fY - This parameter is used to initialize the Y-coordinate - of the Point. The homogenous part is initialized to 1.0. - - @param fZ - This parameter is used to initialize the Z-coordinate - of the Point. The homogenous part is initialized to 1.0. - */ - B3DHomPoint(double fX, double fY, double fZ) - : maTuple(fX, fY, fZ), - mfW(1.0) - {} - - /** Create a copy of a 3D Point - - @param rVec - The 3D point which will be copied. The homogenous part - is initialized to 1.0. - */ - B3DHomPoint(const B3DPoint& rVec) - : maTuple(rVec), - mfW(1.0) - {} - - /** Create a copy of a homogen point - - @param rVec - The homogen point which will be copied. The homogenous part - is copied, too. - */ - B3DHomPoint(const B3DHomPoint& rVec) - : maTuple(rVec.maTuple.getX(), rVec.maTuple.getY(), rVec.maTuple.getZ()), - mfW(rVec.mfW) - {} - - ~B3DHomPoint() - {} - - /** get a 3D point from this homogenous point - - This method normalizes this homogen point if necessary and - returns the corresponding 3D point for this homogen point. - - @attention Even when this method is const it may change all - members of this instance. - */ - B3DPoint getB3DPoint() const - { - implTestAndHomogenize(); - return B3DPoint(maTuple.getX(), maTuple.getY(), maTuple.getZ()); - } + public: + /** Create a homogen point - /** get X-coordinate + @param fVal + This parameter is used to initialize the coordinate + part of the Point. The homogenous part is initialized to 1.0. + */ + B3DHomPoint(double fVal = 0.0) + : maTuple(fVal), + mfW(1.0) + {} - This method normalizes this homogen point if necessary and - returns the corresponding X-coordinate for this homogen point. + /** Create a homogen point - @attention Even when this method is const it may change all - members of this instance. - */ - double getX() const - { - implTestAndHomogenize(); - return maTuple.getX(); - } + @param fX + This parameter is used to initialize the X-coordinate + of the Point. The homogenous part is initialized to 1.0. - /** get Y-coordinate + @param fY + This parameter is used to initialize the Y-coordinate + of the Point. The homogenous part is initialized to 1.0. - This method normalizes this homogen point if necessary and - returns the corresponding Y-coordinate for this homogen point. + @param fZ + This parameter is used to initialize the Z-coordinate + of the Point. The homogenous part is initialized to 1.0. + */ + B3DHomPoint(double fX, double fY, double fZ) + : maTuple(fX, fY, fZ), + mfW(1.0) + {} - @attention Even when this method is const it may change all - members of this instance. - */ - double getY() const - { - implTestAndHomogenize(); - return maTuple.getY(); - } + /** Create a copy of a 3D Point - /** get Z-coordinate + @param rVec + The 3D point which will be copied. The homogenous part + is initialized to 1.0. + */ + B3DHomPoint(const B3DPoint& rVec) + : maTuple(rVec), + mfW(1.0) + {} - This method normalizes this homogen point if necessary and - returns the corresponding Z-coordinate for this homogen point. + /** Create a copy of a homogen point - @attention Even when this method is const it may change all - members of this instance. - */ - double getZ() const - { - implTestAndHomogenize(); - return maTuple.getY(); - } + @param rVec + The homogen point which will be copied. The homogenous part + is copied, too. + */ + B3DHomPoint(const B3DHomPoint& rVec) + : maTuple(rVec.maTuple.getX(), rVec.maTuple.getY(), rVec.maTuple.getZ()), + mfW(rVec.mfW) + {} - /** Set X-coordinate of the homogen point. + ~B3DHomPoint() + {} - This method sets the X-coordinate of the homogen point. If - the point does have a homogenous part this is taken into account. + /** get a 3D point from this homogenous point - @param fX - The to-be-set X-coordinate without homogenous part. - */ - void setX(double fX) - { - maTuple.setX(implIsHomogenized() ? fX : fX * mfW ); - } + This method normalizes this homogen point if necessary and + returns the corresponding 3D point for this homogen point. - /** Set Y-coordinate of the homogen point. + @attention Even when this method is const it may change all + members of this instance. + */ + B3DPoint getB3DPoint() const + { + implTestAndHomogenize(); + return B3DPoint(maTuple.getX(), maTuple.getY(), maTuple.getZ()); + } - This method sets the Y-coordinate of the homogen point. If - the point does have a homogenous part this is taken into account. + /** get X-coordinate - @param fY - The to-be-set Y-coordinate without homogenous part. - */ - void setY(double fY) - { - maTuple.setY(implIsHomogenized() ? fY : fY * mfW ); - } + This method normalizes this homogen point if necessary and + returns the corresponding X-coordinate for this homogen point. - /** Set Z-coordinate of the homogen point. + @attention Even when this method is const it may change all + members of this instance. + */ + double getX() const + { + implTestAndHomogenize(); + return maTuple.getX(); + } - This method sets the Z-coordinate of the homogen point. If - the point does have a homogenous part this is taken into account. + /** get Y-coordinate - @param fZ - The to-be-set Z-coordinate without homogenous part. - */ - void setZ(double fZ) - { - maTuple.setZ(implIsHomogenized() ? fZ : fZ * mfW ); - } + This method normalizes this homogen point if necessary and + returns the corresponding Y-coordinate for this homogen point. - // operators - ////////////////////////////////////////////////////////////////////// + @attention Even when this method is const it may change all + members of this instance. + */ + double getY() const + { + implTestAndHomogenize(); + return maTuple.getY(); + } - B3DHomPoint& operator+=( const B3DHomPoint& rPnt ) - { - maTuple.setX(getX() * rPnt.mfW + rPnt.getX() * mfW); - maTuple.setY(getY() * rPnt.mfW + rPnt.getY() * mfW); - maTuple.setZ(getZ() * rPnt.mfW + rPnt.getZ() * mfW); - mfW = mfW * rPnt.mfW; + /** get Z-coordinate - return *this; - } + This method normalizes this homogen point if necessary and + returns the corresponding Z-coordinate for this homogen point. - B3DHomPoint& operator-=( const B3DHomPoint& rPnt ) - { - maTuple.setX(getX() * rPnt.mfW - rPnt.getX() * mfW); - maTuple.setY(getY() * rPnt.mfW - rPnt.getY() * mfW); - maTuple.setZ(getZ() * rPnt.mfW - rPnt.getZ() * mfW); - mfW = mfW * rPnt.mfW; + @attention Even when this method is const it may change all + members of this instance. + */ + double getZ() const + { + implTestAndHomogenize(); + return maTuple.getY(); + } - return *this; - } + /** Set X-coordinate of the homogen point. - B3DHomPoint& operator*=(double t) - { - if(!::basegfx::numeric::fTools::equalZero(t)) - { - mfW /= t; - } + This method sets the X-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. - return *this; - } - - B3DHomPoint& operator/=(double t) - { - mfW *= t; - return *this; - } + @param fX + The to-be-set X-coordinate without homogenous part. + */ + void setX(double fX) + { + maTuple.setX(implIsHomogenized() ? fX : fX * mfW ); + } - B3DHomPoint& operator-(void) - { - mfW = -mfW; - return *this; - } + /** Set Y-coordinate of the homogen point. - sal_Bool operator==( const B3DHomPoint& rPnt ) const - { - implTestAndHomogenize(); - return (maTuple == rPnt.maTuple); - } + This method sets the Y-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. - sal_Bool operator!=( const B3DHomPoint& rPnt ) const - { - implTestAndHomogenize(); - return (maTuple != rPnt.maTuple); - } + @param fY + The to-be-set Y-coordinate without homogenous part. + */ + void setY(double fY) + { + maTuple.setY(implIsHomogenized() ? fY : fY * mfW ); + } - B3DHomPoint& operator=( const B3DHomPoint& rPnt ) - { - maTuple = rPnt.maTuple; - mfW = rPnt.mfW; - return *this; - } - }; + /** Set Z-coordinate of the homogen point. - // external operators - ////////////////////////////////////////////////////////////////////////// + This method sets the Z-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. - inline B3DHomPoint min(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + @param fZ + The to-be-set Z-coordinate without homogenous part. + */ + void setZ(double fZ) { - B3DHomPoint aMin( - (rVecB.getX() < rVecA.getX()) ? rVecB.getX() : rVecA.getX(), - (rVecB.getY() < rVecA.getY()) ? rVecB.getY() : rVecA.getY(), - (rVecB.getZ() < rVecA.getZ()) ? rVecB.getZ() : rVecA.getZ()); - return aMin; + maTuple.setZ(implIsHomogenized() ? fZ : fZ * mfW ); } - inline B3DHomPoint max(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) - { - B3DHomPoint aMax( - (rVecB.getX() > rVecA.getX()) ? rVecB.getX() : rVecA.getX(), - (rVecB.getY() > rVecA.getY()) ? rVecB.getY() : rVecA.getY(), - (rVecB.getZ() > rVecA.getZ()) ? rVecB.getZ() : rVecA.getZ()); - return aMax; - } + // operators + ////////////////////////////////////////////////////////////////////// - inline B3DHomPoint abs(const B3DHomPoint& rVec) + B3DHomPoint& operator+=( const B3DHomPoint& rPnt ) { - B3DHomPoint aAbs( - (0.0 > rVec.getX()) ? -rVec.getX() : rVec.getX(), - (0.0 > rVec.getY()) ? -rVec.getY() : rVec.getY(), - (0.0 > rVec.getZ()) ? -rVec.getZ() : rVec.getZ()); - return aAbs; - } + maTuple.setX(getX() * rPnt.mfW + rPnt.getX() * mfW); + maTuple.setY(getY() * rPnt.mfW + rPnt.getY() * mfW); + maTuple.setZ(getZ() * rPnt.mfW + rPnt.getZ() * mfW); + mfW = mfW * rPnt.mfW; - inline B3DHomPoint interpolate(B3DHomPoint& rOld1, B3DHomPoint& rOld2, double t) - { - B3DHomPoint aInt( - ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), - ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(), - ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ()); - return aInt; + return *this; } - inline B3DHomPoint average(B3DHomPoint& rOld1, B3DHomPoint& rOld2) + B3DHomPoint& operator-=( const B3DHomPoint& rPnt ) { - B3DHomPoint aAvg( - (rOld1.getX() + rOld2.getX()) * 0.5, - (rOld1.getY() + rOld2.getY()) * 0.5, - (rOld1.getZ() + rOld2.getZ()) * 0.5); - return aAvg; - } + maTuple.setX(getX() * rPnt.mfW - rPnt.getX() * mfW); + maTuple.setY(getY() * rPnt.mfW - rPnt.getY() * mfW); + maTuple.setZ(getZ() * rPnt.mfW - rPnt.getZ() * mfW); + mfW = mfW * rPnt.mfW; - inline B3DHomPoint average(B3DHomPoint& rOld1, B3DHomPoint& rOld2, B3DHomPoint& rOld3) - { - B3DHomPoint aAvg( - (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), - (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0), - (rOld1.getZ() + rOld2.getZ() + rOld3.getZ()) * (1.0 / 3.0)); - return aAvg; + return *this; } - inline B3DHomPoint operator+(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + B3DHomPoint& operator*=(double t) { - B3DHomPoint aSum(rVecA); - aSum += rVecB; - return aSum; + if(!::basegfx::fTools::equalZero(t)) + { + mfW /= t; + } + + return *this; } - inline B3DHomPoint operator-(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + B3DHomPoint& operator/=(double t) { - B3DHomPoint aSub(rVecA); - aSub -= rVecB; - return aSub; + mfW *= t; + return *this; } - inline B3DHomPoint operator*(const B3DHomPoint& rVec, double t) + B3DHomPoint& operator-(void) { - B3DHomPoint aNew(rVec); - aNew *= t; - return aNew; + mfW = -mfW; + return *this; } - inline B3DHomPoint operator*(double t, const B3DHomPoint& rVec) + sal_Bool operator==( const B3DHomPoint& rPnt ) const { - B3DHomPoint aNew(rVec); - aNew *= t; - return aNew; + implTestAndHomogenize(); + return (maTuple == rPnt.maTuple); } - inline B3DHomPoint operator/(const B3DHomPoint& rVec, double t) + sal_Bool operator!=( const B3DHomPoint& rPnt ) const { - B3DHomPoint aNew(rVec); - aNew /= t; - return aNew; + implTestAndHomogenize(); + return (maTuple != rPnt.maTuple); } - inline B3DHomPoint operator/(double t, const B3DHomPoint& rVec) + B3DHomPoint& operator=( const B3DHomPoint& rPnt ) { - B3DHomPoint aNew(rVec); - aNew /= t; - return aNew; + maTuple = rPnt.maTuple; + mfW = rPnt.mfW; + return *this; } - } // end of namespace point + }; + + // external operators + ////////////////////////////////////////////////////////////////////////// + + inline B3DHomPoint min(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + { + B3DHomPoint aMin( + (rVecB.getX() < rVecA.getX()) ? rVecB.getX() : rVecA.getX(), + (rVecB.getY() < rVecA.getY()) ? rVecB.getY() : rVecA.getY(), + (rVecB.getZ() < rVecA.getZ()) ? rVecB.getZ() : rVecA.getZ()); + return aMin; + } + + inline B3DHomPoint max(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + { + B3DHomPoint aMax( + (rVecB.getX() > rVecA.getX()) ? rVecB.getX() : rVecA.getX(), + (rVecB.getY() > rVecA.getY()) ? rVecB.getY() : rVecA.getY(), + (rVecB.getZ() > rVecA.getZ()) ? rVecB.getZ() : rVecA.getZ()); + return aMax; + } + + inline B3DHomPoint abs(const B3DHomPoint& rVec) + { + B3DHomPoint aAbs( + (0.0 > rVec.getX()) ? -rVec.getX() : rVec.getX(), + (0.0 > rVec.getY()) ? -rVec.getY() : rVec.getY(), + (0.0 > rVec.getZ()) ? -rVec.getZ() : rVec.getZ()); + return aAbs; + } + + inline B3DHomPoint interpolate(B3DHomPoint& rOld1, B3DHomPoint& rOld2, double t) + { + B3DHomPoint aInt( + ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), + ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(), + ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ()); + return aInt; + } + + inline B3DHomPoint average(B3DHomPoint& rOld1, B3DHomPoint& rOld2) + { + B3DHomPoint aAvg( + (rOld1.getX() + rOld2.getX()) * 0.5, + (rOld1.getY() + rOld2.getY()) * 0.5, + (rOld1.getZ() + rOld2.getZ()) * 0.5); + return aAvg; + } + + inline B3DHomPoint average(B3DHomPoint& rOld1, B3DHomPoint& rOld2, B3DHomPoint& rOld3) + { + B3DHomPoint aAvg( + (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), + (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0), + (rOld1.getZ() + rOld2.getZ() + rOld3.getZ()) * (1.0 / 3.0)); + return aAvg; + } + + inline B3DHomPoint operator+(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + { + B3DHomPoint aSum(rVecA); + aSum += rVecB; + return aSum; + } + + inline B3DHomPoint operator-(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + { + B3DHomPoint aSub(rVecA); + aSub -= rVecB; + return aSub; + } + + inline B3DHomPoint operator*(const B3DHomPoint& rVec, double t) + { + B3DHomPoint aNew(rVec); + aNew *= t; + return aNew; + } + + inline B3DHomPoint operator*(double t, const B3DHomPoint& rVec) + { + B3DHomPoint aNew(rVec); + aNew *= t; + return aNew; + } + + inline B3DHomPoint operator/(const B3DHomPoint& rVec, double t) + { + B3DHomPoint aNew(rVec); + aNew /= t; + return aNew; + } + + inline B3DHomPoint operator/(double t, const B3DHomPoint& rVec) + { + B3DHomPoint aNew(rVec); + aNew /= t; + return aNew; + } } // end of namespace basegfx #endif // _BGFX_POINT_B3DHOMPOINT_HXX diff --git a/basegfx/inc/basegfx/point/b3dpoint.hxx b/basegfx/inc/basegfx/point/b3dpoint.hxx index 7f444b850234..06a4b7e346e1 100644 --- a/basegfx/inc/basegfx/point/b3dpoint.hxx +++ b/basegfx/inc/basegfx/point/b3dpoint.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpoint.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:39:54 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,116 +68,110 @@ namespace basegfx { - namespace matrix - { - // predeclaration - class B3DHomMatrix; - } // end of namespace matrix; + // predeclaration + class B3DHomMatrix; + + /** Base Point class with three double values - namespace point + This class derives all operators and common handling for + a 3D data class from B3DTuple. All necessary extensions + which are special for points will be added here. + + @see B3DTuple + */ + class B3DPoint : public ::basegfx::B3DTuple { - /** Base Point class with three double values + public: + /** Create a 3D Point + + @param fVal + This parameter is used to initialize the coordinate + part of the 3D Point. + */ + B3DPoint(double fVal = 0.0) + : B3DTuple(fVal) + {} + + /** Create a 3D Point + + @param fX + This parameter is used to initialize the X-coordinate + of the 3D Point. - This class derives all operators and common handling for - a 3D data class from B3DTuple. All necessary extensions - which are special for points will be added here. + @param fY + This parameter is used to initialize the Y-coordinate + of the 3D Point. - @see B3DTuple + @param fZ + This parameter is used to initialize the Z-coordinate + of the 3D Point. */ - class B3DPoint : public ::basegfx::tuple::B3DTuple + B3DPoint(double fX, double fY, double fZ) + : B3DTuple(fX, fY, fZ) + {} + + /** Create a copy of a 3D Point + + @param rVec + The 3D Point which will be copied. + */ + B3DPoint(const B3DPoint& rVec) + : B3DTuple(rVec) + {} + + /** constructor with tuple to allow copy-constructing + from B3DTuple-based classes + */ + B3DPoint(const ::basegfx::B3DTuple& rTuple) + : B3DTuple(rTuple) + {} + + ~B3DPoint() + {} + + /** *=operator to allow usage from B3DPoint, too + */ + B3DPoint& operator*=( const B3DPoint& rPnt ) + { + mfX *= rPnt.mfX; + mfY *= rPnt.mfY; + mfZ *= rPnt.mfZ; + return *this; + } + + /** *=operator to allow usage from B3DPoint, too + */ + B3DPoint& operator*=(double t) + { + mfX *= t; + mfY *= t; + mfZ *= t; + return *this; + } + + /** assignment operator to allow assigning the results + of B3DTuple calculations + */ + B3DPoint& operator=( const ::basegfx::B3DTuple& rVec ) + { + mfX = rVec.getX(); + mfY = rVec.getY(); + mfZ = rVec.getZ(); + return *this; + } + + /** Transform point by given transformation matrix. + + The translational components of the matrix are, in + contrast to B3DVector, applied. + */ + B3DPoint& operator*=( const ::basegfx::B3DHomMatrix& rMat ); + + static const B3DPoint& getEmptyPoint() { - public: - /** Create a 3D Point - - @param fVal - This parameter is used to initialize the coordinate - part of the 3D Point. - */ - B3DPoint(double fVal = 0.0) - : B3DTuple(fVal) - {} - - /** Create a 3D Point - - @param fX - This parameter is used to initialize the X-coordinate - of the 3D Point. - - @param fY - This parameter is used to initialize the Y-coordinate - of the 3D Point. - - @param fZ - This parameter is used to initialize the Z-coordinate - of the 3D Point. - */ - B3DPoint(double fX, double fY, double fZ) - : B3DTuple(fX, fY, fZ) - {} - - /** Create a copy of a 3D Point - - @param rVec - The 3D Point which will be copied. - */ - B3DPoint(const B3DPoint& rVec) - : B3DTuple(rVec) - {} - - /** constructor with tuple to allow copy-constructing - from B3DTuple-based classes - */ - B3DPoint(const ::basegfx::tuple::B3DTuple& rTuple) - : B3DTuple(rTuple) - {} - - ~B3DPoint() - {} - - /** *=operator to allow usage from B3DPoint, too - */ - B3DPoint& operator*=( const B3DPoint& rPnt ) - { - mfX *= rPnt.mfX; - mfY *= rPnt.mfY; - mfZ *= rPnt.mfZ; - return *this; - } - - /** *=operator to allow usage from B3DPoint, too - */ - B3DPoint& operator*=(double t) - { - mfX *= t; - mfY *= t; - mfZ *= t; - return *this; - } - - /** assignment operator to allow assigning the results - of B3DTuple calculations - */ - B3DPoint& operator=( const ::basegfx::tuple::B3DTuple& rVec ) - { - mfX = rVec.getX(); - mfY = rVec.getY(); - mfZ = rVec.getZ(); - return *this; - } - - /** Transform point by given transformation matrix. - - The translational components of the matrix are, in - contrast to B3DVector, applied. - */ - B3DPoint& operator*=( const ::basegfx::matrix::B3DHomMatrix& rMat ); - - static const B3DPoint& getEmptyPoint() - { - return (const B3DPoint&) ::basegfx::tuple::B3DTuple::getEmptyTuple(); - } - }; - } // end of namespace point + return (const B3DPoint&) ::basegfx::B3DTuple::getEmptyTuple(); + } + }; } // end of namespace basegfx #endif // _BGFX_POINT_B3DPOINT_HXX diff --git a/basegfx/inc/basegfx/polygon/b2dpolygon.hxx b/basegfx/inc/basegfx/polygon/b2dpolygon.hxx index c58be040d447..610ce5c75df6 100644 --- a/basegfx/inc/basegfx/polygon/b2dpolygon.hxx +++ b/basegfx/inc/basegfx/polygon/b2dpolygon.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygon.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:39:56 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:52 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,101 +72,83 @@ class ImplB2DPolygon; namespace basegfx { - namespace polygon - { - class B2DPolygon; - } // end of namespace polygon - - namespace point - { - class B2DPoint; - } // end of namespace point - - namespace vector - { - class B2DVector; - } // end of namespace vector - - namespace matrix - { - class B2DHomMatrix; - } // end of namespace matrix + class B2DPolygon; + class B2DPoint; + class B2DVector; + class B2DHomMatrix; } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// namespace basegfx { - namespace polygon + class B2DPolygon { - class B2DPolygon - { - private: - // internal data. - ImplB2DPolygon* mpPolygon; - - // internal method to force a ref-counted instance to be copied - // to a modifyable unique copy. - void implForceUniqueCopy(); - - public: - B2DPolygon(); - B2DPolygon(const B2DPolygon& rPolygon); - B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount); - ~B2DPolygon(); - - // assignment operator - B2DPolygon& operator=(const B2DPolygon& rPolygon); - - // compare operators - sal_Bool operator==(const B2DPolygon& rPolygon) const; - sal_Bool operator!=(const B2DPolygon& rPolygon) const; - - // member count - sal_uInt32 count() const; - - // Coordinate interface - ::basegfx::point::B2DPoint getB2DPoint(sal_uInt32 nIndex) const; - void setB2DPoint(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rValue); - - // Coordinate insert/append - void insert(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount = 1); - void append(const ::basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount = 1); - - // ControlVector interface - ::basegfx::vector::B2DVector getControlVectorA(sal_uInt32 nIndex) const; - void setControlVectorA(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue); - ::basegfx::vector::B2DVector getControlVectorB(sal_uInt32 nIndex) const; - void setControlVectorB(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue); - sal_Bool areControlPointsUsed() const; - - // insert/append other 2D polygons - void insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2 = 0, sal_uInt32 nCount = 0); - void append(const B2DPolygon& rPoly, sal_uInt32 nIndex = 0, sal_uInt32 nCount = 0); - - // remove - void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); - - // clear all points - void clear(); - - // closed state - sal_Bool isClosed() const; - void setClosed(sal_Bool bNew); - - // flip polygon direction - void flip(); - - // test if Polygon has double points - sal_Bool hasDoublePoints() const; - - // remove double points, at the begin/end and follow-ups, too - void removeDoublePoints(); - - // apply transformation given in matrix form to the polygon - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix); - }; - } // end of namespace polygon + private: + // internal data. + ImplB2DPolygon* mpPolygon; + + // internal method to force a ref-counted instance to be copied + // to a modifyable unique copy. + void implForceUniqueCopy(); + + public: + B2DPolygon(); + B2DPolygon(const B2DPolygon& rPolygon); + B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount); + ~B2DPolygon(); + + // assignment operator + B2DPolygon& operator=(const B2DPolygon& rPolygon); + + // compare operators + sal_Bool operator==(const B2DPolygon& rPolygon) const; + sal_Bool operator!=(const B2DPolygon& rPolygon) const; + + // member count + sal_uInt32 count() const; + + // Coordinate interface + ::basegfx::B2DPoint getB2DPoint(sal_uInt32 nIndex) const; + void setB2DPoint(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue); + + // Coordinate insert/append + void insert(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rPoint, sal_uInt32 nCount = 1); + void append(const ::basegfx::B2DPoint& rPoint, sal_uInt32 nCount = 1); + + // ControlVector interface + ::basegfx::B2DVector getControlVectorA(sal_uInt32 nIndex) const; + void setControlVectorA(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue); + ::basegfx::B2DVector getControlVectorB(sal_uInt32 nIndex) const; + void setControlVectorB(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue); + sal_Bool areControlPointsUsed() const; + + // insert/append other 2D polygons + void insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2 = 0, sal_uInt32 nCount = 0); + void append(const B2DPolygon& rPoly, sal_uInt32 nIndex = 0, sal_uInt32 nCount = 0); + + // remove + void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); + + // clear all points + void clear(); + + // closed state + sal_Bool isClosed() const; + void setClosed(sal_Bool bNew); + + // flip polygon direction + void flip(); + + // test if Polygon has double points + sal_Bool hasDoublePoints() const; + + // remove double points, at the begin/end and follow-ups, too + void removeDoublePoints(); + + // apply transformation given in matrix form to the polygon + void transform(const ::basegfx::B2DHomMatrix& rMatrix); + }; } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx b/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx index b2fc5f9c16e5..4da9f650a526 100644 --- a/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx +++ b/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygontools.hxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:39:56 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:53 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,148 +70,137 @@ #include <basegfx/vector/b2dvector.hxx> #endif +#include <vector> + ////////////////////////////////////////////////////////////////////////////// namespace basegfx { // predefinitions - namespace polygon - { - class B2DPolygon; - } // end of namespace polygon - - // predefinitions - namespace range - { - class B2DRange; - } // end of namespace range + class B2DPolygon; + class B2DRange; - namespace polygon + namespace tools { - namespace tools - { - // B2DPolygon tools - - /** Check if given polygon is closed. This is kind of a - 'classic' method to support old polygon definitions. - Those old polygon definitions define the closed state - of the polygon using identical start and endpoints. This - method corrects this (removes double start/end points) - and sets the Closed()-state of the polygon correctly. - */ - void checkClosed(::basegfx::polygon::B2DPolygon& rCandidate); - - // Get index of outmost point (e.g. biggest X and biggest Y) - sal_uInt32 getIndexOfOutmostPoint(const ::basegfx::polygon::B2DPolygon& rCandidate); - - // Get successor and predecessor indices. Returning the same index means there - // is none. Same for successor. - sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate); - sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate); - - // Get index of first different predecessor. Returning the same index means there - // is none. Same for successor. - sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate); - sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate); - - // Get orientation of Polygon - ::basegfx::vector::B2DVectorOrientation getOrientation(const ::basegfx::polygon::B2DPolygon& rCandidate); - - // isInside tests for B2dPoint and other B2dPolygon. On border is not inside as long as - // not sal_True is given in bWithBorder flag. - sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::point::B2DPoint& rPoint, sal_Bool bWithBorder = sal_False); - sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::polygon::B2DPolygon& rPolygon, sal_Bool bWithBorder = sal_False); - - // get size of polygon. Control vectors are included in that ranges. - ::basegfx::range::B2DRange getRange(const ::basegfx::polygon::B2DPolygon& rCandidate); - - // get area of polygon - double getArea(const ::basegfx::polygon::B2DPolygon& rCandidate); - - // get length of polygon edge from point nIndex to nIndex + 1 - double getEdgeLength(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex); - - // get length of polygon - double getLength(const ::basegfx::polygon::B2DPolygon& rCandidate); - - // get position on polygon for absolute given distance. If - // length is given, it is assumed the correct polygon length, if 0.0 it is calculated - // using getLength(...) - ::basegfx::point::B2DPoint getPositionAbsolute(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistance, double fLength = 0.0); - - // get position on polygon for relative given distance in range [0.0 .. 1.0]. If - // length is given, it is assumed the correct polygon length, if 0.0 it is calculated - // using getLength(...) - ::basegfx::point::B2DPoint getPositionRelative(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistance, double fLength = 0.0); - - // get orientation at given polygon point - ::basegfx::vector::B2DVectorOrientation getPointOrientation(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex); - - // Continuity check for point with given index - ::basegfx::vector::B2DVectorContinuity getContinuityInPoint(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex); - - // Subdivide all contained curves. Use distanceBound value if given. - ::basegfx::polygon::B2DPolygon adaptiveSubdivideByDistance(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistanceBound = 0.0); - - // Subdivide all contained curves. Use distanceBound value if given. - ::basegfx::polygon::B2DPolygon adaptiveSubdivideByAngle(const ::basegfx::polygon::B2DPolygon& rCandidate, double fAngleBound = 5.0); - - // Definitions for the cut flags used from the findCut methods - typedef sal_uInt16 CutFlagValue; - - #define CUTFLAG_NONE (0x0000) - #define CUTFLAG_LINE (0x0001) - #define CUTFLAG_START1 (0x0002) - #define CUTFLAG_START2 (0x0004) - #define CUTFLAG_END1 (0x0008) - #define CUTFLAG_END2 (0x0010) - #define CUTFLAG_ALL (CUTFLAG_LINE|CUTFLAG_START1|CUTFLAG_START2|CUTFLAG_END1|CUTFLAG_END2) - #define CUTFLAG_DEFAULT (CUTFLAG_LINE|CUTFLAG_START2|CUTFLAG_END2) - - // Calculate cut between the points given by the two indices. pCut1 - // and pCut2 will contain the cut coordinate on each edge in ]0.0, 1.0] - // (if given) and the return value will contain a cut description. - CutFlagValue findCut( - const ::basegfx::polygon::B2DPolygon& rCandidate, - sal_uInt32 nIndex1, sal_uInt32 nIndex2, - CutFlagValue aCutFlags = CUTFLAG_DEFAULT, - double* pCut1 = 0L, double* pCut2 = 0L); - - // This version is working with two indexed edges from different - // polygons. - CutFlagValue findCut( - const ::basegfx::polygon::B2DPolygon& rCandidate1, sal_uInt32 nIndex1, - const ::basegfx::polygon::B2DPolygon& rCandidate2, sal_uInt32 nIndex2, - CutFlagValue aCutFlags = CUTFLAG_DEFAULT, - double* pCut1 = 0L, double* pCut2 = 0L); - - // This version works with two points and vectors to define the - // edges for the cut test. - CutFlagValue findCut( - const ::basegfx::point::B2DPoint& rEdge1Start, const ::basegfx::vector::B2DVector& rEdge1Delta, - const ::basegfx::point::B2DPoint& rEdge2Start, const ::basegfx::vector::B2DVector& rEdge2Delta, - CutFlagValue aCutFlags = CUTFLAG_DEFAULT, - double* pCut1 = 0L, double* pCut2 = 0L); - - // test if point is on the given edge in range ]0.0..1.0[ without - // the start/end points. If so, return sal_True and put the parameter - // value in pCut (if provided) - sal_Bool isPointOnEdge( - const ::basegfx::point::B2DPoint& rPoint, - const ::basegfx::point::B2DPoint& rEdgeStart, - const ::basegfx::vector::B2DVector& rEdgeDelta, - double* pCut = 0L); - - - - /* Still missing: - void transform(const Matrix4D& rTfMatrix); - Polygon3D getExpandedPolygon(sal_uInt32 nNum); - */ - - - } // end of namespace tools - } // end of namespace polygon + // B2DPolygon tools + + /** Check if given polygon is closed. This is kind of a + 'classic' method to support old polygon definitions. + Those old polygon definitions define the closed state + of the polygon using identical start and endpoints. This + method corrects this (removes double start/end points) + and sets the Closed()-state of the polygon correctly. + */ + void checkClosed(::basegfx::B2DPolygon& rCandidate); + + // Get index of outmost point (e.g. biggest X and biggest Y) + sal_uInt32 getIndexOfOutmostPoint(const ::basegfx::B2DPolygon& rCandidate); + + // Get successor and predecessor indices. Returning the same index means there + // is none. Same for successor. + sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate); + sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate); + + // Get index of first different predecessor. Returning the same index means there + // is none. Same for successor. + sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate); + sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate); + + // Get orientation of Polygon + ::basegfx::B2DVectorOrientation getOrientation(const ::basegfx::B2DPolygon& rCandidate); + + // isInside tests for B2dPoint and other B2dPolygon. On border is not inside as long as + // not sal_True is given in bWithBorder flag. + sal_Bool isInside(const ::basegfx::B2DPolygon& rCandidate, const ::basegfx::B2DPoint& rPoint, sal_Bool bWithBorder = sal_False); + sal_Bool isInside(const ::basegfx::B2DPolygon& rCandidate, const ::basegfx::B2DPolygon& rPolygon, sal_Bool bWithBorder = sal_False); + + // get size of polygon. Control vectors are included in that ranges. + ::basegfx::B2DRange getRange(const ::basegfx::B2DPolygon& rCandidate); + + // get area of polygon + double getArea(const ::basegfx::B2DPolygon& rCandidate); + + // get length of polygon edge from point nIndex to nIndex + 1 + double getEdgeLength(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex); + + // get length of polygon + double getLength(const ::basegfx::B2DPolygon& rCandidate); + + // get position on polygon for absolute given distance. If + // length is given, it is assumed the correct polygon length, if 0.0 it is calculated + // using getLength(...) + ::basegfx::B2DPoint getPositionAbsolute(const ::basegfx::B2DPolygon& rCandidate, double fDistance, double fLength = 0.0); + + // get position on polygon for relative given distance in range [0.0 .. 1.0]. If + // length is given, it is assumed the correct polygon length, if 0.0 it is calculated + // using getLength(...) + ::basegfx::B2DPoint getPositionRelative(const ::basegfx::B2DPolygon& rCandidate, double fDistance, double fLength = 0.0); + + // get orientation at given polygon point + ::basegfx::B2DVectorOrientation getPointOrientation(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex); + + // Continuity check for point with given index + ::basegfx::B2DVectorContinuity getContinuityInPoint(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex); + + // Subdivide all contained curves. Use distanceBound value if given. + ::basegfx::B2DPolygon adaptiveSubdivideByDistance(const ::basegfx::B2DPolygon& rCandidate, double fDistanceBound = 0.0); + + // Subdivide all contained curves. Use distanceBound value if given. + ::basegfx::B2DPolygon adaptiveSubdivideByAngle(const ::basegfx::B2DPolygon& rCandidate, double fAngleBound = 5.0); + + // Definitions for the cut flags used from the findCut methods + typedef sal_uInt16 CutFlagValue; + + #define CUTFLAG_NONE (0x0000) + #define CUTFLAG_LINE (0x0001) + #define CUTFLAG_START1 (0x0002) + #define CUTFLAG_START2 (0x0004) + #define CUTFLAG_END1 (0x0008) + #define CUTFLAG_END2 (0x0010) + #define CUTFLAG_ALL (CUTFLAG_LINE|CUTFLAG_START1|CUTFLAG_START2|CUTFLAG_END1|CUTFLAG_END2) + #define CUTFLAG_DEFAULT (CUTFLAG_LINE|CUTFLAG_START2|CUTFLAG_END2) + + // Calculate cut between the points given by the two indices. pCut1 + // and pCut2 will contain the cut coordinate on each edge in ]0.0, 1.0] + // (if given) and the return value will contain a cut description. + CutFlagValue findCut( + const ::basegfx::B2DPolygon& rCandidate, + sal_uInt32 nIndex1, sal_uInt32 nIndex2, + CutFlagValue aCutFlags = CUTFLAG_DEFAULT, + double* pCut1 = 0L, double* pCut2 = 0L); + + // This version is working with two indexed edges from different + // polygons. + CutFlagValue findCut( + const ::basegfx::B2DPolygon& rCandidate1, sal_uInt32 nIndex1, + const ::basegfx::B2DPolygon& rCandidate2, sal_uInt32 nIndex2, + CutFlagValue aCutFlags = CUTFLAG_DEFAULT, + double* pCut1 = 0L, double* pCut2 = 0L); + + // This version works with two points and vectors to define the + // edges for the cut test. + CutFlagValue findCut( + const ::basegfx::B2DPoint& rEdge1Start, const ::basegfx::B2DVector& rEdge1Delta, + const ::basegfx::B2DPoint& rEdge2Start, const ::basegfx::B2DVector& rEdge2Delta, + CutFlagValue aCutFlags = CUTFLAG_DEFAULT, + double* pCut1 = 0L, double* pCut2 = 0L); + + // test if point is on the given edge in range ]0.0..1.0[ without + // the start/end points. If so, return sal_True and put the parameter + // value in pCut (if provided) + sal_Bool isPointOnEdge( + const ::basegfx::B2DPoint& rPoint, + const ::basegfx::B2DPoint& rEdgeStart, + const ::basegfx::B2DVector& rEdgeDelta, + double* pCut = 0L); + + + + /* Still missing: + void transform(const Matrix4D& rTfMatrix); + Polygon3D getExpandedPolygon(sal_uInt32 nNum); + */ + } // end of namespace tools } // end of namespace basegfx #endif // _BGFX_POLYGON_B2DPOLYGONTOOLS_HXX diff --git a/basegfx/inc/basegfx/polygon/b2dpolypolygon.hxx b/basegfx/inc/basegfx/polygon/b2dpolypolygon.hxx index 89e6b68b4072..1bffaee504f4 100644 --- a/basegfx/inc/basegfx/polygon/b2dpolypolygon.hxx +++ b/basegfx/inc/basegfx/polygon/b2dpolypolygon.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygon.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:39:57 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:53 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,84 +71,74 @@ class ImplB2DPolyPolygon; namespace basegfx { - namespace polygon - { - class B2DPolygon; - } // end of namespace polygon - - namespace matrix - { - class B2DHomMatrix; - } // end of namespace matrix + class B2DPolygon; + class B2DHomMatrix; } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// namespace basegfx { - namespace polygon + class B2DPolyPolygon { - class B2DPolyPolygon - { - private: - ImplB2DPolyPolygon* mpPolyPolygon; + private: + ImplB2DPolyPolygon* mpPolyPolygon; - // internal method to force a ref-counted instance to be copied - // to a modifyable unique copy. - void implForceUniqueCopy(); + // internal method to force a ref-counted instance to be copied + // to a modifyable unique copy. + void implForceUniqueCopy(); - public: - B2DPolyPolygon(); - B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon); - ~B2DPolyPolygon(); + public: + B2DPolyPolygon(); + B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon); + ~B2DPolyPolygon(); - // assignment operator - B2DPolyPolygon& operator=(const B2DPolyPolygon& rPolyPolygon); + // assignment operator + B2DPolyPolygon& operator=(const B2DPolyPolygon& rPolyPolygon); - // compare operators - sal_Bool operator==(const B2DPolyPolygon& rPolyPolygon) const; - sal_Bool operator!=(const B2DPolyPolygon& rPolyPolygon) const; + // compare operators + sal_Bool operator==(const B2DPolyPolygon& rPolyPolygon) const; + sal_Bool operator!=(const B2DPolyPolygon& rPolyPolygon) const; - // polygon interface - sal_uInt32 count() const; + // polygon interface + sal_uInt32 count() const; - B2DPolygon getB2DPolygon(sal_uInt32 nIndex) const; - void setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon); + B2DPolygon getB2DPolygon(sal_uInt32 nIndex) const; + void setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon); - // test for curve - sal_Bool areControlPointsUsed() const; + // test for curve + sal_Bool areControlPointsUsed() const; - // insert/append single polygon - void insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount = 1); - void append(const B2DPolygon& rPolygon, sal_uInt32 nCount = 1); + // insert/append single polygon + void insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount = 1); + void append(const B2DPolygon& rPolygon, sal_uInt32 nCount = 1); - // insert/append multiple polygons - void insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon); - void append(const B2DPolyPolygon& rPolyPolygon); + // insert/append multiple polygons + void insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon); + void append(const B2DPolyPolygon& rPolyPolygon); - // remove - void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); + // remove + void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); - // reset to empty state - void clear(); + // reset to empty state + void clear(); - // closed state - sal_Bool isClosed() const; - void setClosed(sal_Bool bNew); + // closed state + sal_Bool isClosed() const; + void setClosed(sal_Bool bNew); - // flip polygon direction - void flip(); + // flip polygon direction + void flip(); - // test if PolyPolygon has double points - sal_Bool hasDoublePoints() const; + // test if PolyPolygon has double points + sal_Bool hasDoublePoints() const; - // remove double points, at the begin/end and follow-ups, too - void removeDoublePoints(); + // remove double points, at the begin/end and follow-ups, too + void removeDoublePoints(); - // apply transformation given in matrix form to the polygon - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix); - }; - } // end of namespace polygon + // apply transformation given in matrix form to the polygon + void transform(const ::basegfx::B2DHomMatrix& rMatrix); + }; } // end of namespace basegfx #endif // _BGFX_POLYGON_B2DPOLYPOLYGON_HXX diff --git a/basegfx/inc/basegfx/polygon/b2dpolypolygoncutter.hxx b/basegfx/inc/basegfx/polygon/b2dpolypolygoncutter.hxx index c118076d82fe..641045afa14e 100644 --- a/basegfx/inc/basegfx/polygon/b2dpolypolygoncutter.hxx +++ b/basegfx/inc/basegfx/polygon/b2dpolypolygoncutter.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygoncutter.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aw $ $Date: 2003-11-10 11:45:48 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:53 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -93,48 +93,45 @@ namespace basegfx { - namespace polygon + class B2DPolygonNode { - class B2DPolygonNode - { - ::basegfx::point::B2DPoint maPosition; - B2DPolygonNode* mpPrevious; - B2DPolygonNode* mpNext; + ::basegfx::B2DPoint maPosition; + B2DPolygonNode* mpPrevious; + B2DPolygonNode* mpNext; - B2DPolygonNode* mpListPrevious; - B2DPolygonNode* mpListNext; + B2DPolygonNode* mpListPrevious; + B2DPolygonNode* mpListNext; - public: - B2DPolygonNode(const ::basegfx::point::B2DPoint& rPosition, B2DPolygonNode* pPrevious); - ~B2DPolygonNode(); + public: + B2DPolygonNode(const ::basegfx::B2DPoint& rPosition, B2DPolygonNode* pPrevious); + ~B2DPolygonNode(); - B2DPolygonNode* getPrevious() const { return mpPrevious; } - B2DPolygonNode* getNext() const { return mpNext; } - const ::basegfx::point::B2DPoint& getPosition() const { return maPosition; } + B2DPolygonNode* getPrevious() const { return mpPrevious; } + B2DPolygonNode* getNext() const { return mpNext; } + const ::basegfx::B2DPoint& getPosition() const { return maPosition; } - void calcMinMaxX(double& fMaxAX, double& fMinAX) const; - void calcMinMaxY(double& fMaxAY, double& fMinAY) const; + void calcMinMaxX(double& fMaxAX, double& fMinAX) const; + void calcMinMaxY(double& fMaxAY, double& fMinAY) const; - void swapPreviousNext() { B2DPolygonNode* pZwi = mpPrevious; mpPrevious = mpNext; mpNext = pZwi; } - void swapNextPointers(B2DPolygonNode* pCand); + void swapPreviousNext() { B2DPolygonNode* pZwi = mpPrevious; mpPrevious = mpNext; mpNext = pZwi; } + void swapNextPointers(B2DPolygonNode* pCand); - void addToList(B2DPolygonNode*& rpList); - void remFromList(B2DPolygonNode*& rpList); + void addToList(B2DPolygonNode*& rpList); + void remFromList(B2DPolygonNode*& rpList); - sal_Bool getOrientation() const; - void swapOrientation(); - ::basegfx::range::B2DRange getRange() const; + sal_Bool getOrientation() const; + void swapOrientation(); + ::basegfx::B2DRange getRange() const; - // isInside tests for B2dPoint and other B2DPolygonNode Polygon. On border is not inside as long as - // not sal_True is given in bWithBorder flag. - sal_Bool isInside(const ::basegfx::point::B2DPoint& rPnt, sal_Bool bWithBorder = sal_False) const; - sal_Bool isPolygonInside(B2DPolygonNode* pPoly, sal_Bool bWithBorder = sal_False) const; - }; + // isInside tests for B2dPoint and other B2DPolygonNode Polygon. On border is not inside as long as + // not sal_True is given in bWithBorder flag. + sal_Bool isInside(const ::basegfx::B2DPoint& rPnt, sal_Bool bWithBorder = sal_False) const; + sal_Bool isPolygonInside(B2DPolygonNode* pPoly, sal_Bool bWithBorder = sal_False) const; + }; - // a type definition to have a vector of pointers to B2DPolygonNodes - typedef ::std::vector< B2DPolygonNode* > B2DPolygonNodeVector; + // a type definition to have a vector of pointers to B2DPolygonNodes + typedef ::std::vector< B2DPolygonNode* > B2DPolygonNodeVector; - } // end of namespace polygon } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -142,40 +139,37 @@ namespace basegfx namespace basegfx { - namespace polygon + class B2DSimpleCut { - class B2DSimpleCut + B2DPolygonNode* mpLeft; + B2DPolygonNode* mpRight; + + // bitfield + unsigned mbCorrectOrientation : 1; + unsigned mbOrientation : 1; + + public: + B2DSimpleCut(B2DPolygonNode* pL, B2DPolygonNode* pR, sal_Bool bCoOr = sal_False, sal_Bool bOr = sal_True) + : mpLeft(pL), + mpRight(pR), + mbCorrectOrientation(bCoOr), + mbOrientation(bOr) + { + } + + void solve(); + B2DPolygonNode* getLeft() const { return mpLeft; } + B2DPolygonNode* getRight() const { return mpRight; } + + sal_Bool isSameCut(B2DPolygonNode* pA, B2DPolygonNode* pB) const { - B2DPolygonNode* mpLeft; - B2DPolygonNode* mpRight; - - // bitfield - unsigned mbCorrectOrientation : 1; - unsigned mbOrientation : 1; - - public: - B2DSimpleCut(B2DPolygonNode* pL, B2DPolygonNode* pR, sal_Bool bCoOr = sal_False, sal_Bool bOr = sal_True) - : mpLeft(pL), - mpRight(pR), - mbCorrectOrientation(bCoOr), - mbOrientation(bOr) - { - } - - void solve(); - B2DPolygonNode* getLeft() const { return mpLeft; } - B2DPolygonNode* getRight() const { return mpRight; } - - sal_Bool isSameCut(B2DPolygonNode* pA, B2DPolygonNode* pB) const - { - return ((pA == mpLeft && pB == mpRight) || (pB == mpLeft && pA == mpRight)); - } - }; - - // a type definition to have a vector of pointers to B2DSimpleCuts - typedef ::std::vector< B2DSimpleCut* > B2DSimpleCutVector; - - } // end of namespace polygon + return ((pA == mpLeft && pB == mpRight) || (pB == mpLeft && pA == mpRight)); + } + }; + + // a type definition to have a vector of pointers to B2DSimpleCuts + typedef ::std::vector< B2DSimpleCut* > B2DSimpleCutVector; + } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -183,27 +177,24 @@ namespace basegfx namespace basegfx { - namespace polygon + class B2DClipExtraPolygonInfo { - class B2DClipExtraPolygonInfo - { - ::basegfx::range::B2DRange maRange; - sal_Int32 mnDepth; + ::basegfx::B2DRange maRange; + sal_Int32 mnDepth; - // bitfield - unsigned mbOrientation : 1; + // bitfield + unsigned mbOrientation : 1; - public: - B2DClipExtraPolygonInfo() {} + public: + B2DClipExtraPolygonInfo() {} - void init(B2DPolygonNode* pNew); - const ::basegfx::range::B2DRange& getRange() const { return maRange; } - sal_Bool getOrientation() const { return mbOrientation; } + void init(B2DPolygonNode* pNew); + const ::basegfx::B2DRange& getRange() const { return maRange; } + sal_Bool getOrientation() const { return mbOrientation; } - sal_Int32 getDepth() const { return mnDepth; } - void changeDepth(sal_Bool bOrientation); - }; - } // end of namespace polygon + sal_Int32 getDepth() const { return mnDepth; } + void changeDepth(sal_Bool bOrientation); + }; } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -211,69 +202,66 @@ namespace basegfx namespace basegfx { - namespace polygon + class B2DPolyPolygonCutter { - class B2DPolyPolygonCutter + // list of polys + B2DPolygonNodeVector maPolygonList; + B2DPolyPolygon maNotClosedPolygons; + + // help routines + sal_Bool isSamePos(const ::basegfx::B2DPoint& rPntA, const ::basegfx::B2DPoint& rPntB) + { + return rPntA.equal(rPntB); + } + + B2DSimpleCut* getExistingCut(B2DSimpleCutVector& rTmpCuts, B2DPolygonNode* pA, B2DPolygonNode* pB); + B2DPolygonNode* extractNextPolygon(B2DPolygonNode*& rpList); + sal_Bool isCrossover(B2DPolygonNode* pA, B2DPolygonNode* pB); + sal_Bool isCrossover(B2DSimpleCut* pEnter, B2DSimpleCut* pLeave); + + sal_Bool isNextSamePos(B2DPolygonNode* pA, B2DPolygonNode* pB) { - // list of polys - B2DPolygonNodeVector maPolygonList; - B2DPolyPolygon maNotClosedPolygons; - - // help routines - sal_Bool isSamePos(const ::basegfx::point::B2DPoint& rPntA, const ::basegfx::point::B2DPoint& rPntB) - { - return rPntA.equal(rPntB); - } - - B2DSimpleCut* getExistingCut(B2DSimpleCutVector& rTmpCuts, B2DPolygonNode* pA, B2DPolygonNode* pB); - B2DPolygonNode* extractNextPolygon(B2DPolygonNode*& rpList); - sal_Bool isCrossover(B2DPolygonNode* pA, B2DPolygonNode* pB); - sal_Bool isCrossover(B2DSimpleCut* pEnter, B2DSimpleCut* pLeave); - - sal_Bool isNextSamePos(B2DPolygonNode* pA, B2DPolygonNode* pB) - { - return isSamePos(pA->getNext()->getPosition(), pB->getNext()->getPosition()); - } - - sal_Bool isPrevSamePos(B2DPolygonNode* pA, B2DPolygonNode* pB) - { - return isSamePos(pA->getPrevious()->getPosition(), pB->getPrevious()->getPosition()); - } - - void addAllNodes(B2DPolygonNode* pPolygon, B2DPolygonNode*& rpList); - B2DPolygonNode* createNewPolygon(const B2DPolygon& rPolygon); - void deletePolygon(B2DPolygonNode* pCand); - void polysToList(B2DPolygonNode*& rpList); - void listToPolys(B2DPolygonNode*& rpList); - - sal_Bool doRangesIntersect(const ::basegfx::range::B2DRange& rRange1, const ::basegfx::range::B2DRange& rRange2) const - { - return rRange1.overlaps(rRange2); - } - - sal_Bool doRangesInclude(const ::basegfx::range::B2DRange& rRange1, const ::basegfx::range::B2DRange& rRange2) const - { - return rRange1.isInside(rRange2); - } - - void solveAllCuts(B2DSimpleCutVector& rCuts); - - public: - B2DPolyPolygonCutter() {} - ~B2DPolyPolygonCutter(); - - // put/get poly - void addPolyPolygon(const B2DPolyPolygon& rPolyPolygon, sal_Bool bForceOrientation = sal_False); - void getPolyPolygon(B2DPolyPolygon& rPolyPolygon); - - // transformations - void removeSelfIntersections(); - void removeDoubleIntersections(); - - // remove included - void removeIncludedPolygons(sal_Bool bUseOr = sal_True); - }; - } // end of namespace polygon + return isSamePos(pA->getNext()->getPosition(), pB->getNext()->getPosition()); + } + + sal_Bool isPrevSamePos(B2DPolygonNode* pA, B2DPolygonNode* pB) + { + return isSamePos(pA->getPrevious()->getPosition(), pB->getPrevious()->getPosition()); + } + + void addAllNodes(B2DPolygonNode* pPolygon, B2DPolygonNode*& rpList); + B2DPolygonNode* createNewPolygon(const B2DPolygon& rPolygon); + void deletePolygon(B2DPolygonNode* pCand); + void polysToList(B2DPolygonNode*& rpList); + void listToPolys(B2DPolygonNode*& rpList); + + sal_Bool doRangesIntersect(const ::basegfx::B2DRange& rRange1, const ::basegfx::B2DRange& rRange2) const + { + return rRange1.overlaps(rRange2); + } + + sal_Bool doRangesInclude(const ::basegfx::B2DRange& rRange1, const ::basegfx::B2DRange& rRange2) const + { + return rRange1.isInside(rRange2); + } + + void solveAllCuts(B2DSimpleCutVector& rCuts); + + public: + B2DPolyPolygonCutter() {} + ~B2DPolyPolygonCutter(); + + // put/get poly + void addPolyPolygon(const B2DPolyPolygon& rPolyPolygon, sal_Bool bForceOrientation = sal_False); + void getPolyPolygon(B2DPolyPolygon& rPolyPolygon); + + // transformations + void removeSelfIntersections(); + void removeDoubleIntersections(); + + // remove included + void removeIncludedPolygons(sal_Bool bUseOr = sal_True); + }; } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx b/basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx index 5165ef6a37ed..f51f64e9ec23 100644 --- a/basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx +++ b/basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygontools.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:39:57 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:53 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,56 +70,59 @@ #include <basegfx/vector/b2dvector.hxx> #endif +#ifndef _BGFX_POLYGON_B2DPOLYGON_HXX +#include <basegfx/polygon/b2dpolygon.hxx> +#endif + +#include <vector> + ////////////////////////////////////////////////////////////////////////////// namespace basegfx { // predefinitions - namespace polygon - { - class B2DPolyPolygon; - } // end of namespace polygon + class B2DPolyPolygon; + class B2DRange; - // predefinitions - namespace range + namespace tools { - class B2DRange; - } // end of namespace range + // B2DPolyPolygon tools - namespace polygon - { - namespace tools - { - // B2DPolyPolygon tools - - // Check and evtl. correct orientations of all contained Polygons so that - // the orientations of contained polygons will variate to express areas and - // holes - void correctOrientations(::basegfx::polygon::B2DPolyPolygon& rCandidate); - - // Remove all intersections, the self intersections and the in-between - // polygon intersections. After this operation there are no more intersections - // in the given PolyPolygon. Only closed polygons are handled. The non-closed - // polygons or the ones with less than 3 points are preserved, but not - // computed. - // bForceOrientation: If sal_True, the orientations of all contained polygons - // is changed to ORIENTATION_POSITIVE before computing. - // bInvertRemove: if sal_True, created polygons which are inside others and - // have the same orientation are removed (cleanup). - void removeIntersections(::basegfx::polygon::B2DPolyPolygon& rCandidate, - sal_Bool bForceOrientation = sal_True, sal_Bool bInvertRemove = sal_False); - - // Subdivide all contained curves. Use distanceBound value if given. - ::basegfx::polygon::B2DPolyPolygon adaptiveSubdivideByDistance(const ::basegfx::polygon::B2DPolyPolygon& rCandidate, double fDistanceBound = 0.0); - - // Subdivide all contained curves. Use distanceBound value if given. - ::basegfx::polygon::B2DPolyPolygon adaptiveSubdivideByAngle(const ::basegfx::polygon::B2DPolyPolygon& rCandidate, double fAngleBound = 5.0); - - // get size of PolyPolygon. Control vectors are included in that ranges. - ::basegfx::range::B2DRange getRange(const ::basegfx::polygon::B2DPolyPolygon& rCandidate); - - } // end of namespace tools - } // end of namespace polygon + // Check and evtl. correct orientations of all contained Polygons so that + // the orientations of contained polygons will variate to express areas and + // holes + void correctOrientations(::basegfx::B2DPolyPolygon& rCandidate); + + // Remove all intersections, the self intersections and the in-between + // polygon intersections. After this operation there are no more intersections + // in the given PolyPolygon. Only closed polygons are handled. The non-closed + // polygons or the ones with less than 3 points are preserved, but not + // computed. + // bForceOrientation: If sal_True, the orientations of all contained polygons + // is changed to ORIENTATION_POSITIVE before computing. + // bInvertRemove: if sal_True, created polygons which are inside others and + // have the same orientation are removed (cleanup). + void removeIntersections(::basegfx::B2DPolyPolygon& rCandidate, + sal_Bool bForceOrientation = sal_True, sal_Bool bInvertRemove = sal_False); + + // Subdivide all contained curves. Use distanceBound value if given. + ::basegfx::B2DPolyPolygon adaptiveSubdivideByDistance(const ::basegfx::B2DPolyPolygon& rCandidate, double fDistanceBound = 0.0); + + // Subdivide all contained curves. Use distanceBound value if given. + ::basegfx::B2DPolyPolygon adaptiveSubdivideByAngle(const ::basegfx::B2DPolyPolygon& rCandidate, double fAngleBound = 5.0); + + // get size of PolyPolygon. Control vectors are included in that ranges. + ::basegfx::B2DRange getRange(const ::basegfx::B2DPolyPolygon& rCandidate); + + // Apply Line Dashing. This cuts every contained PolyPolygon into line pieces + // which are inserted as single polygons into the result. + ::basegfx::B2DPolyPolygon applyLineDashing(const ::basegfx::B2DPolyPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen); + + // Apply Line Dashing. This cuts the Polygon into line pieces + // which are inserted as single polygons into the result. + ::basegfx::B2DPolyPolygon applyLineDashing(const ::basegfx::B2DPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen); + + } // end of namespace tools } // end of namespace basegfx #endif // _BGFX_POLYPOLYGON_B2DPOLYGONTOOLS_HXX diff --git a/basegfx/inc/basegfx/polygon/b3dpolygon.hxx b/basegfx/inc/basegfx/polygon/b3dpolygon.hxx index 4df95083ee57..ef18da4035f9 100644 --- a/basegfx/inc/basegfx/polygon/b3dpolygon.hxx +++ b/basegfx/inc/basegfx/polygon/b3dpolygon.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolygon.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:29:18 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:53 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,89 +72,75 @@ class ImplB3DPolygon; namespace basegfx { - namespace polygon - { - class B3DPolygon; - } // end of namespace polygon - - namespace point - { - class B3DPoint; - } // end of namespace point - - namespace matrix - { - class B3DHomMatrix; - } // end of namespace matrix + class B3DPolygon; + class B3DPoint; + class B3DHomMatrix; } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// namespace basegfx { - namespace polygon + class B3DPolygon { - class B3DPolygon - { - private: - // internal data. - ImplB3DPolygon* mpPolygon; + private: + // internal data. + ImplB3DPolygon* mpPolygon; - // internal method to force a ref-counted instance to be copied - // to a modifyable unique copy. - void implForceUniqueCopy(); + // internal method to force a ref-counted instance to be copied + // to a modifyable unique copy. + void implForceUniqueCopy(); - public: - B3DPolygon(); - B3DPolygon(const B3DPolygon& rPolygon); - B3DPolygon(const B3DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount); - ~B3DPolygon(); + public: + B3DPolygon(); + B3DPolygon(const B3DPolygon& rPolygon); + B3DPolygon(const B3DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount); + ~B3DPolygon(); - // assignment operator - B3DPolygon& operator=(const B3DPolygon& rPolygon); + // assignment operator + B3DPolygon& operator=(const B3DPolygon& rPolygon); - // compare operators - sal_Bool operator==(const B3DPolygon& rPolygon) const; - sal_Bool operator!=(const B3DPolygon& rPolygon) const; + // compare operators + sal_Bool operator==(const B3DPolygon& rPolygon) const; + sal_Bool operator!=(const B3DPolygon& rPolygon) const; - // member count - sal_uInt32 count() const; + // member count + sal_uInt32 count() const; - // Coordinate interface - ::basegfx::point::B3DPoint getB3DPoint(sal_uInt32 nIndex) const; - void setB3DPoint(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rValue); + // Coordinate interface + ::basegfx::B3DPoint getB3DPoint(sal_uInt32 nIndex) const; + void setB3DPoint(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rValue); - // Coordinate insert/append - void insert(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rPoint, sal_uInt32 nCount = 1); - void append(const ::basegfx::point::B3DPoint& rPoint, sal_uInt32 nCount = 1); + // Coordinate insert/append + void insert(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount = 1); + void append(const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount = 1); - // insert/append other 2D polygons - void insert(sal_uInt32 nIndex, const B3DPolygon& rPoly, sal_uInt32 nIndex2 = 0, sal_uInt32 nCount = 0); - void append(const B3DPolygon& rPoly, sal_uInt32 nIndex = 0, sal_uInt32 nCount = 0); + // insert/append other 2D polygons + void insert(sal_uInt32 nIndex, const B3DPolygon& rPoly, sal_uInt32 nIndex2 = 0, sal_uInt32 nCount = 0); + void append(const B3DPolygon& rPoly, sal_uInt32 nIndex = 0, sal_uInt32 nCount = 0); - // remove - void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); + // remove + void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); - // clear all points - void clear(); + // clear all points + void clear(); - // closed state - sal_Bool isClosed() const; - void setClosed(sal_Bool bNew); + // closed state + sal_Bool isClosed() const; + void setClosed(sal_Bool bNew); - // flip polygon direction - void flip(); + // flip polygon direction + void flip(); - // test if Polygon has double points - sal_Bool hasDoublePoints() const; + // test if Polygon has double points + sal_Bool hasDoublePoints() const; - // remove double points, at the begin/end and follow-ups, too - void removeDoublePoints(); + // remove double points, at the begin/end and follow-ups, too + void removeDoublePoints(); - // apply transformation given in matrix form to the polygon - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix); - }; - } // end of namespace polygon + // apply transformation given in matrix form to the polygon + void transform(const ::basegfx::B3DHomMatrix& rMatrix); + }; } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/inc/basegfx/polygon/b3dpolygontools.hxx b/basegfx/inc/basegfx/polygon/b3dpolygontools.hxx index 7536de67bb21..e8d71b52197d 100644 --- a/basegfx/inc/basegfx/polygon/b3dpolygontools.hxx +++ b/basegfx/inc/basegfx/polygon/b3dpolygontools.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolygontools.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:29:20 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,68 +70,67 @@ #include <basegfx/vector/b3dvector.hxx> #endif +#ifndef _BGFX_POLYGON_B3DPOLYPOLYGON_HXX +#include <basegfx/polygon/b3dpolypolygon.hxx> +#endif + +#include <vector> + ////////////////////////////////////////////////////////////////////////////// namespace basegfx { // predefinitions - namespace polygon - { - class B3DPolygon; - } // end of namespace polygon - - // predefinitions - namespace range - { - class B3DRange; - } // end of namespace range + class B3DPolygon; + class B3DRange; - namespace polygon + namespace tools { - namespace tools - { - // B3DPolygon tools - - /** Check if given polygon is closed. This is kind of a - 'classic' method to support old polygon definitions. - Those old polygon definitions define the closed state - of the polygon using identical start and endpoints. This - method corrects this (removes double start/end points) - and sets the Closed()-state of the polygon correctly. - */ - void checkClosed(::basegfx::polygon::B3DPolygon& rCandidate); - - // Get successor and predecessor indices. Returning the same index means there - // is none. Same for successor. - sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate); - sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate); - - // Get index of first different predecessor. Returning the same index means there - // is none. Same for successor. - sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate); - sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate); - - // get size of polygon. Control vectors are included in that ranges. - ::basegfx::range::B3DRange getRange(const ::basegfx::polygon::B3DPolygon& rCandidate); - - // get length of polygon edge from point nIndex to nIndex + 1 - double getEdgeLength(const ::basegfx::polygon::B3DPolygon& rCandidate, sal_uInt32 nIndex); - - // get length of polygon - double getLength(const ::basegfx::polygon::B3DPolygon& rCandidate); - - // get position on polygon for absolute given distance. If - // length is given, it is assumed the correct polygon length, if 0.0 it is calculated - // using getLength(...) - ::basegfx::point::B3DPoint getPositionAbsolute(const ::basegfx::polygon::B3DPolygon& rCandidate, double fDistance, double fLength = 0.0); - - // get position on polygon for relative given distance in range [0.0 .. 1.0]. If - // length is given, it is assumed the correct polygon length, if 0.0 it is calculated - // using getLength(...) - ::basegfx::point::B3DPoint getPositionRelative(const ::basegfx::polygon::B3DPolygon& rCandidate, double fDistance, double fLength = 0.0); - - } // end of namespace tools - } // end of namespace polygon + // B3DPolygon tools + + /** Check if given polygon is closed. This is kind of a + 'classic' method to support old polygon definitions. + Those old polygon definitions define the closed state + of the polygon using identical start and endpoints. This + method corrects this (removes double start/end points) + and sets the Closed()-state of the polygon correctly. + */ + void checkClosed(::basegfx::B3DPolygon& rCandidate); + + // Get successor and predecessor indices. Returning the same index means there + // is none. Same for successor. + sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate); + sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate); + + // Get index of first different predecessor. Returning the same index means there + // is none. Same for successor. + sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate); + sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate); + + // get size of polygon. Control vectors are included in that ranges. + ::basegfx::B3DRange getRange(const ::basegfx::B3DPolygon& rCandidate); + + // get length of polygon edge from point nIndex to nIndex + 1 + double getEdgeLength(const ::basegfx::B3DPolygon& rCandidate, sal_uInt32 nIndex); + + // get length of polygon + double getLength(const ::basegfx::B3DPolygon& rCandidate); + + // get position on polygon for absolute given distance. If + // length is given, it is assumed the correct polygon length, if 0.0 it is calculated + // using getLength(...) + ::basegfx::B3DPoint getPositionAbsolute(const ::basegfx::B3DPolygon& rCandidate, double fDistance, double fLength = 0.0); + + // get position on polygon for relative given distance in range [0.0 .. 1.0]. If + // length is given, it is assumed the correct polygon length, if 0.0 it is calculated + // using getLength(...) + ::basegfx::B3DPoint getPositionRelative(const ::basegfx::B3DPolygon& rCandidate, double fDistance, double fLength = 0.0); + + // Apply Line Dashing. This cuts the Polygon into line pieces + // which are inserted as single polygons into the result. + ::basegfx::B3DPolyPolygon applyLineDashing(const ::basegfx::B3DPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen); + + } // end of namespace tools } // end of namespace basegfx #endif // _BGFX_POLYGON_B3DPOLYGONTOOLS_HXX diff --git a/basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx b/basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx index 1fcd5634d15c..c3a84e3e8750 100644 --- a/basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx +++ b/basegfx/inc/basegfx/polygon/b3dpolypolygon.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolypolygon.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:29:18 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,81 +71,71 @@ class ImplB3DPolyPolygon; namespace basegfx { - namespace polygon - { - class B3DPolygon; - } // end of namespace polygon - - namespace matrix - { - class B3DHomMatrix; - } // end of namespace matrix + class B3DPolygon; + class B3DHomMatrix; } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// namespace basegfx { - namespace polygon + class B3DPolyPolygon { - class B3DPolyPolygon - { - private: - ImplB3DPolyPolygon* mpPolyPolygon; + private: + ImplB3DPolyPolygon* mpPolyPolygon; - // internal method to force a ref-counted instance to be copied - // to a modifyable unique copy. - void implForceUniqueCopy(); + // internal method to force a ref-counted instance to be copied + // to a modifyable unique copy. + void implForceUniqueCopy(); - public: - B3DPolyPolygon(); - B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon); - ~B3DPolyPolygon(); + public: + B3DPolyPolygon(); + B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon); + ~B3DPolyPolygon(); - // assignment operator - B3DPolyPolygon& operator=(const B3DPolyPolygon& rPolyPolygon); + // assignment operator + B3DPolyPolygon& operator=(const B3DPolyPolygon& rPolyPolygon); - // compare operators - sal_Bool operator==(const B3DPolyPolygon& rPolyPolygon) const; - sal_Bool operator!=(const B3DPolyPolygon& rPolyPolygon) const; + // compare operators + sal_Bool operator==(const B3DPolyPolygon& rPolyPolygon) const; + sal_Bool operator!=(const B3DPolyPolygon& rPolyPolygon) const; - // polygon interface - sal_uInt32 count() const; + // polygon interface + sal_uInt32 count() const; - B3DPolygon getB3DPolygon(sal_uInt32 nIndex) const; - void setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon); + B3DPolygon getB3DPolygon(sal_uInt32 nIndex) const; + void setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon); - // insert/append single polygon - void insert(sal_uInt32 nIndex, const B3DPolygon& rPolygon, sal_uInt32 nCount = 1); - void append(const B3DPolygon& rPolygon, sal_uInt32 nCount = 1); + // insert/append single polygon + void insert(sal_uInt32 nIndex, const B3DPolygon& rPolygon, sal_uInt32 nCount = 1); + void append(const B3DPolygon& rPolygon, sal_uInt32 nCount = 1); - // insert/append multiple polygons - void insert(sal_uInt32 nIndex, const B3DPolyPolygon& rPolyPolygon); - void append(const B3DPolyPolygon& rPolyPolygon); + // insert/append multiple polygons + void insert(sal_uInt32 nIndex, const B3DPolyPolygon& rPolyPolygon); + void append(const B3DPolyPolygon& rPolyPolygon); - // remove - void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); + // remove + void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); - // reset to empty state - void clear(); + // reset to empty state + void clear(); - // closed state - sal_Bool isClosed() const; - void setClosed(sal_Bool bNew); + // closed state + sal_Bool isClosed() const; + void setClosed(sal_Bool bNew); - // flip polygon direction - void flip(); + // flip polygon direction + void flip(); - // test if PolyPolygon has double points - sal_Bool hasDoublePoints() const; + // test if PolyPolygon has double points + sal_Bool hasDoublePoints() const; - // remove double points, at the begin/end and follow-ups, too - void removeDoublePoints(); + // remove double points, at the begin/end and follow-ups, too + void removeDoublePoints(); - // apply transformation given in matrix form to the polygon - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix); - }; - } // end of namespace polygon + // apply transformation given in matrix form to the polygon + void transform(const ::basegfx::B3DHomMatrix& rMatrix); + }; } // end of namespace basegfx #endif // _BGFX_POLYGON_B3DPOLYPOLYGON_HXX diff --git a/basegfx/inc/basegfx/polygon/b3dpolypolygontools.hxx b/basegfx/inc/basegfx/polygon/b3dpolypolygontools.hxx index c731930fa69a..aa056975971e 100644 --- a/basegfx/inc/basegfx/polygon/b3dpolypolygontools.hxx +++ b/basegfx/inc/basegfx/polygon/b3dpolypolygontools.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolypolygontools.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:29:22 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,33 +70,28 @@ #include <basegfx/vector/b2dvector.hxx> #endif +#include <vector> + ////////////////////////////////////////////////////////////////////////////// namespace basegfx { // predefinitions - namespace polygon - { - class B3DPolyPolygon; - } // end of namespace polygon + class B3DPolyPolygon; + class B3DRange; - // predefinitions - namespace range + namespace tools { - class B3DRange; - } // end of namespace range + // B3DPolyPolygon tools - namespace polygon - { - namespace tools - { - // B3DPolyPolygon tools + // get size of PolyPolygon. Control vectors are included in that ranges. + ::basegfx::B3DRange getRange(const ::basegfx::B3DPolyPolygon& rCandidate); - // get size of PolyPolygon. Control vectors are included in that ranges. - ::basegfx::range::B3DRange getRange(const ::basegfx::polygon::B3DPolyPolygon& rCandidate); + // Apply Line Dashing. This cuts every contained PolyPolygon into line pieces + // which are inserted as single polygons into the result. + ::basegfx::B3DPolyPolygon applyLineDashing(const ::basegfx::B3DPolyPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen); - } // end of namespace tools - } // end of namespace polygon + } // end of namespace tools } // end of namespace basegfx #endif // _BGFX_POLYPOLYGON_B3DPOLYGONTOOLS_HXX diff --git a/basegfx/inc/basegfx/range/b1drange.hxx b/basegfx/inc/basegfx/range/b1drange.hxx index e2fd154b5e11..4bb457b28d35 100644 --- a/basegfx/inc/basegfx/range/b1drange.hxx +++ b/basegfx/inc/basegfx/range/b1drange.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b1drange.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:00 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:56 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,88 +68,85 @@ namespace basegfx { - namespace range + class B1DRange { - class B1DRange + ::basegfx::BasicRange maRange; + + public: + B1DRange() + { + } + + B1DRange(double fStartValue) + : maRange(fStartValue) + { + } + + B1DRange(const B1DRange& rRange) + : maRange(rRange.maRange) + { + } + + sal_Bool isEmpty() const + { + return maRange.isEmpty(); + } + + void reset() + { + maRange.reset(); + } + + void operator=(const B1DRange& rRange) + { + maRange = rRange.maRange; + } + + double getMinimum() const + { + return maRange.getMinimum(); + } + + double getMaximum() const + { + return maRange.getMaximum(); + } + + double getRange() const + { + return maRange.getRange(); + } + + double getCenter() const + { + return maRange.getCenter(); + } + + sal_Bool isInside(double fValue) const + { + return maRange.isInside(fValue); + } + + sal_Bool isInside(const B1DRange& rRange) const + { + return maRange.isInside(rRange.maRange); + } + + sal_Bool overlaps(const B1DRange& rRange) const + { + return maRange.overlaps(rRange.maRange); + } + + void expand(double fValue) + { + maRange.expand(fValue); + } + + void expand(const B1DRange& rRange) { - ::basegfx::range::BasicRange maRange; - - public: - B1DRange() - { - } - - B1DRange(double fStartValue) - : maRange(fStartValue) - { - } - - B1DRange(const B1DRange& rRange) - : maRange(rRange.maRange) - { - } - - sal_Bool isEmpty() const - { - return maRange.isEmpty(); - } - - void reset() - { - maRange.reset(); - } - - void operator=(const B1DRange& rRange) - { - maRange = rRange.maRange; - } - - double getMinimum() const - { - return maRange.getMinimum(); - } - - double getMaximum() const - { - return maRange.getMaximum(); - } - - double getRange() const - { - return maRange.getRange(); - } - - double getCenter() const - { - return maRange.getCenter(); - } - - sal_Bool isInside(double fValue) const - { - return maRange.isInside(fValue); - } - - sal_Bool isInside(const B1DRange& rRange) const - { - return maRange.isInside(rRange.maRange); - } - - sal_Bool overlaps(const B1DRange& rRange) const - { - return maRange.overlaps(rRange.maRange); - } - - void expand(double fValue) - { - maRange.expand(fValue); - } - - void expand(const B1DRange& rRange) - { - maRange.expand(rRange.maRange); - } - }; - } // end of namespace range + maRange.expand(rRange.maRange); + } + }; } // end of namespace basegfx #endif // _BGFX_RANGE_B1DRANGE_HXX diff --git a/basegfx/inc/basegfx/range/b2drange.hxx b/basegfx/inc/basegfx/range/b2drange.hxx index 10f14abe9fd7..c30d461f259a 100644 --- a/basegfx/inc/basegfx/range/b2drange.hxx +++ b/basegfx/inc/basegfx/range/b2drange.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2drange.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:01 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:56 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,119 +72,116 @@ namespace basegfx { - namespace range + class B2DRange { - class B2DRange + ::basegfx::BasicRange maRangeX; + ::basegfx::BasicRange maRangeY; + + public: + B2DRange() + { + } + + B2DRange(const B2DTuple& rTuple) + : maRangeX(rTuple.getX()), + maRangeY(rTuple.getY()) + { + } + + B2DRange(const B2DRange& rRange) + : maRangeX(rRange.maRangeX), + maRangeY(rRange.maRangeY) + { + } + + sal_Bool isEmpty() const + { + return ( + maRangeX.isEmpty() + || maRangeY.isEmpty() + ); + } + + void reset() + { + maRangeX.reset(); + maRangeY.reset(); + } + + void operator=(const B2DRange& rRange) + { + maRangeX = rRange.maRangeX; + maRangeY = rRange.maRangeY; + } + + B2DTuple getMinimum() const + { + return B2DTuple( + maRangeX.getMinimum(), + maRangeY.getMinimum() + ); + } + + B2DTuple getMaximum() const + { + return B2DTuple( + maRangeX.getMaximum(), + maRangeY.getMaximum() + ); + } + + B2DTuple getRange() const + { + return B2DTuple( + maRangeX.getRange(), + maRangeY.getRange() + ); + } + + B2DTuple getCenter() const + { + return B2DTuple( + maRangeX.getCenter(), + maRangeY.getCenter() + ); + } + + sal_Bool isInside(const B2DTuple& rTuple) const + { + return ( + maRangeX.isInside(rTuple.getX()) + && maRangeY.isInside(rTuple.getY()) + ); + } + + sal_Bool isInside(const B2DRange& rRange) const + { + return ( + maRangeX.isInside(rRange.maRangeX) + && maRangeY.isInside(rRange.maRangeY) + ); + } + + sal_Bool overlaps(const B2DRange& rRange) const + { + return ( + maRangeX.overlaps(rRange.maRangeX) + && maRangeY.overlaps(rRange.maRangeY) + ); + } + + void expand(const B2DTuple& rTuple) + { + maRangeX.expand(rTuple.getX()); + maRangeY.expand(rTuple.getY()); + } + + void expand(const B2DRange& rRange) { - ::basegfx::range::BasicRange maRangeX; - ::basegfx::range::BasicRange maRangeY; - - public: - B2DRange() - { - } - - B2DRange(const tuple::B2DTuple& rTuple) - : maRangeX(rTuple.getX()), - maRangeY(rTuple.getY()) - { - } - - B2DRange(const B2DRange& rRange) - : maRangeX(rRange.maRangeX), - maRangeY(rRange.maRangeY) - { - } - - sal_Bool isEmpty() const - { - return ( - maRangeX.isEmpty() - || maRangeY.isEmpty() - ); - } - - void reset() - { - maRangeX.reset(); - maRangeY.reset(); - } - - void operator=(const B2DRange& rRange) - { - maRangeX = rRange.maRangeX; - maRangeY = rRange.maRangeY; - } - - tuple::B2DTuple getMinimum() const - { - return tuple::B2DTuple( - maRangeX.getMinimum(), - maRangeY.getMinimum() - ); - } - - tuple::B2DTuple getMaximum() const - { - return tuple::B2DTuple( - maRangeX.getMaximum(), - maRangeY.getMaximum() - ); - } - - tuple::B2DTuple getRange() const - { - return tuple::B2DTuple( - maRangeX.getRange(), - maRangeY.getRange() - ); - } - - tuple::B2DTuple getCenter() const - { - return tuple::B2DTuple( - maRangeX.getCenter(), - maRangeY.getCenter() - ); - } - - sal_Bool isInside(const tuple::B2DTuple& rTuple) const - { - return ( - maRangeX.isInside(rTuple.getX()) - && maRangeY.isInside(rTuple.getY()) - ); - } - - sal_Bool isInside(const B2DRange& rRange) const - { - return ( - maRangeX.isInside(rRange.maRangeX) - && maRangeY.isInside(rRange.maRangeY) - ); - } - - sal_Bool overlaps(const B2DRange& rRange) const - { - return ( - maRangeX.overlaps(rRange.maRangeX) - && maRangeY.overlaps(rRange.maRangeY) - ); - } - - void expand(const tuple::B2DTuple& rTuple) - { - maRangeX.expand(rTuple.getX()); - maRangeY.expand(rTuple.getY()); - } - - void expand(const B2DRange& rRange) - { - maRangeX.expand(rRange.maRangeX); - maRangeY.expand(rRange.maRangeY); - } - }; - } // end of namespace range + maRangeX.expand(rRange.maRangeX); + maRangeY.expand(rRange.maRangeY); + } + }; } // end of namespace basegfx #endif // _BGFX_RANGE_B2DRANGE_HXX diff --git a/basegfx/inc/basegfx/range/b3drange.hxx b/basegfx/inc/basegfx/range/b3drange.hxx index 3d6c3c958d1a..a4d5be99f6ec 100644 --- a/basegfx/inc/basegfx/range/b3drange.hxx +++ b/basegfx/inc/basegfx/range/b3drange.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3drange.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:02 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:56 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,134 +72,131 @@ namespace basegfx { - namespace range + class B3DRange { - class B3DRange + ::basegfx::BasicRange maRangeX; + ::basegfx::BasicRange maRangeY; + ::basegfx::BasicRange maRangeZ; + + public: + B3DRange() + { + } + + B3DRange(const B3DTuple& rTuple) + : maRangeX(rTuple.getX()), + maRangeY(rTuple.getY()), + maRangeZ(rTuple.getZ()) + { + } + + B3DRange(const B3DRange& rRange) + : maRangeX(rRange.maRangeX), + maRangeY(rRange.maRangeY), + maRangeZ(rRange.maRangeZ) + { + } + + sal_Bool isEmpty() const + { + return ( + maRangeX.isEmpty() + || maRangeY.isEmpty() + || maRangeZ.isEmpty() + ); + } + + void reset() + { + maRangeX.reset(); + maRangeY.reset(); + maRangeZ.reset(); + } + + void operator=(const B3DRange& rRange) + { + maRangeX = rRange.maRangeX; + maRangeY = rRange.maRangeY; + maRangeZ = rRange.maRangeZ; + } + + B3DTuple getMinimum() const + { + return B3DTuple( + maRangeX.getMinimum(), + maRangeY.getMinimum(), + maRangeZ.getMinimum() + ); + } + + B3DTuple getMaximum() const + { + return B3DTuple( + maRangeX.getMaximum(), + maRangeY.getMaximum(), + maRangeZ.getMaximum() + ); + } + + B3DTuple getRange() const + { + return B3DTuple( + maRangeX.getRange(), + maRangeY.getRange(), + maRangeZ.getRange() + ); + } + + B3DTuple getCenter() const + { + return B3DTuple( + maRangeX.getCenter(), + maRangeY.getCenter(), + maRangeZ.getCenter() + ); + } + + sal_Bool isInside(const B3DTuple& rTuple) const + { + return ( + maRangeX.isInside(rTuple.getX()) + && maRangeY.isInside(rTuple.getY()) + && maRangeZ.isInside(rTuple.getZ()) + ); + } + + sal_Bool isInside(const B3DRange& rRange) const + { + return ( + maRangeX.isInside(rRange.maRangeX) + && maRangeY.isInside(rRange.maRangeY) + && maRangeZ.isInside(rRange.maRangeZ) + ); + } + + sal_Bool overlaps(const B3DRange& rRange) const + { + return ( + maRangeX.overlaps(rRange.maRangeX) + && maRangeY.overlaps(rRange.maRangeY) + && maRangeZ.overlaps(rRange.maRangeZ) + ); + } + + void expand(const B3DTuple& rTuple) + { + maRangeX.expand(rTuple.getX()); + maRangeY.expand(rTuple.getY()); + maRangeZ.expand(rTuple.getZ()); + } + + void expand(const B3DRange& rRange) { - ::basegfx::range::BasicRange maRangeX; - ::basegfx::range::BasicRange maRangeY; - ::basegfx::range::BasicRange maRangeZ; - - public: - B3DRange() - { - } - - B3DRange(const tuple::B3DTuple& rTuple) - : maRangeX(rTuple.getX()), - maRangeY(rTuple.getY()), - maRangeZ(rTuple.getZ()) - { - } - - B3DRange(const B3DRange& rRange) - : maRangeX(rRange.maRangeX), - maRangeY(rRange.maRangeY), - maRangeZ(rRange.maRangeZ) - { - } - - sal_Bool isEmpty() const - { - return ( - maRangeX.isEmpty() - || maRangeY.isEmpty() - || maRangeZ.isEmpty() - ); - } - - void reset() - { - maRangeX.reset(); - maRangeY.reset(); - maRangeZ.reset(); - } - - void operator=(const B3DRange& rRange) - { - maRangeX = rRange.maRangeX; - maRangeY = rRange.maRangeY; - maRangeZ = rRange.maRangeZ; - } - - tuple::B3DTuple getMinimum() const - { - return tuple::B3DTuple( - maRangeX.getMinimum(), - maRangeY.getMinimum(), - maRangeZ.getMinimum() - ); - } - - tuple::B3DTuple getMaximum() const - { - return tuple::B3DTuple( - maRangeX.getMaximum(), - maRangeY.getMaximum(), - maRangeZ.getMaximum() - ); - } - - tuple::B3DTuple getRange() const - { - return tuple::B3DTuple( - maRangeX.getRange(), - maRangeY.getRange(), - maRangeZ.getRange() - ); - } - - tuple::B3DTuple getCenter() const - { - return tuple::B3DTuple( - maRangeX.getCenter(), - maRangeY.getCenter(), - maRangeZ.getCenter() - ); - } - - sal_Bool isInside(const tuple::B3DTuple& rTuple) const - { - return ( - maRangeX.isInside(rTuple.getX()) - && maRangeY.isInside(rTuple.getY()) - && maRangeZ.isInside(rTuple.getZ()) - ); - } - - sal_Bool isInside(const B3DRange& rRange) const - { - return ( - maRangeX.isInside(rRange.maRangeX) - && maRangeY.isInside(rRange.maRangeY) - && maRangeZ.isInside(rRange.maRangeZ) - ); - } - - sal_Bool overlaps(const B3DRange& rRange) const - { - return ( - maRangeX.overlaps(rRange.maRangeX) - && maRangeY.overlaps(rRange.maRangeY) - && maRangeZ.overlaps(rRange.maRangeZ) - ); - } - - void expand(const tuple::B3DTuple& rTuple) - { - maRangeX.expand(rTuple.getX()); - maRangeY.expand(rTuple.getY()); - maRangeZ.expand(rTuple.getZ()); - } - - void expand(const B3DRange& rRange) - { - maRangeX.expand(rRange.maRangeX); - maRangeY.expand(rRange.maRangeY); - maRangeZ.expand(rRange.maRangeZ); - } - }; - } // end of namespace range + maRangeX.expand(rRange.maRangeX); + maRangeY.expand(rRange.maRangeY); + maRangeZ.expand(rRange.maRangeZ); + } + }; } // end of namespace basegfx #endif // _BGFX_RANGE_B3DRANGE_HXX diff --git a/basegfx/inc/basegfx/range/basicrange.hxx b/basegfx/inc/basegfx/range/basicrange.hxx index 700f2b17add4..732a95abcf70 100644 --- a/basegfx/inc/basegfx/range/basicrange.hxx +++ b/basegfx/inc/basegfx/range/basicrange.hxx @@ -2,9 +2,9 @@ * * $RCSfile: basicrange.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:30:28 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:56 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,103 +75,100 @@ namespace basegfx { - namespace range + class BasicRange { - class BasicRange + protected: + double mfMinimum; + double mfMaximum; + + public: + void reset() { - protected: - double mfMinimum; - double mfMaximum; + mfMinimum = START_MINIMUM_VALUE; + mfMaximum = START_MAXIMUM_VALUE; + } - public: - void reset() - { - mfMinimum = START_MINIMUM_VALUE; - mfMaximum = START_MAXIMUM_VALUE; - } + sal_Bool isEmpty() const + { + return sal_Bool(START_MINIMUM_VALUE == mfMinimum && START_MAXIMUM_VALUE == mfMaximum); + } - sal_Bool isEmpty() const - { - return sal_Bool(START_MINIMUM_VALUE == mfMinimum && START_MAXIMUM_VALUE == mfMaximum); - } + double getMinimum() const { return mfMinimum; } + double getMaximum() const { return mfMaximum; } - double getMinimum() const { return mfMinimum; } - double getMaximum() const { return mfMaximum; } + double getRange() const + { + return (mfMaximum - mfMinimum); + } - double getRange() const - { - return (mfMaximum - mfMinimum); - } + double getCenter() const + { + return ((mfMaximum + mfMinimum) / 2.0); + } - double getCenter() const - { - return ((mfMaximum + mfMinimum) / 2.0); - } + sal_Bool isInside(double fValue) const + { + return sal_Bool((fValue >= mfMinimum) && (fValue <= mfMaximum)); + } - sal_Bool isInside(double fValue) const - { - return sal_Bool((fValue >= mfMinimum) && (fValue <= mfMaximum)); - } + sal_Bool isInside(const BasicRange& rRange) const + { + return sal_Bool((rRange.getMinimum() >= mfMinimum) && (rRange.getMaximum() <= mfMaximum)); + } - sal_Bool isInside(const BasicRange& rRange) const - { - return sal_Bool((rRange.getMinimum() >= mfMinimum) && (rRange.getMaximum() <= mfMaximum)); - } + sal_Bool overlaps(const BasicRange& rRange) const + { + return !sal_Bool((rRange.getMaximum() < mfMinimum) || (rRange.getMinimum() > mfMaximum)); + } - sal_Bool overlaps(const BasicRange& rRange) const - { - return !sal_Bool((rRange.getMaximum() < mfMinimum) || (rRange.getMinimum() > mfMaximum)); - } + BasicRange() + : mfMinimum(START_MINIMUM_VALUE), + mfMaximum(START_MAXIMUM_VALUE) + { + } + BasicRange(double fStartValue) + : mfMinimum(fStartValue), + mfMaximum(fStartValue) + { + } + BasicRange(const BasicRange& rRange) + : mfMinimum(rRange.getMinimum()), + mfMaximum(rRange.getMaximum()) + { + } - BasicRange() - : mfMinimum(START_MINIMUM_VALUE), - mfMaximum(START_MAXIMUM_VALUE) - { - } - BasicRange(double fStartValue) - : mfMinimum(fStartValue), - mfMaximum(fStartValue) - { - } - BasicRange(const BasicRange& rRange) - : mfMinimum(rRange.getMinimum()), - mfMaximum(rRange.getMaximum()) + void operator=(const BasicRange& rRange) + { + mfMinimum = rRange.getMinimum(); + mfMaximum = rRange.getMaximum(); + } + + void expand(double fValue) + { + if(fValue < mfMinimum) { + mfMinimum = fValue; } - void operator=(const BasicRange& rRange) + if(fValue > mfMaximum) { - mfMinimum = rRange.getMinimum(); - mfMaximum = rRange.getMaximum(); + mfMaximum = fValue; } + } - void expand(double fValue) + void expand(const BasicRange& rRange) + { + if(rRange.getMinimum() < mfMinimum) { - if(fValue < mfMinimum) - { - mfMinimum = fValue; - } - - if(fValue > mfMaximum) - { - mfMaximum = fValue; - } + mfMinimum = rRange.getMinimum(); } - void expand(const BasicRange& rRange) + if(rRange.getMaximum() > mfMaximum) { - if(rRange.getMinimum() < mfMinimum) - { - mfMinimum = rRange.getMinimum(); - } - - if(rRange.getMaximum() > mfMaximum) - { - mfMaximum = rRange.getMaximum(); - } + mfMaximum = rRange.getMaximum(); } - }; - } // end of namespace range + } + }; } // end of namespace basegfx #endif _BGFX_RANGE_BASICRANGE_HXX diff --git a/basegfx/inc/basegfx/tuple/b2dtuple.hxx b/basegfx/inc/basegfx/tuple/b2dtuple.hxx index dd775d8c399e..4f555481c2c2 100644 --- a/basegfx/inc/basegfx/tuple/b2dtuple.hxx +++ b/basegfx/inc/basegfx/tuple/b2dtuple.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dtuple.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-10 11:45:48 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,301 +72,298 @@ namespace basegfx { - namespace tuple + /** Base class for all Points/Vectors with two double values + + This class provides all methods common to Point + avd Vector classes which are derived from here. + + @derive Use this class to implement Points or Vectors + which are based on two double values + */ + class B2DTuple { - /** Base class for all Points/Vectors with two double values + private: + static B2DTuple maEmptyTuple; + + protected: + double mfX; + double mfY; + + public: + /** Create a 2D Tuple + + @param fVal + This parameter is used to initialize the coordinate + part of the 2D Tuple. + */ + B2DTuple(double fVal = 0.0) + : mfX(fVal), + mfY(fVal) + {} + + /** Create a 2D Tuple - This class provides all methods common to Point - avd Vector classes which are derived from here. + @param fX + This parameter is used to initialize the X-coordinate + of the 2D Tuple. - @derive Use this class to implement Points or Vectors - which are based on two double values + @param fY + This parameter is used to initialize the Y-coordinate + of the 2D Tuple. */ - class B2DTuple + B2DTuple(double fX, double fY) + : mfX( fX ), + mfY( fY ) + {} + + /** Create a copy of a 2D Tuple + + @param rTup + The 2D Tuple which will be copied. + */ + B2DTuple(const B2DTuple& rTup) + : mfX( rTup.mfX ), + mfY( rTup.mfY ) + {} + + ~B2DTuple() + {} + + /// Get X-Coordinate of 2D Tuple + double getX() const + { + return mfX; + } + + /// Get Y-Coordinate of 2D Tuple + double getY() const { - private: - static B2DTuple maEmptyTuple; - - protected: - double mfX; - double mfY; - - public: - /** Create a 2D Tuple - - @param fVal - This parameter is used to initialize the coordinate - part of the 2D Tuple. - */ - B2DTuple(double fVal = 0.0) - : mfX(fVal), - mfY(fVal) - {} - - /** Create a 2D Tuple - - @param fX - This parameter is used to initialize the X-coordinate - of the 2D Tuple. - - @param fY - This parameter is used to initialize the Y-coordinate - of the 2D Tuple. - */ - B2DTuple(double fX, double fY) - : mfX( fX ), - mfY( fY ) - {} - - /** Create a copy of a 2D Tuple - - @param rTup - The 2D Tuple which will be copied. - */ - B2DTuple(const B2DTuple& rTup) - : mfX( rTup.mfX ), - mfY( rTup.mfY ) - {} - - ~B2DTuple() - {} - - /// Get X-Coordinate of 2D Tuple - double getX() const - { - return mfX; - } - - /// Get Y-Coordinate of 2D Tuple - double getY() const - { - return mfY; - } - - /// Set X-Coordinate of 2D Tuple - void setX(double fX) - { - mfX = fX; - } - - /// Set Y-Coordinate of 2D Tuple - void setY(double fY) - { - mfY = fY; - } - - /// Array-access to 2D Tuple - const double& operator[] (int nPos) const - { - // Here, normally one if(...) should be used. In the assumption that - // both double members can be accessed as an array a shortcut is used here. - // if(0 == nPos) return mfX; return mfY; - return *((&mfX) + nPos); - } - - /// Array-access to 2D Tuple - double& operator[] (int nPos) - { - // Here, normally one if(...) should be used. In the assumption that - // both double members can be accessed as an array a shortcut is used here. - // if(0 == nPos) return mfX; return mfY; - return *((&mfX) + nPos); - } - - // comparators with tolerance - ////////////////////////////////////////////////////////////////////// - - sal_Bool equalZero() const; - - sal_Bool equalZero(const double& rfSmallValue) const; - - sal_Bool equal(const B2DTuple& rTup) const; - - sal_Bool equal(const B2DTuple& rTup, const double& rfSmallValue) const; - - // operators - ////////////////////////////////////////////////////////////////////// - - B2DTuple& operator+=( const B2DTuple& rTup ) - { - mfX += rTup.mfX; - mfY += rTup.mfY; - return *this; - } - - B2DTuple& operator-=( const B2DTuple& rTup ) - { - mfX -= rTup.mfX; - mfY -= rTup.mfY; - return *this; - } - - B2DTuple& operator/=( const B2DTuple& rTup ) - { - mfX /= rTup.mfX; - mfY /= rTup.mfY; - return *this; - } - - B2DTuple& operator*=( const B2DTuple& rTup ) - { - mfX *= rTup.mfX; - mfY *= rTup.mfY; - return *this; - } - - B2DTuple& operator*=(double t) - { - mfX *= t; - mfY *= t; - return *this; - } - - B2DTuple& operator/=(double t) - { - const double fVal(1.0 / t); - mfX *= fVal; - mfY *= fVal; - return *this; - } - - B2DTuple operator-(void) const - { - return B2DTuple(-mfX, -mfY); - } - - sal_Bool operator==( const B2DTuple& rTup ) const - { - return equal(rTup); - } - - sal_Bool operator!=( const B2DTuple& rTup ) const - { - return !equal(rTup); - } - - B2DTuple& operator=( const B2DTuple& rTup ) - { - mfX = rTup.mfX; - mfY = rTup.mfY; - return *this; - } - - void correctValues(const double fCompareValue = 0.0); - - static const B2DTuple& getEmptyTuple() - { - return maEmptyTuple; - } - }; - - // external operators - ////////////////////////////////////////////////////////////////////////// - - inline B2DTuple min(const B2DTuple& rTupA, const B2DTuple& rTupB) + return mfY; + } + + /// Set X-Coordinate of 2D Tuple + void setX(double fX) { - B2DTuple aMin( - (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(), - (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY()); - return aMin; + mfX = fX; } - inline B2DTuple max(const B2DTuple& rTupA, const B2DTuple& rTupB) + /// Set Y-Coordinate of 2D Tuple + void setY(double fY) { - B2DTuple aMax( - (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(), - (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY()); - return aMax; + mfY = fY; } - inline B2DTuple abs(const B2DTuple& rTup) + /// Array-access to 2D Tuple + const double& operator[] (int nPos) const { - B2DTuple aAbs( - (0.0 > rTup.getX()) ? -rTup.getX() : rTup.getX(), - (0.0 > rTup.getY()) ? -rTup.getY() : rTup.getY()); - return aAbs; + // Here, normally one if(...) should be used. In the assumption that + // both double members can be accessed as an array a shortcut is used here. + // if(0 == nPos) return mfX; return mfY; + return *((&mfX) + nPos); } - inline B2DTuple interpolate(const B2DTuple& rOld1, const B2DTuple& rOld2, double t) + /// Array-access to 2D Tuple + double& operator[] (int nPos) + { + // Here, normally one if(...) should be used. In the assumption that + // both double members can be accessed as an array a shortcut is used here. + // if(0 == nPos) return mfX; return mfY; + return *((&mfX) + nPos); + } + + // comparators with tolerance + ////////////////////////////////////////////////////////////////////// + + sal_Bool equalZero() const; + + sal_Bool equalZero(const double& rfSmallValue) const; + + sal_Bool equal(const B2DTuple& rTup) const; + + sal_Bool equal(const B2DTuple& rTup, const double& rfSmallValue) const; + + // operators + ////////////////////////////////////////////////////////////////////// + + B2DTuple& operator+=( const B2DTuple& rTup ) { - B2DTuple aInt( - ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), - ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY()); - return aInt; + mfX += rTup.mfX; + mfY += rTup.mfY; + return *this; } - inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2) + B2DTuple& operator-=( const B2DTuple& rTup ) { - B2DTuple aAvg( - (rOld1.getX() + rOld2.getX()) * 0.5, - (rOld1.getY() + rOld2.getY()) * 0.5); - return aAvg; + mfX -= rTup.mfX; + mfY -= rTup.mfY; + return *this; } - inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2, const B2DTuple& rOld3) + B2DTuple& operator/=( const B2DTuple& rTup ) { - B2DTuple aAvg( - (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), - (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0)); - return aAvg; + mfX /= rTup.mfX; + mfY /= rTup.mfY; + return *this; } - inline B2DTuple operator+(const B2DTuple& rTupA, const B2DTuple& rTupB) + B2DTuple& operator*=( const B2DTuple& rTup ) { - B2DTuple aSum(rTupA); - aSum += rTupB; - return aSum; + mfX *= rTup.mfX; + mfY *= rTup.mfY; + return *this; } - inline B2DTuple operator-(const B2DTuple& rTupA, const B2DTuple& rTupB) + B2DTuple& operator*=(double t) { - B2DTuple aSub(rTupA); - aSub -= rTupB; - return aSub; + mfX *= t; + mfY *= t; + return *this; } - inline B2DTuple operator/(const B2DTuple& rTupA, const B2DTuple& rTupB) + B2DTuple& operator/=(double t) { - B2DTuple aDiv(rTupA); - aDiv /= rTupB; - return aDiv; + const double fVal(1.0 / t); + mfX *= fVal; + mfY *= fVal; + return *this; } - inline B2DTuple operator*(const B2DTuple& rTupA, const B2DTuple& rTupB) + B2DTuple operator-(void) const { - B2DTuple aMul(rTupA); - aMul *= rTupB; - return aMul; + return B2DTuple(-mfX, -mfY); } - inline B2DTuple operator*(const B2DTuple& rTup, double t) + sal_Bool operator==( const B2DTuple& rTup ) const { - B2DTuple aNew(rTup); - aNew *= t; - return aNew; + return equal(rTup); } - inline B2DTuple operator*(double t, const B2DTuple& rTup) + sal_Bool operator!=( const B2DTuple& rTup ) const { - B2DTuple aNew(rTup); - aNew *= t; - return aNew; + return !equal(rTup); } - inline B2DTuple operator/(const B2DTuple& rTup, double t) + B2DTuple& operator=( const B2DTuple& rTup ) { - B2DTuple aNew(rTup); - aNew /= t; - return aNew; + mfX = rTup.mfX; + mfY = rTup.mfY; + return *this; } - inline B2DTuple operator/(double t, const B2DTuple& rTup) + void correctValues(const double fCompareValue = 0.0); + + static const B2DTuple& getEmptyTuple() { - B2DTuple aNew(rTup); - aNew /= t; - return aNew; + return maEmptyTuple; } - } // end of namespace tuple + }; + + // external operators + ////////////////////////////////////////////////////////////////////////// + + inline B2DTuple min(const B2DTuple& rTupA, const B2DTuple& rTupB) + { + B2DTuple aMin( + (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(), + (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY()); + return aMin; + } + + inline B2DTuple max(const B2DTuple& rTupA, const B2DTuple& rTupB) + { + B2DTuple aMax( + (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(), + (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY()); + return aMax; + } + + inline B2DTuple abs(const B2DTuple& rTup) + { + B2DTuple aAbs( + (0.0 > rTup.getX()) ? -rTup.getX() : rTup.getX(), + (0.0 > rTup.getY()) ? -rTup.getY() : rTup.getY()); + return aAbs; + } + + inline B2DTuple interpolate(const B2DTuple& rOld1, const B2DTuple& rOld2, double t) + { + B2DTuple aInt( + ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), + ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY()); + return aInt; + } + + inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2) + { + B2DTuple aAvg( + (rOld1.getX() + rOld2.getX()) * 0.5, + (rOld1.getY() + rOld2.getY()) * 0.5); + return aAvg; + } + + inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2, const B2DTuple& rOld3) + { + B2DTuple aAvg( + (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), + (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0)); + return aAvg; + } + + inline B2DTuple operator+(const B2DTuple& rTupA, const B2DTuple& rTupB) + { + B2DTuple aSum(rTupA); + aSum += rTupB; + return aSum; + } + + inline B2DTuple operator-(const B2DTuple& rTupA, const B2DTuple& rTupB) + { + B2DTuple aSub(rTupA); + aSub -= rTupB; + return aSub; + } + + inline B2DTuple operator/(const B2DTuple& rTupA, const B2DTuple& rTupB) + { + B2DTuple aDiv(rTupA); + aDiv /= rTupB; + return aDiv; + } + + inline B2DTuple operator*(const B2DTuple& rTupA, const B2DTuple& rTupB) + { + B2DTuple aMul(rTupA); + aMul *= rTupB; + return aMul; + } + + inline B2DTuple operator*(const B2DTuple& rTup, double t) + { + B2DTuple aNew(rTup); + aNew *= t; + return aNew; + } + + inline B2DTuple operator*(double t, const B2DTuple& rTup) + { + B2DTuple aNew(rTup); + aNew *= t; + return aNew; + } + + inline B2DTuple operator/(const B2DTuple& rTup, double t) + { + B2DTuple aNew(rTup); + aNew /= t; + return aNew; + } + + inline B2DTuple operator/(double t, const B2DTuple& rTup) + { + B2DTuple aNew(rTup); + aNew /= t; + return aNew; + } } // end of namespace basegfx #endif // _BGFX_TUPLE_B2DTUPLE_HXX diff --git a/basegfx/inc/basegfx/tuple/b3dtuple.hxx b/basegfx/inc/basegfx/tuple/b3dtuple.hxx index 48f1fde48a24..928f1f081855 100644 --- a/basegfx/inc/basegfx/tuple/b3dtuple.hxx +++ b/basegfx/inc/basegfx/tuple/b3dtuple.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dtuple.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:04 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,394 +68,391 @@ namespace basegfx { - namespace tuple - { - /** Base class for all Points/Vectors with three double values - - This class provides all methods common to Point - avd Vector classes which are derived from here. - - @derive Use this class to implement Points or Vectors - which are based on three double values - */ - class B3DTuple - { - private: - static B3DTuple maEmptyTuple; - - protected: - double mfX; - double mfY; - double mfZ; - - public: - /** Create a 3D Tuple - - @param fVal - This parameter is used to initialize the coordinate - part of the 3D Tuple. - */ - B3DTuple(double fVal = 0.0) - : mfX(fVal), - mfY(fVal), - mfZ(fVal) - {} - - /** Create a 3D Tuple - - @param fX - This parameter is used to initialize the X-coordinate - of the 3D Tuple. - - @param fY - This parameter is used to initialize the Y-coordinate - of the 3D Tuple. - - @param fZ - This parameter is used to initialize the Z-coordinate - of the 3D Tuple. - */ - B3DTuple(double fX, double fY, double fZ) - : mfX(fX), - mfY(fY), - mfZ(fZ) - {} - - /** Create a copy of a 3D Tuple - - @param rTup - The 3D Tuple which will be copied. - */ - B3DTuple(const B3DTuple& rTup) - : mfX( rTup.mfX ), - mfY( rTup.mfY ), - mfZ( rTup.mfZ ) - {} - - ~B3DTuple() - {} - - /// get X-Coordinate of 3D Tuple - double getX() const - { - return mfX; - } - - /// get Y-Coordinate of 3D Tuple - double getY() const - { - return mfY; - } - - /// get Z-Coordinate of 3D Tuple - double getZ() const - { - return mfZ; - } - - /// set X-Coordinate of 3D Tuple - void setX(double fX) - { - mfX = fX; - } + /** Base class for all Points/Vectors with three double values - /// set Y-Coordinate of 3D Tuple - void setY(double fY) - { - mfY = fY; - } + This class provides all methods common to Point + avd Vector classes which are derived from here. - /// set Z-Coordinate of 3D Tuple - void setZ(double fZ) - { - mfZ = fZ; - } + @derive Use this class to implement Points or Vectors + which are based on three double values + */ + class B3DTuple + { + private: + static B3DTuple maEmptyTuple; - /// Array-access to 3D Tuple - const double& operator[] (int nPos) const - { - // Here, normally two if(...)'s should be used. In the assumption that - // both double members can be accessed as an array a shortcut is used here. - // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ; - return *((&mfX) + nPos); - } + protected: + double mfX; + double mfY; + double mfZ; - /// Array-access to 3D Tuple - double& operator[] (int nPos) - { - // Here, normally two if(...)'s should be used. In the assumption that - // both double members can be accessed as an array a shortcut is used here. - // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ; - return *((&mfX) + nPos); - } + public: + /** Create a 3D Tuple - // comparators with tolerance - ////////////////////////////////////////////////////////////////////// + @param fVal + This parameter is used to initialize the coordinate + part of the 3D Tuple. + */ + B3DTuple(double fVal = 0.0) + : mfX(fVal), + mfY(fVal), + mfZ(fVal) + {} - sal_Bool equalZero() const - { - return (this == &maEmptyTuple || - (::basegfx::numeric::fTools::equalZero(mfX) - && ::basegfx::numeric::fTools::equalZero(mfY) - && ::basegfx::numeric::fTools::equalZero(mfZ))); - } + /** Create a 3D Tuple - sal_Bool equalZero(const double& rfSmallValue) const - { - return (this == &maEmptyTuple || - (::basegfx::numeric::fTools::equalZero(mfX, rfSmallValue) - && ::basegfx::numeric::fTools::equalZero(mfY, rfSmallValue) - && ::basegfx::numeric::fTools::equalZero(mfZ, rfSmallValue))); - } + @param fX + This parameter is used to initialize the X-coordinate + of the 3D Tuple. - sal_Bool equal(const B3DTuple& rTup) const - { - return ( - ::basegfx::numeric::fTools::equal(mfX, rTup.mfX) && - ::basegfx::numeric::fTools::equal(mfY, rTup.mfY) && - ::basegfx::numeric::fTools::equal(mfZ, rTup.mfZ)); - } + @param fY + This parameter is used to initialize the Y-coordinate + of the 3D Tuple. - sal_Bool equal(const B3DTuple& rTup, const double& rfSmallValue) const - { - return ( - ::basegfx::numeric::fTools::equal(mfX, rTup.mfX, rfSmallValue) && - ::basegfx::numeric::fTools::equal(mfY, rTup.mfY, rfSmallValue) && - ::basegfx::numeric::fTools::equal(mfZ, rTup.mfZ, rfSmallValue)); - } + @param fZ + This parameter is used to initialize the Z-coordinate + of the 3D Tuple. + */ + B3DTuple(double fX, double fY, double fZ) + : mfX(fX), + mfY(fY), + mfZ(fZ) + {} - // operators - ////////////////////////////////////////////////////////////////////// + /** Create a copy of a 3D Tuple - B3DTuple& operator+=( const B3DTuple& rTup ) - { - mfX += rTup.mfX; - mfY += rTup.mfY; - mfZ += rTup.mfZ; - return *this; - } + @param rTup + The 3D Tuple which will be copied. + */ + B3DTuple(const B3DTuple& rTup) + : mfX( rTup.mfX ), + mfY( rTup.mfY ), + mfZ( rTup.mfZ ) + {} - B3DTuple& operator-=( const B3DTuple& rTup ) - { - mfX -= rTup.mfX; - mfY -= rTup.mfY; - mfZ -= rTup.mfZ; - return *this; - } + ~B3DTuple() + {} - B3DTuple& operator/=( const B3DTuple& rTup ) - { - mfX /= rTup.mfX; - mfY /= rTup.mfY; - mfZ /= rTup.mfZ; - return *this; - } + /// get X-Coordinate of 3D Tuple + double getX() const + { + return mfX; + } - B3DTuple& operator*=( const B3DTuple& rTup ) - { - mfX *= rTup.mfX; - mfY *= rTup.mfY; - mfZ *= rTup.mfZ; - return *this; - } + /// get Y-Coordinate of 3D Tuple + double getY() const + { + return mfY; + } - B3DTuple& operator*=(double t) - { - mfX *= t; - mfY *= t; - mfZ *= t; - return *this; - } + /// get Z-Coordinate of 3D Tuple + double getZ() const + { + return mfZ; + } - B3DTuple& operator/=(double t) - { - const double fVal(1.0 / t); - mfX *= t; - mfY *= t; - mfZ *= t; - return *this; - } + /// set X-Coordinate of 3D Tuple + void setX(double fX) + { + mfX = fX; + } - B3DTuple operator-(void) const - { - return B3DTuple(-mfX, -mfY, -mfZ); - } + /// set Y-Coordinate of 3D Tuple + void setY(double fY) + { + mfY = fY; + } - sal_Bool operator==( const B3DTuple& rTup ) const - { - return equal(rTup); - } + /// set Z-Coordinate of 3D Tuple + void setZ(double fZ) + { + mfZ = fZ; + } - sal_Bool operator!=( const B3DTuple& rTup ) const - { - return !equal(rTup); - } + /// Array-access to 3D Tuple + const double& operator[] (int nPos) const + { + // Here, normally two if(...)'s should be used. In the assumption that + // both double members can be accessed as an array a shortcut is used here. + // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ; + return *((&mfX) + nPos); + } - B3DTuple& operator=( const B3DTuple& rTup ) - { - mfX = rTup.mfX; - mfY = rTup.mfY; - mfZ = rTup.mfZ; - return *this; - } + /// Array-access to 3D Tuple + double& operator[] (int nPos) + { + // Here, normally two if(...)'s should be used. In the assumption that + // both double members can be accessed as an array a shortcut is used here. + // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ; + return *((&mfX) + nPos); + } - void correctValues(const double fCompareValue = 0.0) - { - if(0.0 == fCompareValue) - { - if(::basegfx::numeric::fTools::equalZero(mfX)) - { - mfX = 0.0; - } - - if(::basegfx::numeric::fTools::equalZero(mfY)) - { - mfY = 0.0; - } - - if(::basegfx::numeric::fTools::equalZero(mfZ)) - { - mfZ = 0.0; - } - } - else - { - if(::basegfx::numeric::fTools::equal(mfX, fCompareValue)) - { - mfX = fCompareValue; - } - - if(::basegfx::numeric::fTools::equal(mfY, fCompareValue)) - { - mfY = fCompareValue; - } - - if(::basegfx::numeric::fTools::equal(mfZ, fCompareValue)) - { - mfZ = fCompareValue; - } - } - } + // comparators with tolerance + ////////////////////////////////////////////////////////////////////// - static const B3DTuple& getEmptyTuple() - { - return maEmptyTuple; - } - }; + sal_Bool equalZero() const + { + return (this == &maEmptyTuple || + (::basegfx::fTools::equalZero(mfX) + && ::basegfx::fTools::equalZero(mfY) + && ::basegfx::fTools::equalZero(mfZ))); + } - // external operators - ////////////////////////////////////////////////////////////////////////// + sal_Bool equalZero(const double& rfSmallValue) const + { + return (this == &maEmptyTuple || + (::basegfx::fTools::equalZero(mfX, rfSmallValue) + && ::basegfx::fTools::equalZero(mfY, rfSmallValue) + && ::basegfx::fTools::equalZero(mfZ, rfSmallValue))); + } - inline B3DTuple min(const B3DTuple& rTupA, const B3DTuple& rTupB) + sal_Bool equal(const B3DTuple& rTup) const { - B3DTuple aMin( - (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(), - (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY(), - (rTupB.getZ() < rTupA.getZ()) ? rTupB.getZ() : rTupA.getZ()); - return aMin; + return ( + ::basegfx::fTools::equal(mfX, rTup.mfX) && + ::basegfx::fTools::equal(mfY, rTup.mfY) && + ::basegfx::fTools::equal(mfZ, rTup.mfZ)); } - inline B3DTuple max(const B3DTuple& rTupA, const B3DTuple& rTupB) + sal_Bool equal(const B3DTuple& rTup, const double& rfSmallValue) const { - B3DTuple aMax( - (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(), - (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY(), - (rTupB.getZ() > rTupA.getZ()) ? rTupB.getZ() : rTupA.getZ()); - return aMax; + return ( + ::basegfx::fTools::equal(mfX, rTup.mfX, rfSmallValue) && + ::basegfx::fTools::equal(mfY, rTup.mfY, rfSmallValue) && + ::basegfx::fTools::equal(mfZ, rTup.mfZ, rfSmallValue)); } - inline B3DTuple abs(const B3DTuple& rTup) + // operators + ////////////////////////////////////////////////////////////////////// + + B3DTuple& operator+=( const B3DTuple& rTup ) { - B3DTuple aAbs( - (0.0 > rTup.getX()) ? -rTup.getX() : rTup.getX(), - (0.0 > rTup.getY()) ? -rTup.getY() : rTup.getY(), - (0.0 > rTup.getZ()) ? -rTup.getZ() : rTup.getZ()); - return aAbs; + mfX += rTup.mfX; + mfY += rTup.mfY; + mfZ += rTup.mfZ; + return *this; } - inline B3DTuple interpolate(const B3DTuple& rOld1, const B3DTuple& rOld2, double t) + B3DTuple& operator-=( const B3DTuple& rTup ) { - B3DTuple aInt( - ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), - ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(), - ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ()); - return aInt; + mfX -= rTup.mfX; + mfY -= rTup.mfY; + mfZ -= rTup.mfZ; + return *this; } - inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2) + B3DTuple& operator/=( const B3DTuple& rTup ) { - B3DTuple aAvg( - (rOld1.getX() + rOld2.getX()) * 0.5, - (rOld1.getY() + rOld2.getY()) * 0.5, - (rOld1.getZ() + rOld2.getZ()) * 0.5); - return aAvg; + mfX /= rTup.mfX; + mfY /= rTup.mfY; + mfZ /= rTup.mfZ; + return *this; } - inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2, const B3DTuple& rOld3) + B3DTuple& operator*=( const B3DTuple& rTup ) { - B3DTuple aAvg( - (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), - (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0), - (rOld1.getZ() + rOld2.getZ() + rOld3.getZ()) * (1.0 / 3.0)); - return aAvg; + mfX *= rTup.mfX; + mfY *= rTup.mfY; + mfZ *= rTup.mfZ; + return *this; } - inline B3DTuple operator+(const B3DTuple& rTupA, const B3DTuple& rTupB) + B3DTuple& operator*=(double t) { - B3DTuple aSum(rTupA); - aSum += rTupB; - return aSum; + mfX *= t; + mfY *= t; + mfZ *= t; + return *this; } - inline B3DTuple operator-(const B3DTuple& rTupA, const B3DTuple& rTupB) + B3DTuple& operator/=(double t) { - B3DTuple aSub(rTupA); - aSub -= rTupB; - return aSub; + const double fVal(1.0 / t); + mfX *= t; + mfY *= t; + mfZ *= t; + return *this; } - inline B3DTuple operator/(const B3DTuple& rTupA, const B3DTuple& rTupB) + B3DTuple operator-(void) const { - B3DTuple aDiv(rTupA); - aDiv /= rTupB; - return aDiv; + return B3DTuple(-mfX, -mfY, -mfZ); } - inline B3DTuple operator*(const B3DTuple& rTupA, const B3DTuple& rTupB) + sal_Bool operator==( const B3DTuple& rTup ) const { - B3DTuple aMul(rTupA); - aMul *= rTupB; - return aMul; + return equal(rTup); } - inline B3DTuple operator*(const B3DTuple& rTup, double t) + sal_Bool operator!=( const B3DTuple& rTup ) const { - B3DTuple aNew(rTup); - aNew *= t; - return aNew; + return !equal(rTup); } - inline B3DTuple operator*(double t, const B3DTuple& rTup) + B3DTuple& operator=( const B3DTuple& rTup ) { - B3DTuple aNew(rTup); - aNew *= t; - return aNew; + mfX = rTup.mfX; + mfY = rTup.mfY; + mfZ = rTup.mfZ; + return *this; } - inline B3DTuple operator/(const B3DTuple& rTup, double t) + void correctValues(const double fCompareValue = 0.0) { - B3DTuple aNew(rTup); - aNew /= t; - return aNew; + if(0.0 == fCompareValue) + { + if(::basegfx::fTools::equalZero(mfX)) + { + mfX = 0.0; + } + + if(::basegfx::fTools::equalZero(mfY)) + { + mfY = 0.0; + } + + if(::basegfx::fTools::equalZero(mfZ)) + { + mfZ = 0.0; + } + } + else + { + if(::basegfx::fTools::equal(mfX, fCompareValue)) + { + mfX = fCompareValue; + } + + if(::basegfx::fTools::equal(mfY, fCompareValue)) + { + mfY = fCompareValue; + } + + if(::basegfx::fTools::equal(mfZ, fCompareValue)) + { + mfZ = fCompareValue; + } + } } - inline B3DTuple operator/(double t, const B3DTuple& rTup) + static const B3DTuple& getEmptyTuple() { - B3DTuple aNew(rTup); - aNew /= t; - return aNew; + return maEmptyTuple; } - } // end of namespace tuple + }; + + // external operators + ////////////////////////////////////////////////////////////////////////// + + inline B3DTuple min(const B3DTuple& rTupA, const B3DTuple& rTupB) + { + B3DTuple aMin( + (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(), + (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY(), + (rTupB.getZ() < rTupA.getZ()) ? rTupB.getZ() : rTupA.getZ()); + return aMin; + } + + inline B3DTuple max(const B3DTuple& rTupA, const B3DTuple& rTupB) + { + B3DTuple aMax( + (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(), + (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY(), + (rTupB.getZ() > rTupA.getZ()) ? rTupB.getZ() : rTupA.getZ()); + return aMax; + } + + inline B3DTuple abs(const B3DTuple& rTup) + { + B3DTuple aAbs( + (0.0 > rTup.getX()) ? -rTup.getX() : rTup.getX(), + (0.0 > rTup.getY()) ? -rTup.getY() : rTup.getY(), + (0.0 > rTup.getZ()) ? -rTup.getZ() : rTup.getZ()); + return aAbs; + } + + inline B3DTuple interpolate(const B3DTuple& rOld1, const B3DTuple& rOld2, double t) + { + B3DTuple aInt( + ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), + ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(), + ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ()); + return aInt; + } + + inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2) + { + B3DTuple aAvg( + (rOld1.getX() + rOld2.getX()) * 0.5, + (rOld1.getY() + rOld2.getY()) * 0.5, + (rOld1.getZ() + rOld2.getZ()) * 0.5); + return aAvg; + } + + inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2, const B3DTuple& rOld3) + { + B3DTuple aAvg( + (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), + (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0), + (rOld1.getZ() + rOld2.getZ() + rOld3.getZ()) * (1.0 / 3.0)); + return aAvg; + } + + inline B3DTuple operator+(const B3DTuple& rTupA, const B3DTuple& rTupB) + { + B3DTuple aSum(rTupA); + aSum += rTupB; + return aSum; + } + + inline B3DTuple operator-(const B3DTuple& rTupA, const B3DTuple& rTupB) + { + B3DTuple aSub(rTupA); + aSub -= rTupB; + return aSub; + } + + inline B3DTuple operator/(const B3DTuple& rTupA, const B3DTuple& rTupB) + { + B3DTuple aDiv(rTupA); + aDiv /= rTupB; + return aDiv; + } + + inline B3DTuple operator*(const B3DTuple& rTupA, const B3DTuple& rTupB) + { + B3DTuple aMul(rTupA); + aMul *= rTupB; + return aMul; + } + + inline B3DTuple operator*(const B3DTuple& rTup, double t) + { + B3DTuple aNew(rTup); + aNew *= t; + return aNew; + } + + inline B3DTuple operator*(double t, const B3DTuple& rTup) + { + B3DTuple aNew(rTup); + aNew *= t; + return aNew; + } + + inline B3DTuple operator/(const B3DTuple& rTup, double t) + { + B3DTuple aNew(rTup); + aNew /= t; + return aNew; + } + + inline B3DTuple operator/(double t, const B3DTuple& rTup) + { + B3DTuple aNew(rTup); + aNew /= t; + return aNew; + } } // end of namespace basegfx #endif // _BGFX_TUPLE_B3DTUPLE_HXX diff --git a/basegfx/inc/basegfx/vector/b2dvector.hxx b/basegfx/inc/basegfx/vector/b2dvector.hxx index f35c38bb3236..6b5fe724b3e9 100644 --- a/basegfx/inc/basegfx/vector/b2dvector.hxx +++ b/basegfx/inc/basegfx/vector/b2dvector.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dvector.hxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:05 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:58 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,250 +68,244 @@ namespace basegfx { - namespace matrix + // predeclaration + class B2DHomMatrix; + + /** Descriptor for the mathematical orientations of two 2D Vectors + */ + enum B2DVectorOrientation + { + /// mathematically positive oriented + ORIENTATION_POSITIVE = 0, + + /// mathematically negative oriented + ORIENTATION_NEGATIVE, + + /// mathematically neutral, thus parallel + ORIENTATION_NEUTRAL + }; + + /** Descriptor for the mathematical continuity of two 2D Vectors + */ + enum B2DVectorContinuity { - // predeclaration - class B2DHomMatrix; - } // end of namespace matrix; + /// none + CONTINUITY_NONE = 0, + + /// mathematically negative oriented + CONTINUITY_C1, - namespace vector + /// mathematically neutral, thus parallel + CONTINUITY_C2 + }; + + /** Base Point class with two double values + + This class derives all operators and common handling for + a 2D data class from B2DTuple. All necessary extensions + which are special for 2D Vectors are added here. + + @see B2DTuple + */ + class B2DVector : public ::basegfx::B2DTuple { - /** Descriptor for the mathematical orientations of two 2D Vectors + public: + /** Create a 2D Vector + + @param fVal + This parameter is used to initialize the coordinate + part of the 2D Vector. */ - enum B2DVectorOrientation - { - /// mathematically positive oriented - ORIENTATION_POSITIVE = 0, + B2DVector(double fVal = 0.0) + : B2DTuple(fVal) + {} - /// mathematically negative oriented - ORIENTATION_NEGATIVE, + /** Create a 2D Vector - /// mathematically neutral, thus parallel - ORIENTATION_NEUTRAL - }; + @param fX + This parameter is used to initialize the X-coordinate + of the 2D Vector. - /** Descriptor for the mathematical continuity of two 2D Vectors + @param fY + This parameter is used to initialize the Y-coordinate + of the 2D Vector. */ - enum B2DVectorContinuity - { - /// none - CONTINUITY_NONE = 0, + B2DVector(double fX, double fY) + : B2DTuple(fX, fY) + {} - /// mathematically negative oriented - CONTINUITY_C1, + /** Create a copy of a 2D Vector - /// mathematically neutral, thus parallel - CONTINUITY_C2 - }; + @param rVec + The 2D Vector which will be copied. + */ + B2DVector(const B2DVector& rVec) + : B2DTuple(rVec) + {} - /** Base Point class with two double values + /** constructor with tuple to allow copy-constructing + from B2DTuple-based classes + */ + B2DVector(const ::basegfx::B2DTuple& rTuple) + : B2DTuple(rTuple) + {} - This class derives all operators and common handling for - a 2D data class from B2DTuple. All necessary extensions - which are special for 2D Vectors are added here. + ~B2DVector() + {} - @see B2DTuple + /** *=operator to allow usage from B2DVector, too */ - class B2DVector : public ::basegfx::tuple::B2DTuple + B2DVector& operator*=( const B2DVector& rPnt ) { - public: - /** Create a 2D Vector - - @param fVal - This parameter is used to initialize the coordinate - part of the 2D Vector. - */ - B2DVector(double fVal = 0.0) - : B2DTuple(fVal) - {} - - /** Create a 2D Vector - - @param fX - This parameter is used to initialize the X-coordinate - of the 2D Vector. - - @param fY - This parameter is used to initialize the Y-coordinate - of the 2D Vector. - */ - B2DVector(double fX, double fY) - : B2DTuple(fX, fY) - {} - - /** Create a copy of a 2D Vector - - @param rVec - The 2D Vector which will be copied. - */ - B2DVector(const B2DVector& rVec) - : B2DTuple(rVec) - {} - - /** constructor with tuple to allow copy-constructing - from B2DTuple-based classes - */ - B2DVector(const ::basegfx::tuple::B2DTuple& rTuple) - : B2DTuple(rTuple) - {} - - ~B2DVector() - {} - - /** *=operator to allow usage from B2DVector, too - */ - B2DVector& operator*=( const B2DVector& rPnt ) - { - mfX *= rPnt.mfX; - mfY *= rPnt.mfY; - return *this; - } - - /** *=operator to allow usage from B2DVector, too - */ - B2DVector& operator*=(double t) - { - mfX *= t; - mfY *= t; - return *this; - } - - /** assignment operator to allow assigning the results - of B2DTuple calculations - */ - B2DVector& operator=( const ::basegfx::tuple::B2DTuple& rVec ); - - /** Calculate the length of this 2D Vector - - @return The Length of the 2D Vector - */ - double getLength() const; - - /** Set the length of this 2D Vector - - @param fLen - The to be achieved length of the 2D Vector - */ - B2DVector& setLength(double fLen); - - /** Normalize this 2D Vector - - The length of the 2D Vector is set to 1.0 - */ - B2DVector& normalize(); - - /** Test if this 2D Vector is normalized - - @return - sal_True if lenth of vector is equal to 1.0 - sal_False else - */ - sal_Bool isNormalized() const; - - /** Calculate the Scalar with another 2D Vector - - @param rVec - The second 2D Vector - - @return - The Scalar value of the two involved 2D Vectors - */ - double scalar( const B2DVector& rVec ) const; - - /** Calculate the length of the cross product with another 2D Vector - - In 2D, returning an actual vector does not make much - sense here. The magnitude, although, can be readily - used for tasks such as angle calculations, since for - the returned value, the following equation holds: - retVal = getLength(this)*getLength(rVec)*sin(theta), - with theta being the angle between the two vectors. + mfX *= rPnt.mfX; + mfY *= rPnt.mfY; + return *this; + } - @param rVec - The second 2D Vector + /** *=operator to allow usage from B2DVector, too + */ + B2DVector& operator*=(double t) + { + mfX *= t; + mfY *= t; + return *this; + } - @return - The length of the cross product of the two involved 2D Vectors - */ - double cross( const B2DVector& rVec ) const; + /** assignment operator to allow assigning the results + of B2DTuple calculations + */ + B2DVector& operator=( const ::basegfx::B2DTuple& rVec ); - /** Calculate the Angle with another 2D Vector + /** Calculate the length of this 2D Vector - @param rVec - The second 2D Vector + @return The Length of the 2D Vector + */ + double getLength() const; - @return - The Angle value of the two involved 2D Vectors in -pi/2 < return < pi/2 - */ - double angle( const B2DVector& rVec ) const; + /** Set the length of this 2D Vector - /** Transform vector by given transformation matrix. + @param fLen + The to be achieved length of the 2D Vector + */ + B2DVector& setLength(double fLen); - Since this is a vector, translational components of the - matrix are disregarded. - */ - B2DVector& operator*=( const matrix::B2DHomMatrix& rMat ); + /** Normalize this 2D Vector - static const B2DVector& getEmptyVector(); - }; + The length of the 2D Vector is set to 1.0 + */ + B2DVector& normalize(); - // external operators - ////////////////////////////////////////////////////////////////////////// + /** Test if this 2D Vector is normalized - /** Calculate the orientation to another 2D Vector + @return + sal_True if lenth of vector is equal to 1.0 + sal_False else + */ + sal_Bool isNormalized() const; - @param rVecA - The first 2D Vector + /** Calculate the Scalar with another 2D Vector - @param rVecB + @param rVec The second 2D Vector @return - The mathematical Orientation of the two involved 2D Vectors + The Scalar value of the two involved 2D Vectors */ - B2DVectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB ); + double scalar( const B2DVector& rVec ) const; - /** Calculate a perpendicular 2D Vector to the given one + /** Calculate the length of the cross product with another 2D Vector - @param rVec - The source 2D Vector + In 2D, returning an actual vector does not make much + sense here. The magnitude, although, can be readily + used for tasks such as angle calculations, since for + the returned value, the following equation holds: + retVal = getLength(this)*getLength(rVec)*sin(theta), + with theta being the angle between the two vectors. - @attention This only works if the given 2D Vector is normalized. + @param rVec + The second 2D Vector @return - A 2D Vector perpendicular to the one given in parameter rVec + The length of the cross product of the two involved 2D Vectors */ - B2DVector getPerpendicular( const B2DVector& rNormalizedVec ); - - /** Test two vectors which need not to be normalized for parallelism + double cross( const B2DVector& rVec ) const; - @param rVecA - The first 2D Vector + /** Calculate the Angle with another 2D Vector - @param rVecB + @param rVec The second 2D Vector @return - sal_Bool if the two values are parallel. Also sal_True if - one of the vectors is empty. + The Angle value of the two involved 2D Vectors in -pi/2 < return < pi/2 */ - sal_Bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB ); + double angle( const B2DVector& rVec ) const; /** Transform vector by given transformation matrix. Since this is a vector, translational components of the matrix are disregarded. */ - B2DVector operator*( const matrix::B2DHomMatrix& rMat, const B2DVector& rVec ); + B2DVector& operator*=( const B2DHomMatrix& rMat ); - /** Test continuity between given vectors. + static const B2DVector& getEmptyVector(); + }; - The two given vectors are assumed to describe control points on a - common point. Calculate if there is a continuity between them. - */ - ::basegfx::vector::B2DVectorContinuity getContinuity( const B2DVector& rBackVector, const B2DVector& rForwardVector ); + // external operators + ////////////////////////////////////////////////////////////////////////// + + /** Calculate the orientation to another 2D Vector + + @param rVecA + The first 2D Vector + + @param rVecB + The second 2D Vector + + @return + The mathematical Orientation of the two involved 2D Vectors + */ + B2DVectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB ); + + /** Calculate a perpendicular 2D Vector to the given one + + @param rVec + The source 2D Vector + + @attention This only works if the given 2D Vector is normalized. + + @return + A 2D Vector perpendicular to the one given in parameter rVec + */ + B2DVector getPerpendicular( const B2DVector& rNormalizedVec ); + + /** Test two vectors which need not to be normalized for parallelism + + @param rVecA + The first 2D Vector + + @param rVecB + The second 2D Vector + + @return + sal_Bool if the two values are parallel. Also sal_True if + one of the vectors is empty. + */ + sal_Bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB ); + + /** Transform vector by given transformation matrix. + + Since this is a vector, translational components of the + matrix are disregarded. + */ + B2DVector operator*( const B2DHomMatrix& rMat, const B2DVector& rVec ); + + /** Test continuity between given vectors. + + The two given vectors are assumed to describe control points on a + common point. Calculate if there is a continuity between them. + */ + ::basegfx::B2DVectorContinuity getContinuity( const B2DVector& rBackVector, const B2DVector& rForwardVector ); - } // end of namespace vector } // end of namespace basegfx #endif // _BGFX_VECTOR_B2DVECTOR_HXX diff --git a/basegfx/inc/basegfx/vector/b3dvector.hxx b/basegfx/inc/basegfx/vector/b3dvector.hxx index 855abb7f71e8..094bacfb50a1 100644 --- a/basegfx/inc/basegfx/vector/b3dvector.hxx +++ b/basegfx/inc/basegfx/vector/b3dvector.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dvector.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:05 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:17:58 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,270 +68,232 @@ namespace basegfx { - namespace matrix - { - // predeclaration - class B3DHomMatrix; - } // end of namespace matrix; + // predeclaration + class B3DHomMatrix; - namespace vector - { - /** Base Point class with three double values + /** Base Point class with three double values + + This class derives all operators and common handling for + a 3D data class from B3DTuple. All necessary extensions + which are special for 3D Vectors are added here. - This class derives all operators and common handling for - a 3D data class from B3DTuple. All necessary extensions - which are special for 3D Vectors are added here. + @see B3DTuple + */ + class B3DVector : public ::basegfx::B3DTuple + { + public: + /** Create a 3D Vector - @see B3DTuple + @param fVal + This parameter is used to initialize the coordinate + part of the 3D Vector. */ - class B3DVector : public ::basegfx::tuple::B3DTuple - { - public: - /** Create a 3D Vector - - @param fVal - This parameter is used to initialize the coordinate - part of the 3D Vector. - */ - B3DVector(double fVal = 0.0) - : B3DTuple(fVal) - {} - - /** Create a 3D Vector - - @param fX - This parameter is used to initialize the X-coordinate - of the 3D Vector. - - @param fY - This parameter is used to initialize the Y-coordinate - of the 3D Vector. - - @param fZ - This parameter is used to initialize the Z-coordinate - of the 3D Vector. - */ - B3DVector(double fX, double fY, double fZ) - : B3DTuple(fX, fY, fZ) - {} - - /** Create a copy of a 3D Vector - - @param rVec - The 3D Vector which will be copied. - */ - B3DVector(const B3DVector& rVec) - : B3DTuple(rVec) - {} - - /** constructor with tuple to allow copy-constructing - from B3DTuple-based classes - */ - B3DVector(const ::basegfx::tuple::B3DTuple& rTuple) - : B3DTuple(rTuple) - {} - - ~B3DVector() - {} - - /** *=operator to allow usage from B3DVector, too - */ - B3DVector& operator*=( const B3DVector& rPnt ) - { - mfX *= rPnt.mfX; - mfY *= rPnt.mfY; - mfZ *= rPnt.mfZ; - return *this; - } + B3DVector(double fVal = 0.0) + : B3DTuple(fVal) + {} - /** *=operator to allow usage from B3DVector, too - */ - B3DVector& operator*=(double t) - { - mfX *= t; - mfY *= t; - mfZ *= t; - return *this; - } + /** Create a 3D Vector - /** assignment operator to allow assigning the results - of B3DTuple calculations - */ - B3DVector& operator=( const ::basegfx::tuple::B3DTuple& rVec ) - { - mfX = rVec.getX(); - mfY = rVec.getY(); - mfZ = rVec.getZ(); - return *this; - } + @param fX + This parameter is used to initialize the X-coordinate + of the 3D Vector. - /** Calculate the length of this 3D Vector + @param fY + This parameter is used to initialize the Y-coordinate + of the 3D Vector. - @return The Length of the 3D Vector - */ - double getLength(void) const - { - double fLen(scalar(*this)); - if((0.0 == fLen) || (1.0 == fLen)) - return fLen; - return sqrt(fLen); - } + @param fZ + This parameter is used to initialize the Z-coordinate + of the 3D Vector. + */ + B3DVector(double fX, double fY, double fZ) + : B3DTuple(fX, fY, fZ) + {} - /** Calculate the length in the XY-Plane for this 3D Vector + /** Create a copy of a 3D Vector - @return The XY-Plane Length of the 3D Vector - */ - double getXYLength(void) const - { - double fLen((mfX * mfX) + (mfY * mfY)); - if((0.0 == fLen) || (1.0 == fLen)) - return fLen; - return sqrt(fLen); - } + @param rVec + The 3D Vector which will be copied. + */ + B3DVector(const B3DVector& rVec) + : B3DTuple(rVec) + {} - /** Calculate the length in the XZ-Plane for this 3D Vector + /** constructor with tuple to allow copy-constructing + from B3DTuple-based classes + */ + B3DVector(const ::basegfx::B3DTuple& rTuple) + : B3DTuple(rTuple) + {} - @return The XZ-Plane Length of the 3D Vector - */ - double getXZLength(void) const - { - double fLen((mfX * mfZ) + (mfY * mfZ)); - if((0.0 == fLen) || (1.0 == fLen)) - return fLen; - return sqrt(fLen); - } + ~B3DVector() + {} + + /** *=operator to allow usage from B3DVector, too + */ + B3DVector& operator*=( const B3DVector& rPnt ) + { + mfX *= rPnt.mfX; + mfY *= rPnt.mfY; + mfZ *= rPnt.mfZ; + return *this; + } - /** Calculate the length in the YZ-Plane for this 3D Vector + /** *=operator to allow usage from B3DVector, too + */ + B3DVector& operator*=(double t) + { + mfX *= t; + mfY *= t; + mfZ *= t; + return *this; + } - @return The YZ-Plane Length of the 3D Vector - */ - double getYZLength(void) const - { - double fLen((mfY * mfY) + (mfZ * mfZ)); - if((0.0 == fLen) || (1.0 == fLen)) - return fLen; - return sqrt(fLen); - } + /** assignment operator to allow assigning the results + of B3DTuple calculations + */ + B3DVector& operator=( const ::basegfx::B3DTuple& rVec ) + { + mfX = rVec.getX(); + mfY = rVec.getY(); + mfZ = rVec.getZ(); + return *this; + } - /** Set the length of this 3D Vector + /** Calculate the length of this 3D Vector - @param fLen - The to be achieved length of the 3D Vector - */ - B3DVector& setLength(double fLen) - { - double fLenNow(scalar(*this)); + @return The Length of the 3D Vector + */ + double getLength(void) const + { + double fLen(scalar(*this)); + if((0.0 == fLen) || (1.0 == fLen)) + return fLen; + return sqrt(fLen); + } - if(!::basegfx::numeric::fTools::equalZero(fLenNow)) - { - const double fOne(1.0); + /** Calculate the length in the XY-Plane for this 3D Vector - if(!::basegfx::numeric::fTools::equal(fOne, fLenNow)) - { - fLen /= sqrt(fLenNow); - } + @return The XY-Plane Length of the 3D Vector + */ + double getXYLength(void) const + { + double fLen((mfX * mfX) + (mfY * mfY)); + if((0.0 == fLen) || (1.0 == fLen)) + return fLen; + return sqrt(fLen); + } - mfX *= fLen; - mfY *= fLen; - mfZ *= fLen; - } + /** Calculate the length in the XZ-Plane for this 3D Vector - return *this; - } + @return The XZ-Plane Length of the 3D Vector + */ + double getXZLength(void) const + { + double fLen((mfX * mfZ) + (mfY * mfZ)); + if((0.0 == fLen) || (1.0 == fLen)) + return fLen; + return sqrt(fLen); + } + + /** Calculate the length in the YZ-Plane for this 3D Vector - /** Normalize this 3D Vector + @return The YZ-Plane Length of the 3D Vector + */ + double getYZLength(void) const + { + double fLen((mfY * mfY) + (mfZ * mfZ)); + if((0.0 == fLen) || (1.0 == fLen)) + return fLen; + return sqrt(fLen); + } - The length of the 3D Vector is set to 1.0 - */ - B3DVector& normalize(); + /** Set the length of this 3D Vector - /** Test if this 3D Vector is normalized + @param fLen + The to be achieved length of the 3D Vector + */ + B3DVector& setLength(double fLen) + { + double fLenNow(scalar(*this)); - @return - sal_True if lenth of vector is equal to 1.0 - sal_False else - */ - sal_Bool isNormalized() const + if(!::basegfx::fTools::equalZero(fLenNow)) { const double fOne(1.0); - const double fScalar(scalar(*this)); - - return (::basegfx::numeric::fTools::equal(fOne, fScalar)); - } - /** get a 3D Vector which is perpendicular to this and a given 3D Vector + if(!::basegfx::fTools::equal(fOne, fLenNow)) + { + fLen /= sqrt(fLenNow); + } - @attention This only works if this and the given 3D Vector are - both normalized. + mfX *= fLen; + mfY *= fLen; + mfZ *= fLen; + } - @param rNormalizedVec - A normalized 3D Vector. + return *this; + } - @return - A 3D Vector perpendicular to this and the given one - */ - B3DVector getPerpendicular(const B3DVector& rNormalizedVec) const; + /** Normalize this 3D Vector - /** get the projection of this Vector on the given Plane + The length of the 3D Vector is set to 1.0 + */ + B3DVector& normalize(); - @attention This only works if the given 3D Vector defining - the Plane is normalized. + /** Test if this 3D Vector is normalized - @param rNormalizedPlane - A normalized 3D Vector defining a Plane. + @return + sal_True if lenth of vector is equal to 1.0 + sal_False else + */ + sal_Bool isNormalized() const + { + const double fOne(1.0); + const double fScalar(scalar(*this)); - @return - The projected 3D Vector - */ - B3DVector getProjectionOnPlane(const B3DVector& rNormalizedPlane) const; + return (::basegfx::fTools::equal(fOne, fScalar)); + } - /** Calculate the Scalar product + /** get a 3D Vector which is perpendicular to this and a given 3D Vector - This method calculates the Scalar product between this - and the given 3D Vector. + @attention This only works if this and the given 3D Vector are + both normalized. - @param rVec - A second 3D Vector. + @param rNormalizedVec + A normalized 3D Vector. - @return - The Scalar Product of two 3D Vectors - */ - double scalar(const B3DVector& rVec) const - { - return ((mfX * rVec.mfX) + (mfY * rVec.mfY) + (mfZ * rVec.mfZ)); - } + @return + A 3D Vector perpendicular to this and the given one + */ + B3DVector getPerpendicular(const B3DVector& rNormalizedVec) const; - /** Transform vector by given transformation matrix. + /** get the projection of this Vector on the given Plane - Since this is a vector, translational components of the - matrix are disregarded. - */ - B3DVector& operator*=( const matrix::B3DHomMatrix& rMat ); + @attention This only works if the given 3D Vector defining + the Plane is normalized. - static const B3DVector& getEmptyVector() - { - return (const B3DVector&) ::basegfx::tuple::B3DTuple::getEmptyTuple(); - } - }; + @param rNormalizedPlane + A normalized 3D Vector defining a Plane. - // external operators - ////////////////////////////////////////////////////////////////////////// + @return + The projected 3D Vector + */ + B3DVector getProjectionOnPlane(const B3DVector& rNormalizedPlane) const; - /** get a 3D Vector which is in 2D (ignoring - the Z-Coordinate) perpendicular to a given 3D Vector + /** Calculate the Scalar product - @attention This only works if the given 3D Vector is normalized. + This method calculates the Scalar product between this + and the given 3D Vector. - @param rNormalizedVec - A normalized 3D Vector. + @param rVec + A second 3D Vector. @return - A 3D Vector perpendicular to the given one in X,Y (2D). + The Scalar Product of two 3D Vectors */ - inline B3DVector getPerpendicular2D( const B3DVector& rNormalizedVec ) + double scalar(const B3DVector& rVec) const { - B3DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX(), rNormalizedVec.getZ()); - return aPerpendicular; + return ((mfX * rVec.mfX) + (mfY * rVec.mfY) + (mfZ * rVec.mfZ)); } /** Transform vector by given transformation matrix. @@ -339,28 +301,60 @@ namespace basegfx Since this is a vector, translational components of the matrix are disregarded. */ - B3DVector operator*( const matrix::B3DHomMatrix& rMat, const B3DVector& rVec ); + B3DVector& operator*=( const B3DHomMatrix& rMat ); - /** Calculate the Cross Product of two 3D Vectors + static const B3DVector& getEmptyVector() + { + return (const B3DVector&) ::basegfx::B3DTuple::getEmptyTuple(); + } + }; - @param rVecA - A first 3D Vector. + // external operators + ////////////////////////////////////////////////////////////////////////// - @param rVecB - A second 3D Vector. + /** get a 3D Vector which is in 2D (ignoring + the Z-Coordinate) perpendicular to a given 3D Vector - @return - The Cross Product of both 3D Vectors - */ - inline B3DVector cross(const B3DVector& rVecA, const B3DVector& rVecB) - { - B3DVector aVec( - rVecA.getY() * rVecB.getZ() - rVecA.getZ() * rVecB.getY(), - rVecA.getZ() * rVecB.getX() - rVecA.getX() * rVecB.getZ(), - rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX()); - return aVec; - } - } // end of namespace vector + @attention This only works if the given 3D Vector is normalized. + + @param rNormalizedVec + A normalized 3D Vector. + + @return + A 3D Vector perpendicular to the given one in X,Y (2D). + */ + inline B3DVector getPerpendicular2D( const B3DVector& rNormalizedVec ) + { + B3DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX(), rNormalizedVec.getZ()); + return aPerpendicular; + } + + /** Transform vector by given transformation matrix. + + Since this is a vector, translational components of the + matrix are disregarded. + */ + B3DVector operator*( const B3DHomMatrix& rMat, const B3DVector& rVec ); + + /** Calculate the Cross Product of two 3D Vectors + + @param rVecA + A first 3D Vector. + + @param rVecB + A second 3D Vector. + + @return + The Cross Product of both 3D Vectors + */ + inline B3DVector cross(const B3DVector& rVecA, const B3DVector& rVecB) + { + B3DVector aVec( + rVecA.getY() * rVecB.getZ() - rVecA.getZ() * rVecB.getY(), + rVecA.getZ() * rVecB.getX() - rVecA.getX() * rVecB.getZ(), + rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX()); + return aVec; + } } // end of namespace basegfx #endif // _BGFX_VECTOR_B3DVECTOR_HXX diff --git a/basegfx/prj/d.lst b/basegfx/prj/d.lst index ac3edb8a1314..bda0e26ceb42 100644 --- a/basegfx/prj/d.lst +++ b/basegfx/prj/d.lst @@ -32,7 +32,8 @@ mkdir: %_DEST%\inc%_EXT%\basegfx\curve ..\inc\basegfx\curve\b2dcubicbezier.hxx %_DEST%\inc%_EXT%\basegfx\curve\b2dcubicbezier.hxx ..\inc\basegfx\curve\b2dquadraticbezier.hxx %_DEST%\inc%_EXT%\basegfx\curve\b2dquadraticbezier.hxx -#mkdir: %_DEST%\inc%_EXT%\basegfx\numeric +mkdir: %_DEST%\inc%_EXT%\basegfx\numeric +..\inc\basegfx\numeric\ftools.hxx %_DEST%\inc%_EXT%\basegfx\numeric\ftools.hxx mkdir: %_DEST%\inc%_EXT%\basegfx\polygon ..\inc\basegfx\polygon\b2dpolygon.hxx %_DEST%\inc%_EXT%\basegfx\polygon\b2dpolygon.hxx @@ -46,4 +47,4 @@ mkdir: %_DEST%\inc%_EXT%\basegfx\polygon mkdir: %_DEST%\inc%_EXT%\basegfx\tuple ..\inc\basegfx\tuple\b2dtuple.hxx %_DEST%\inc%_EXT%\basegfx\tuple\b2dtuple.hxx -..\inc\basegfx\tuple\b3dtuple.hxx %_DEST%\inc%_EXT%\basegfx\tuple\b3dpoint.hxx +..\inc\basegfx\tuple\b3dtuple.hxx %_DEST%\inc%_EXT%\basegfx\tuple\b3dtuple.hxx diff --git a/basegfx/source/curve/b2dbeziertools.cxx b/basegfx/source/curve/b2dbeziertools.cxx index 3512b87ca992..67c25aacb17a 100644 --- a/basegfx/source/curve/b2dbeziertools.cxx +++ b/basegfx/source/curve/b2dbeziertools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dbeziertools.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:07 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -95,441 +95,438 @@ namespace basegfx { - namespace curve + namespace { - namespace + class DistanceErrorFunctor { - class DistanceErrorFunctor + public: + DistanceErrorFunctor( const double& distance ) : + mfDistance2( distance*distance ), + mfLastDistanceError2( ::std::numeric_limits<double>::max() ) { - public: - DistanceErrorFunctor( const double& distance ) : - mfDistance2( distance*distance ), - mfLastDistanceError2( ::std::numeric_limits<double>::max() ) - { - } - - bool subdivideFurther( const double& P1x, const double& P1y, - const double& P2x, const double& P2y, - const double& P3x, const double& P3y, - const double& P4x, const double& P4y, - const double&, const double& ) // last two values not used here - { - // Perform bezier flatness test (lecture notes from R. Schaback, - // Mathematics of Computer-Aided Design, Uni Goettingen, 2000) - // - // ||P(t) - L(t)|| <= max ||b_j - b_0 - j/n(b_n - b_0)|| - // 0<=j<=n - // - // What is calculated here is an upper bound to the distance from - // a line through b_0 and b_3 (P1 and P4 in our notation) and the - // curve. We can drop 0 and n from the running indices, since the - // argument of max becomes zero for those cases. - const double fJ1x( P2x - P1x - 1.0/3.0*(P4x - P1x) ); - const double fJ1y( P2y - P1y - 1.0/3.0*(P4y - P1y) ); - const double fJ2x( P3x - P1x - 2.0/3.0*(P4x - P1x) ); - const double fJ2y( P3y - P1y - 2.0/3.0*(P4y - P1y) ); - const double distanceError2( ::std::max( fJ1x*fJ1x + fJ1y*fJ1y, - fJ2x*fJ2x + fJ2y*fJ2y) ); - - // stop if error measure does not improve anymore. This is a - // safety guard against floating point inaccuracies. - // stop if distance from line is guaranteed to be bounded by d - bool bRet( mfLastDistanceError2 > distanceError2 && - distanceError2 >= mfDistance2 ); - - mfLastDistanceError2 = distanceError2; + } - return bRet; - } + bool subdivideFurther( const double& P1x, const double& P1y, + const double& P2x, const double& P2y, + const double& P3x, const double& P3y, + const double& P4x, const double& P4y, + const double&, const double& ) // last two values not used here + { + // Perform bezier flatness test (lecture notes from R. Schaback, + // Mathematics of Computer-Aided Design, Uni Goettingen, 2000) + // + // ||P(t) - L(t)|| <= max ||b_j - b_0 - j/n(b_n - b_0)|| + // 0<=j<=n + // + // What is calculated here is an upper bound to the distance from + // a line through b_0 and b_3 (P1 and P4 in our notation) and the + // curve. We can drop 0 and n from the running indices, since the + // argument of max becomes zero for those cases. + const double fJ1x( P2x - P1x - 1.0/3.0*(P4x - P1x) ); + const double fJ1y( P2y - P1y - 1.0/3.0*(P4y - P1y) ); + const double fJ2x( P3x - P1x - 2.0/3.0*(P4x - P1x) ); + const double fJ2y( P3y - P1y - 2.0/3.0*(P4y - P1y) ); + const double distanceError2( ::std::max( fJ1x*fJ1x + fJ1y*fJ1y, + fJ2x*fJ2x + fJ2y*fJ2y) ); + + // stop if error measure does not improve anymore. This is a + // safety guard against floating point inaccuracies. + // stop if distance from line is guaranteed to be bounded by d + bool bRet( mfLastDistanceError2 > distanceError2 && + distanceError2 >= mfDistance2 ); + + mfLastDistanceError2 = distanceError2; + + return bRet; + } - private: - double mfDistance2; - double mfLastDistanceError2; - }; + private: + double mfDistance2; + double mfLastDistanceError2; + }; - class AngleErrorFunctor + class AngleErrorFunctor + { + public: + AngleErrorFunctor( const double& angleBounds ) : + mfTanAngle( angleBounds * F_PI180 ), + mfLastTanAngle( ::std::numeric_limits<double>::max() ) { - public: - AngleErrorFunctor( const double& angleBounds ) : - mfTanAngle( angleBounds * F_PI180 ), - mfLastTanAngle( ::std::numeric_limits<double>::max() ) - { - } + } - bool subdivideFurther( const double P1x, const double P1y, - const double P2x, const double P2y, - const double P3x, const double P3y, - const double P4x, const double P4y, - const double Pdx, const double Pdy ) + bool subdivideFurther( const double P1x, const double P1y, + const double P2x, const double P2y, + const double P3x, const double P3y, + const double P4x, const double P4y, + const double Pdx, const double Pdy ) + { + // Test angle differences between two lines (ad + // and bd), meeting in the t=0.5 division point + // (d), and the angle from the other ends of those + // lines (b and a, resp.) to the tangents to the + // curve at this points: + // + // *__________ + // ......*b + // ... + // .. + // . + // * *d + // | . + // | . + // | . + // | . + // |. + // |. + // * + // a + // + // When using half of the angle bound for the + // difference to the tangents at a or b, resp., + // this procedure guarantees that no angle in the + // resulting line polygon is larger than the + // specified angle bound. This is because during + // subdivision, adjacent curve segments will have + // collinear tangent vectors, thus, when each + // side's line segments differs by at most angle/2 + // from that tangent, the summed difference will + // be at most angle (this was modeled after an + // idea from Armin Weiss). + + // To stay within the notation above, a equals P1, + // the other end point of the tangent starting at + // a is P2, d is Pd, and so forth. The + const B2DVector vecAD( Pdx - P1x, Pdy - P1y ); + const B2DVector vecDB( P4x - Pdx, P4y - Pdy ); + + const double scalarVecADDB( vecAD.scalar( vecDB ) ); + const double crossVecADDB( vecAD.cross( vecDB ) ); + + const B2DVector vecStartTangent( P2x - P1x, P2y - P1y ); + const B2DVector vecEndTangent( P4x - P3x, P4y - P3y ); + + const double scalarVecStartTangentAD( vecStartTangent.scalar( vecAD ) ); + const double crossVecStartTangentAD( vecStartTangent.cross( vecAD ) ); + + const double scalarVecDBEndTangent( vecDB.scalar( vecEndTangent ) ); + const double crossVecDBEndTangent( vecDB.cross( vecEndTangent ) ); + + + double fCurrAngle( ::std::numeric_limits<double>::max() ); + + // anyone has zero denominator? then we're at + // +infinity, anyway + if( !fTools::equalZero( scalarVecADDB ) && + !fTools::equalZero( scalarVecStartTangentAD ) && + !fTools::equalZero( scalarVecDBEndTangent ) ) { - // Test angle differences between two lines (ad - // and bd), meeting in the t=0.5 division point - // (d), and the angle from the other ends of those - // lines (b and a, resp.) to the tangents to the - // curve at this points: - // - // *__________ - // ......*b - // ... - // .. - // . - // * *d - // | . - // | . - // | . - // | . - // |. - // |. - // * - // a - // - // When using half of the angle bound for the - // difference to the tangents at a or b, resp., - // this procedure guarantees that no angle in the - // resulting line polygon is larger than the - // specified angle bound. This is because during - // subdivision, adjacent curve segments will have - // collinear tangent vectors, thus, when each - // side's line segments differs by at most angle/2 - // from that tangent, the summed difference will - // be at most angle (this was modeled after an - // idea from Armin Weiss). - - // To stay within the notation above, a equals P1, - // the other end point of the tangent starting at - // a is P2, d is Pd, and so forth. The - const vector::B2DVector vecAD( Pdx - P1x, Pdy - P1y ); - const vector::B2DVector vecDB( P4x - Pdx, P4y - Pdy ); - - const double scalarVecADDB( vecAD.scalar( vecDB ) ); - const double crossVecADDB( vecAD.cross( vecDB ) ); - - const vector::B2DVector vecStartTangent( P2x - P1x, P2y - P1y ); - const vector::B2DVector vecEndTangent( P4x - P3x, P4y - P3y ); - - const double scalarVecStartTangentAD( vecStartTangent.scalar( vecAD ) ); - const double crossVecStartTangentAD( vecStartTangent.cross( vecAD ) ); - - const double scalarVecDBEndTangent( vecDB.scalar( vecEndTangent ) ); - const double crossVecDBEndTangent( vecDB.cross( vecEndTangent ) ); - - - double fCurrAngle( ::std::numeric_limits<double>::max() ); - - // anyone has zero denominator? then we're at - // +infinity, anyway - if( !numeric::fTools::equalZero( scalarVecADDB ) && - !numeric::fTools::equalZero( scalarVecStartTangentAD ) && - !numeric::fTools::equalZero( scalarVecDBEndTangent ) ) + if( scalarVecADDB > 0.0 && + scalarVecStartTangentAD > 0.0 && + scalarVecDBEndTangent > 0.0 ) { - if( scalarVecADDB > 0.0 && - scalarVecStartTangentAD > 0.0 && - scalarVecDBEndTangent > 0.0 ) - { - fCurrAngle = ::std::max( fabs( atan2( crossVecADDB, scalarVecADDB ) ), - ::std::max( fabs( atan2( crossVecStartTangentAD, scalarVecStartTangentAD ) ), - fabs( atan2( crossVecDBEndTangent, scalarVecDBEndTangent ) ) ) ); - } + fCurrAngle = ::std::max( fabs( atan2( crossVecADDB, scalarVecADDB ) ), + ::std::max( fabs( atan2( crossVecStartTangentAD, scalarVecStartTangentAD ) ), + fabs( atan2( crossVecDBEndTangent, scalarVecDBEndTangent ) ) ) ); } + } - // stop if error measure does not improve anymore. This is a - // safety guard against floating point inaccuracies. - // stop if angle difference is guaranteed to be bounded by mfTanAngle - bool bRet( mfLastTanAngle > fCurrAngle && - fCurrAngle >= mfTanAngle ); + // stop if error measure does not improve anymore. This is a + // safety guard against floating point inaccuracies. + // stop if angle difference is guaranteed to be bounded by mfTanAngle + bool bRet( mfLastTanAngle > fCurrAngle && + fCurrAngle >= mfTanAngle ); - mfLastTanAngle = fCurrAngle; + mfLastTanAngle = fCurrAngle; - return bRet; - } + return bRet; + } - private: - double mfTanAngle; - double mfLastTanAngle; - }; + private: + double mfTanAngle; + double mfLastTanAngle; + }; - /* Recursively subdivide cubic bezier curve via deCasteljau. + /* Recursively subdivide cubic bezier curve via deCasteljau. - @param rPoly - Polygon to append generated points to + @param rPoly + Polygon to append generated points to - @param d2 - Maximal squared difference of curve to a straight line + @param d2 + Maximal squared difference of curve to a straight line - @param P* - Exactly four points, interpreted as support and control points of - a cubic bezier curve. + @param P* + Exactly four points, interpreted as support and control points of + a cubic bezier curve. - @param old_distance2 - Last squared distance to line for this recursion - path. Used as an end condition, if it is no longer - improving. + @param old_distance2 + Last squared distance to line for this recursion + path. Used as an end condition, if it is no longer + improving. - @param recursionDepth - Depth of recursion. Used as a termination criterion, to - prevent endless looping. - */ - template < class ErrorFunctor > int ImplAdaptiveSubdivide( polygon::B2DPolygon& rPoly, - ErrorFunctor rErrorFunctor, - const double P1x, const double P1y, - const double P2x, const double P2y, - const double P3x, const double P3y, - const double P4x, const double P4y, - int recursionDepth ) + @param recursionDepth + Depth of recursion. Used as a termination criterion, to + prevent endless looping. + */ + template < class ErrorFunctor > int ImplAdaptiveSubdivide( B2DPolygon& rPoly, + ErrorFunctor rErrorFunctor, + const double P1x, const double P1y, + const double P2x, const double P2y, + const double P3x, const double P3y, + const double P4x, const double P4y, + int recursionDepth ) + { + // Hard limit on recursion depth, empiric number. + enum {maxRecursionDepth=128}; + + // deCasteljau bezier arc, split at t=0.5 + // Foley/vanDam, p. 508 + + // Note that for the pure distance error method, this + // subdivision could be moved into the if-branch. But + // since this accounts for saved work only for the + // very last subdivision step, and we need the + // subdivided curve for the angle criterium, I think + // it's justified here. + const double L1x( P1x ), L1y( P1y ); + const double L2x( (P1x + P2x)*0.5 ), L2y( (P1y + P2y)*0.5 ); + const double Hx ( (P2x + P3x)*0.5 ), Hy ( (P2y + P3y)*0.5 ); + const double L3x( (L2x + Hx)*0.5 ), L3y( (L2y + Hy)*0.5 ); + const double R4x( P4x ), R4y( P4y ); + const double R3x( (P3x + P4x)*0.5 ), R3y( (P3y + P4y)*0.5 ); + const double R2x( (Hx + R3x)*0.5 ), R2y( (Hy + R3y)*0.5 ); + const double R1x( (L3x + R2x)*0.5 ), R1y( (L3y + R2y)*0.5 ); + const double L4x( R1x ), L4y( R1y ); + + // stop at recursion level 128. This is a safety guard against + // floating point inaccuracies. + if( recursionDepth < maxRecursionDepth && + rErrorFunctor.subdivideFurther( P1x, P1y, + P2x, P2y, + P3x, P3y, + P4x, P4y, + R1x, R1y ) ) { - // Hard limit on recursion depth, empiric number. - enum {maxRecursionDepth=128}; - - // deCasteljau bezier arc, split at t=0.5 - // Foley/vanDam, p. 508 - - // Note that for the pure distance error method, this - // subdivision could be moved into the if-branch. But - // since this accounts for saved work only for the - // very last subdivision step, and we need the - // subdivided curve for the angle criterium, I think - // it's justified here. - const double L1x( P1x ), L1y( P1y ); - const double L2x( (P1x + P2x)*0.5 ), L2y( (P1y + P2y)*0.5 ); - const double Hx ( (P2x + P3x)*0.5 ), Hy ( (P2y + P3y)*0.5 ); - const double L3x( (L2x + Hx)*0.5 ), L3y( (L2y + Hy)*0.5 ); - const double R4x( P4x ), R4y( P4y ); - const double R3x( (P3x + P4x)*0.5 ), R3y( (P3y + P4y)*0.5 ); - const double R2x( (Hx + R3x)*0.5 ), R2y( (Hy + R3y)*0.5 ); - const double R1x( (L3x + R2x)*0.5 ), R1y( (L3y + R2y)*0.5 ); - const double L4x( R1x ), L4y( R1y ); - - // stop at recursion level 128. This is a safety guard against - // floating point inaccuracies. - if( recursionDepth < maxRecursionDepth && - rErrorFunctor.subdivideFurther( P1x, P1y, - P2x, P2y, - P3x, P3y, - P4x, P4y, - R1x, R1y ) ) - { - // subdivide further - ++recursionDepth; + // subdivide further + ++recursionDepth; - int nGeneratedPoints(0); + int nGeneratedPoints(0); - nGeneratedPoints += ImplAdaptiveSubdivide(rPoly, rErrorFunctor, L1x, L1y, L2x, L2y, L3x, L3y, L4x, L4y, recursionDepth); - nGeneratedPoints += ImplAdaptiveSubdivide(rPoly, rErrorFunctor, R1x, R1y, R2x, R2y, R3x, R3y, R4x, R4y, recursionDepth); + nGeneratedPoints += ImplAdaptiveSubdivide(rPoly, rErrorFunctor, L1x, L1y, L2x, L2y, L3x, L3y, L4x, L4y, recursionDepth); + nGeneratedPoints += ImplAdaptiveSubdivide(rPoly, rErrorFunctor, R1x, R1y, R2x, R2y, R3x, R3y, R4x, R4y, recursionDepth); - // return number of points generated in this - // recursion branch - return nGeneratedPoints; - } - else - { - // requested resolution reached. Add end points to - // output iterator. order is preserved, since - // this is so to say depth first traversal. - rPoly.append( point::B2DPoint( P1x, P1y ) ); - - // return number of points generated in this - // recursion branch - return 1; - } + // return number of points generated in this + // recursion branch + return nGeneratedPoints; } + else + { + // requested resolution reached. Add end points to + // output iterator. order is preserved, since + // this is so to say depth first traversal. + rPoly.append( B2DPoint( P1x, P1y ) ); + + // return number of points generated in this + // recursion branch + return 1; + } + } // LATER #if 0 - /* Approximate given cubic bezier curve by quadratic bezier segments */ - void ImplQuadBezierApprox( polygon::B2DPolygon& rPoly, - BitStream& rBits, - Point& rLastPoint, - const double d2, - const double P1x, const double P1y, - const double P2x, const double P2y, - const double P3x, const double P3y, - const double P4x, const double P4y ) + /* Approximate given cubic bezier curve by quadratic bezier segments */ + void ImplQuadBezierApprox( B2DPolygon& rPoly, + BitStream& rBits, + Point& rLastPoint, + const double d2, + const double P1x, const double P1y, + const double P2x, const double P2y, + const double P3x, const double P3y, + const double P4x, const double P4y ) + { + // Check for degenerate case, where the given cubic bezier curve + // is already quadratic: P4 == 3P3 - 3P2 + P1 + if( P4x == 3.0*P3x - 3.0*P2x + P1x && + P4y == 3.0*P3y - 3.0*P2y + P1y ) + { + Impl_addQuadBezier( rBits, rLastPoint, + 3.0/2.0*P2x - 1.0/2.0*P1x, 3.0/2.0*P2y - 1.0/2.0*P1y, + P4x, P4y); + } + else { - // Check for degenerate case, where the given cubic bezier curve - // is already quadratic: P4 == 3P3 - 3P2 + P1 - if( P4x == 3.0*P3x - 3.0*P2x + P1x && - P4y == 3.0*P3y - 3.0*P2y + P1y ) + // Create quadratic segment for given cubic: + // Start and end point must coincide, determine quadratic control + // point in such a way that it lies on the intersection of the + // tangents at start and end point, resp. Thus, both cubic and + // quadratic curve segments will match in 0th and 1st derivative + // at the start and end points + + // Intersection of P2P1 and P4P3 + // (P2y-P4y)(P3x-P4x)-(P2x-P4x)(P3y-P4y) + // lambda = ------------------------------------- + // (P1x-P2x)(P3y-P4y)-(P1y-P2y)(P3x-P4x) + // + // Intersection point IP is now + // IP = P2 + lambda(P1-P2) + // + const double nominator( (P2y-P4y)*(P3x-P4x) - (P2x-P4x)*(P3y-P4y) ); + const double denominator( (P1x-P2x)*(P3y-P4y) - (P1y-P2y)*(P3x-P4x) ); + const double lambda( nominator / denominator ); + + const double IPx( P2x + lambda*( P1x - P2x) ); + const double IPy( P2y + lambda*( P1y - P2y) ); + + // Introduce some alias names: quadratic start point is P1, end + // point is P4, control point is IP + const double QP1x( P1x ); + const double QP1y( P1y ); + const double QP2x( IPx ); + const double QP2y( IPy ); + const double QP3x( P4x ); + const double QP3y( P4y ); + + // Adapted bezier flatness test (lecture notes from R. Schaback, + // Mathematics of Computer-Aided Design, Uni Goettingen, 2000) + // + // ||C(t) - Q(t)|| <= max ||c_j - q_j|| + // 0<=j<=n + // + // In this case, we don't need the distance from the cubic bezier + // to a straight line, but to a quadratic bezier. The c_j's are + // the cubic bezier's bernstein coefficients, the q_j's the + // quadratic bezier's. We have the c_j's given, the q_j's can be + // calculated from QPi like this (sorry, mixed index notation, we + // use [1,n], formulas use [0,n-1]): + // + // q_0 = QP1 = P1 + // q_1 = 1/3 QP1 + 2/3 QP2 + // q_2 = 2/3 QP2 + 1/3 QP3 + // q_3 = QP3 = P4 + // + // We can drop case 0 and 3, since there the curves coincide + // (distance is zero) + + // calculate argument of max for j=1 and j=2 + const double fJ1x( P2x - 1.0/3.0*QP1x - 2.0/3.0*QP2x ); + const double fJ1y( P2y - 1.0/3.0*QP1y - 2.0/3.0*QP2y ); + const double fJ2x( P3x - 2.0/3.0*QP2x - 1.0/3.0*QP3x ); + const double fJ2y( P3y - 2.0/3.0*QP2y - 1.0/3.0*QP3y ); + + // stop if distance from cubic curve is guaranteed to be bounded by d + // Should denominator be 0: then P1P2 and P3P4 are parallel (P1P2^T R[90,P3P4] = 0.0), + // meaning that either we have a straight line or an inflexion point (see else block below) + if( 0.0 != denominator && + ::std::max( fJ1x*fJ1x + fJ1y*fJ1y, + fJ2x*fJ2x + fJ2y*fJ2y) < d2 ) { + // requested resolution reached. + // Add end points to output file. + // order is preserved, since this is so to say depth first traversal. Impl_addQuadBezier( rBits, rLastPoint, - 3.0/2.0*P2x - 1.0/2.0*P1x, 3.0/2.0*P2y - 1.0/2.0*P1y, - P4x, P4y); + QP2x, QP2y, + QP3x, QP3y); } else { - // Create quadratic segment for given cubic: - // Start and end point must coincide, determine quadratic control - // point in such a way that it lies on the intersection of the - // tangents at start and end point, resp. Thus, both cubic and - // quadratic curve segments will match in 0th and 1st derivative - // at the start and end points - - // Intersection of P2P1 and P4P3 - // (P2y-P4y)(P3x-P4x)-(P2x-P4x)(P3y-P4y) - // lambda = ------------------------------------- - // (P1x-P2x)(P3y-P4y)-(P1y-P2y)(P3x-P4x) - // - // Intersection point IP is now - // IP = P2 + lambda(P1-P2) - // - const double nominator( (P2y-P4y)*(P3x-P4x) - (P2x-P4x)*(P3y-P4y) ); - const double denominator( (P1x-P2x)*(P3y-P4y) - (P1y-P2y)*(P3x-P4x) ); - const double lambda( nominator / denominator ); - - const double IPx( P2x + lambda*( P1x - P2x) ); - const double IPy( P2y + lambda*( P1y - P2y) ); - - // Introduce some alias names: quadratic start point is P1, end - // point is P4, control point is IP - const double QP1x( P1x ); - const double QP1y( P1y ); - const double QP2x( IPx ); - const double QP2y( IPy ); - const double QP3x( P4x ); - const double QP3y( P4y ); - - // Adapted bezier flatness test (lecture notes from R. Schaback, + // Maybe subdivide further + + // This is for robustness reasons, since the line intersection + // method below gets instable if the curve gets closer to a + // straight line. If the given cubic bezier does not deviate by + // more than d/4 from a straight line, either: + // - take the line (that's what we do here) + // - express the line by a quadratic bezier + + // Perform bezier flatness test (lecture notes from R. Schaback, // Mathematics of Computer-Aided Design, Uni Goettingen, 2000) // - // ||C(t) - Q(t)|| <= max ||c_j - q_j|| + // ||P(t) - L(t)|| <= max ||b_j - b_0 - j/n(b_n - b_0)|| // 0<=j<=n // - // In this case, we don't need the distance from the cubic bezier - // to a straight line, but to a quadratic bezier. The c_j's are - // the cubic bezier's bernstein coefficients, the q_j's the - // quadratic bezier's. We have the c_j's given, the q_j's can be - // calculated from QPi like this (sorry, mixed index notation, we - // use [1,n], formulas use [0,n-1]): - // - // q_0 = QP1 = P1 - // q_1 = 1/3 QP1 + 2/3 QP2 - // q_2 = 2/3 QP2 + 1/3 QP3 - // q_3 = QP3 = P4 - // - // We can drop case 0 and 3, since there the curves coincide - // (distance is zero) - - // calculate argument of max for j=1 and j=2 - const double fJ1x( P2x - 1.0/3.0*QP1x - 2.0/3.0*QP2x ); - const double fJ1y( P2y - 1.0/3.0*QP1y - 2.0/3.0*QP2y ); - const double fJ2x( P3x - 2.0/3.0*QP2x - 1.0/3.0*QP3x ); - const double fJ2y( P3y - 2.0/3.0*QP2y - 1.0/3.0*QP3y ); - - // stop if distance from cubic curve is guaranteed to be bounded by d - // Should denominator be 0: then P1P2 and P3P4 are parallel (P1P2^T R[90,P3P4] = 0.0), - // meaning that either we have a straight line or an inflexion point (see else block below) - if( 0.0 != denominator && - ::std::max( fJ1x*fJ1x + fJ1y*fJ1y, - fJ2x*fJ2x + fJ2y*fJ2y) < d2 ) + // What is calculated here is an upper bound to the distance from + // a line through b_0 and b_3 (P1 and P4 in our notation) and the + // curve. We can drop 0 and n from the running indices, since the + // argument of max becomes zero for those cases. + const double fJ1x( P2x - P1x - 1.0/3.0*(P4x - P1x) ); + const double fJ1y( P2y - P1y - 1.0/3.0*(P4y - P1y) ); + const double fJ2x( P3x - P1x - 2.0/3.0*(P4x - P1x) ); + const double fJ2y( P3y - P1y - 2.0/3.0*(P4y - P1y) ); + + // stop if distance from line is guaranteed to be bounded by d/4 + if( ::std::max( fJ1x*fJ1x + fJ1y*fJ1y, + fJ2x*fJ2x + fJ2y*fJ2y) < d2/16.0 ) { - // requested resolution reached. - // Add end points to output file. - // order is preserved, since this is so to say depth first traversal. - Impl_addQuadBezier( rBits, rLastPoint, - QP2x, QP2y, - QP3x, QP3y); + // do not subdivide further, add straight line instead + Impl_addStraightLine( rBits, rLastPoint, P4x, P4y); } else { - // Maybe subdivide further - - // This is for robustness reasons, since the line intersection - // method below gets instable if the curve gets closer to a - // straight line. If the given cubic bezier does not deviate by - // more than d/4 from a straight line, either: - // - take the line (that's what we do here) - // - express the line by a quadratic bezier - - // Perform bezier flatness test (lecture notes from R. Schaback, - // Mathematics of Computer-Aided Design, Uni Goettingen, 2000) - // - // ||P(t) - L(t)|| <= max ||b_j - b_0 - j/n(b_n - b_0)|| - // 0<=j<=n - // - // What is calculated here is an upper bound to the distance from - // a line through b_0 and b_3 (P1 and P4 in our notation) and the - // curve. We can drop 0 and n from the running indices, since the - // argument of max becomes zero for those cases. - const double fJ1x( P2x - P1x - 1.0/3.0*(P4x - P1x) ); - const double fJ1y( P2y - P1y - 1.0/3.0*(P4y - P1y) ); - const double fJ2x( P3x - P1x - 2.0/3.0*(P4x - P1x) ); - const double fJ2y( P3y - P1y - 2.0/3.0*(P4y - P1y) ); - - // stop if distance from line is guaranteed to be bounded by d/4 - if( ::std::max( fJ1x*fJ1x + fJ1y*fJ1y, - fJ2x*fJ2x + fJ2y*fJ2y) < d2/16.0 ) - { - // do not subdivide further, add straight line instead - Impl_addStraightLine( rBits, rLastPoint, P4x, P4y); - } - else - { - // deCasteljau bezier arc, split at t=0.5 - // Foley/vanDam, p. 508 - const double L1x( P1x ), L1y( P1y ); - const double L2x( (P1x + P2x)*0.5 ), L2y( (P1y + P2y)*0.5 ); - const double Hx ( (P2x + P3x)*0.5 ), Hy ( (P2y + P3y)*0.5 ); - const double L3x( (L2x + Hx)*0.5 ), L3y( (L2y + Hy)*0.5 ); - const double R4x( P4x ), R4y( P4y ); - const double R3x( (P3x + P4x)*0.5 ), R3y( (P3y + P4y)*0.5 ); - const double R2x( (Hx + R3x)*0.5 ), R2y( (Hy + R3y)*0.5 ); - const double R1x( (L3x + R2x)*0.5 ), R1y( (L3y + R2y)*0.5 ); - const double L4x( R1x ), L4y( R1y ); - - // subdivide further - Impl_quadBezierApprox(rBits, rLastPoint, d2, L1x, L1y, L2x, L2y, L3x, L3y, L4x, L4y); - Impl_quadBezierApprox(rBits, rLastPoint, d2, R1x, R1y, R2x, R2y, R3x, R3y, R4x, R4y); - } + // deCasteljau bezier arc, split at t=0.5 + // Foley/vanDam, p. 508 + const double L1x( P1x ), L1y( P1y ); + const double L2x( (P1x + P2x)*0.5 ), L2y( (P1y + P2y)*0.5 ); + const double Hx ( (P2x + P3x)*0.5 ), Hy ( (P2y + P3y)*0.5 ); + const double L3x( (L2x + Hx)*0.5 ), L3y( (L2y + Hy)*0.5 ); + const double R4x( P4x ), R4y( P4y ); + const double R3x( (P3x + P4x)*0.5 ), R3y( (P3y + P4y)*0.5 ); + const double R2x( (Hx + R3x)*0.5 ), R2y( (Hy + R3y)*0.5 ); + const double R1x( (L3x + R2x)*0.5 ), R1y( (L3y + R2y)*0.5 ); + const double L4x( R1x ), L4y( R1y ); + + // subdivide further + Impl_quadBezierApprox(rBits, rLastPoint, d2, L1x, L1y, L2x, L2y, L3x, L3y, L4x, L4y); + Impl_quadBezierApprox(rBits, rLastPoint, d2, R1x, R1y, R2x, R2y, R3x, R3y, R4x, R4y); } } } -#endif - } - - sal_Int32 adaptiveSubdivideByDistance( polygon::B2DPolygon& rPoly, - const B2DCubicBezier& rCurve, - double distanceBounds ) - { - const point::B2DPoint start( rCurve.getStartPoint() ); - const point::B2DPoint control1( rCurve.getControlPointA() ); - const point::B2DPoint control2( rCurve.getControlPointB() ); - const point::B2DPoint end( rCurve.getEndPoint() ); - - return ImplAdaptiveSubdivide( rPoly, - DistanceErrorFunctor( distanceBounds ), - start.getX(), start.getY(), - control1.getX(), control1.getY(), - control2.getX(), control2.getY(), - end.getX(), end.getY(), - 0 ); } +#endif + } - sal_Int32 adaptiveSubdivideByAngle( polygon::B2DPolygon& rPoly, + sal_Int32 adaptiveSubdivideByDistance( B2DPolygon& rPoly, const B2DCubicBezier& rCurve, - double angleBounds ) - { - const point::B2DPoint start( rCurve.getStartPoint() ); - const point::B2DPoint control1( rCurve.getControlPointA() ); - const point::B2DPoint control2( rCurve.getControlPointB() ); - const point::B2DPoint end( rCurve.getEndPoint() ); - - return ImplAdaptiveSubdivide( rPoly, - AngleErrorFunctor( angleBounds ), - start.getX(), start.getY(), - control1.getX(), control1.getY(), - control2.getX(), control2.getY(), - end.getX(), end.getY(), - 0 ); - } + double distanceBounds ) + { + const B2DPoint start( rCurve.getStartPoint() ); + const B2DPoint control1( rCurve.getControlPointA() ); + const B2DPoint control2( rCurve.getControlPointB() ); + const B2DPoint end( rCurve.getEndPoint() ); + + return ImplAdaptiveSubdivide( rPoly, + DistanceErrorFunctor( distanceBounds ), + start.getX(), start.getY(), + control1.getX(), control1.getY(), + control2.getX(), control2.getY(), + end.getX(), end.getY(), + 0 ); + } - sal_Int32 adaptiveSubdivideByDistance( polygon::B2DPolygon& rPoly, - const B2DQuadraticBezier& rCurve, - double distanceBounds ) - { - // TODO - return 0; - } + sal_Int32 adaptiveSubdivideByAngle( B2DPolygon& rPoly, + const B2DCubicBezier& rCurve, + double angleBounds ) + { + const B2DPoint start( rCurve.getStartPoint() ); + const B2DPoint control1( rCurve.getControlPointA() ); + const B2DPoint control2( rCurve.getControlPointB() ); + const B2DPoint end( rCurve.getEndPoint() ); + + return ImplAdaptiveSubdivide( rPoly, + AngleErrorFunctor( angleBounds ), + start.getX(), start.getY(), + control1.getX(), control1.getY(), + control2.getX(), control2.getY(), + end.getX(), end.getY(), + 0 ); + } + + sal_Int32 adaptiveSubdivideByDistance( B2DPolygon& rPoly, + const B2DQuadraticBezier& rCurve, + double distanceBounds ) + { + // TODO + return 0; } } diff --git a/basegfx/source/curve/b2dcubicbezier.cxx b/basegfx/source/curve/b2dcubicbezier.cxx index 9633aa6b5130..33f6fdb8f1ca 100644 --- a/basegfx/source/curve/b2dcubicbezier.cxx +++ b/basegfx/source/curve/b2dcubicbezier.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dcubicbezier.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:07 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,90 +67,86 @@ namespace basegfx { - namespace curve + B2DCubicBezier::B2DCubicBezier(const B2DCubicBezier& rBezier) + : maStartPoint(rBezier.maStartPoint), + maEndPoint(rBezier.maEndPoint), + maControlPointA(rBezier.maControlPointA), + maControlPointB(rBezier.maControlPointB) { - B2DCubicBezier::B2DCubicBezier(const B2DCubicBezier& rBezier) - : maStartPoint(rBezier.maStartPoint), - maEndPoint(rBezier.maEndPoint), - maControlPointA(rBezier.maControlPointA), - maControlPointB(rBezier.maControlPointB) - { - } - - B2DCubicBezier::B2DCubicBezier() - { - } - - B2DCubicBezier::B2DCubicBezier(const ::basegfx::point::B2DPoint& rStart, const ::basegfx::point::B2DPoint& rEnd) - : maStartPoint(rStart), - maEndPoint(rEnd), - maControlPointA(rStart), - maControlPointB(rEnd) - { - } + } - B2DCubicBezier::B2DCubicBezier(const ::basegfx::point::B2DPoint& rStart, const ::basegfx::point::B2DPoint& rControlPointA, - const ::basegfx::point::B2DPoint& rControlPointB, const ::basegfx::point::B2DPoint& rEnd) - : maStartPoint(rStart), - maEndPoint(rEnd), - maControlPointA(rControlPointA), - maControlPointB(rControlPointB) - { - } - - B2DCubicBezier::~B2DCubicBezier() - { - } + B2DCubicBezier::B2DCubicBezier() + { + } - // assignment operator - B2DCubicBezier& B2DCubicBezier::operator=(const B2DCubicBezier& rBezier) - { - maStartPoint = rBezier.maStartPoint; - maEndPoint = rBezier.maEndPoint; - maControlPointA = rBezier.maControlPointA; - maControlPointB = rBezier.maControlPointB; + B2DCubicBezier::B2DCubicBezier(const ::basegfx::B2DPoint& rStart, const ::basegfx::B2DPoint& rEnd) + : maStartPoint(rStart), + maEndPoint(rEnd), + maControlPointA(rStart), + maControlPointB(rEnd) + { + } + + B2DCubicBezier::B2DCubicBezier(const ::basegfx::B2DPoint& rStart, const ::basegfx::B2DPoint& rControlPointA, + const ::basegfx::B2DPoint& rControlPointB, const ::basegfx::B2DPoint& rEnd) + : maStartPoint(rStart), + maEndPoint(rEnd), + maControlPointA(rControlPointA), + maControlPointB(rControlPointB) + { + } - return *this; - } + B2DCubicBezier::~B2DCubicBezier() + { + } - // compare operators - sal_Bool B2DCubicBezier::operator==(const B2DCubicBezier& rBezier) const - { - return ( - maStartPoint == rBezier.maStartPoint - && maEndPoint == rBezier.maEndPoint - && maControlPointA == rBezier.maControlPointA - && maControlPointB == rBezier.maControlPointB - ); - } + // assignment operator + B2DCubicBezier& B2DCubicBezier::operator=(const B2DCubicBezier& rBezier) + { + maStartPoint = rBezier.maStartPoint; + maEndPoint = rBezier.maEndPoint; + maControlPointA = rBezier.maControlPointA; + maControlPointB = rBezier.maControlPointB; - sal_Bool B2DCubicBezier::operator!=(const B2DCubicBezier& rBezier) const - { - return ( - maStartPoint != rBezier.maStartPoint - || maEndPoint != rBezier.maEndPoint - || maControlPointA != rBezier.maControlPointA - || maControlPointB != rBezier.maControlPointB - ); - } + return *this; + } - // test if vectors are used - sal_Bool B2DCubicBezier::isBezier() const + // compare operators + sal_Bool B2DCubicBezier::operator==(const B2DCubicBezier& rBezier) const + { + return ( + maStartPoint == rBezier.maStartPoint + && maEndPoint == rBezier.maEndPoint + && maControlPointA == rBezier.maControlPointA + && maControlPointB == rBezier.maControlPointB + ); + } + + sal_Bool B2DCubicBezier::operator!=(const B2DCubicBezier& rBezier) const + { + return ( + maStartPoint != rBezier.maStartPoint + || maEndPoint != rBezier.maEndPoint + || maControlPointA != rBezier.maControlPointA + || maControlPointB != rBezier.maControlPointB + ); + } + + // test if vectors are used + sal_Bool B2DCubicBezier::isBezier() const + { + if(maControlPointA != maStartPoint || maControlPointB != maEndPoint) { - if(maControlPointA != maStartPoint || maControlPointB != maEndPoint) - { - return sal_True; - } - - return sal_False; + return sal_True; } - void B2DCubicBezier::testAndSolveTrivialBezier() - { - // TODO - } + return sal_False; + } - } // end of namespace curve + void B2DCubicBezier::testAndSolveTrivialBezier() + { + // TODO + } } // end of namespace basegfx // eof diff --git a/basegfx/source/curve/b2dquadraticbezier.cxx b/basegfx/source/curve/b2dquadraticbezier.cxx index 607d10b4a7bc..2086a9d1b15e 100644 --- a/basegfx/source/curve/b2dquadraticbezier.cxx +++ b/basegfx/source/curve/b2dquadraticbezier.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dquadraticbezier.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:08 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,75 +71,72 @@ namespace basegfx { - namespace curve + B2DQuadraticBezier::B2DQuadraticBezier(const B2DQuadraticBezier& rBezier) + : maStartPoint(rBezier.maStartPoint), + maEndPoint(rBezier.maEndPoint), + maControlPoint(rBezier.maControlPoint) { - B2DQuadraticBezier::B2DQuadraticBezier(const B2DQuadraticBezier& rBezier) - : maStartPoint(rBezier.maStartPoint), - maEndPoint(rBezier.maEndPoint), - maControlPoint(rBezier.maControlPoint) - { - } + } - B2DQuadraticBezier::B2DQuadraticBezier() - { - } + B2DQuadraticBezier::B2DQuadraticBezier() + { + } - B2DQuadraticBezier::B2DQuadraticBezier(const ::basegfx::point::B2DPoint& rStart, const ::basegfx::point::B2DPoint& rEnd) - : maStartPoint(rStart), - maEndPoint(rEnd) - { - } + B2DQuadraticBezier::B2DQuadraticBezier(const ::basegfx::B2DPoint& rStart, const ::basegfx::B2DPoint& rEnd) + : maStartPoint(rStart), + maEndPoint(rEnd) + { + } - B2DQuadraticBezier::B2DQuadraticBezier(const ::basegfx::point::B2DPoint& rStart, const ::basegfx::point::B2DPoint& rControl, const ::basegfx::point::B2DPoint& rEnd) - : maStartPoint(rStart), - maEndPoint(rEnd), - maControlPoint(rControl) - { - } + B2DQuadraticBezier::B2DQuadraticBezier(const ::basegfx::B2DPoint& rStart, const ::basegfx::B2DPoint& rControl, const ::basegfx::B2DPoint& rEnd) + : maStartPoint(rStart), + maEndPoint(rEnd), + maControlPoint(rControl) + { + } - B2DQuadraticBezier::~B2DQuadraticBezier() - { - } + B2DQuadraticBezier::~B2DQuadraticBezier() + { + } - // assignment operator - B2DQuadraticBezier& B2DQuadraticBezier::operator=(const B2DQuadraticBezier& rBezier) - { - maStartPoint = rBezier.maStartPoint; - maEndPoint = rBezier.maEndPoint; - maControlPoint = rBezier.maControlPoint; + // assignment operator + B2DQuadraticBezier& B2DQuadraticBezier::operator=(const B2DQuadraticBezier& rBezier) + { + maStartPoint = rBezier.maStartPoint; + maEndPoint = rBezier.maEndPoint; + maControlPoint = rBezier.maControlPoint; - return *this; - } + return *this; + } - // compare operators - sal_Bool B2DQuadraticBezier::operator==(const B2DQuadraticBezier& rBezier) const - { - return ( - maStartPoint == rBezier.maStartPoint - && maEndPoint == rBezier.maEndPoint - && maControlPoint == rBezier.maControlPoint - ); - } + // compare operators + sal_Bool B2DQuadraticBezier::operator==(const B2DQuadraticBezier& rBezier) const + { + return ( + maStartPoint == rBezier.maStartPoint + && maEndPoint == rBezier.maEndPoint + && maControlPoint == rBezier.maControlPoint + ); + } - sal_Bool B2DQuadraticBezier::operator!=(const B2DQuadraticBezier& rBezier) const - { - return ( - maStartPoint != rBezier.maStartPoint - || maEndPoint != rBezier.maEndPoint - || maControlPoint != rBezier.maControlPoint - ); - } + sal_Bool B2DQuadraticBezier::operator!=(const B2DQuadraticBezier& rBezier) const + { + return ( + maStartPoint != rBezier.maStartPoint + || maEndPoint != rBezier.maEndPoint + || maControlPoint != rBezier.maControlPoint + ); + } - // test if control vector is used - sal_Bool B2DQuadraticBezier::isBezier() const - { - // if control vector is empty, bezier is not used - if(maControlPoint == maStartPoint || maControlPoint == maEndPoint) - return sal_False; + // test if control vector is used + sal_Bool B2DQuadraticBezier::isBezier() const + { + // if control vector is empty, bezier is not used + if(maControlPoint == maStartPoint || maControlPoint == maEndPoint) + return sal_False; - return sal_True; - } - } // end of namespace curve + return sal_True; + } } // end of namespace basegfx // eof diff --git a/basegfx/source/inc/hommatrixtemplate.hxx b/basegfx/source/inc/hommatrixtemplate.hxx index 9711dd4e3c01..4c688b09a218 100644 --- a/basegfx/source/inc/hommatrixtemplate.hxx +++ b/basegfx/source/inc/hommatrixtemplate.hxx @@ -2,9 +2,9 @@ * * $RCSfile: hommatrixtemplate.hxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: thb $ $Date: 2003-11-10 15:10:41 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -139,7 +139,7 @@ namespace basegfx const double fDefault(implGetDefaultValue((RowSize - 1), a)); const double fLineValue(mpLine->get(a)); - if(!::basegfx::numeric::fTools::equal(fDefault, fLineValue)) + if(!::basegfx::fTools::equal(fDefault, fLineValue)) { return sal_False; } @@ -226,7 +226,7 @@ namespace basegfx { const double fDefault(implGetDefaultValue((RowSize - 1), nColumn)); - if(!::basegfx::numeric::fTools::equal(fDefault, rValue)) + if(!::basegfx::fTools::equal(fDefault, rValue)) { mpLine = new ImplMatLine< RowSize >((RowSize - 1), 0L); mpLine->set(nColumn, rValue); @@ -245,7 +245,7 @@ namespace basegfx const double fDefault(implGetDefaultValue((RowSize - 1), a)); const double fLineValue(mpLine->get(a)); - if(!::basegfx::numeric::fTools::equal(fDefault, fLineValue)) + if(!::basegfx::fTools::equal(fDefault, fLineValue)) { bNecessary = sal_True; } @@ -278,13 +278,13 @@ namespace basegfx { double fTemp(fabs(get(a, b))); - if(::basegfx::numeric::fTools::more(fTemp, fBig)) + if(::basegfx::fTools::more(fTemp, fBig)) { fBig = fTemp; } } - if(::basegfx::numeric::fTools::equalZero(fBig)) + if(::basegfx::fTools::equalZero(fBig)) { return sal_False; } @@ -321,7 +321,7 @@ namespace basegfx set(a, b, fSum); fDum = fStorage[a] * fabs(fSum); - if(::basegfx::numeric::fTools::moreOrEqual(fDum, fBig)) + if(::basegfx::fTools::moreOrEqual(fDum, fBig)) { fBig = fDum; nAMax = a; @@ -346,7 +346,7 @@ namespace basegfx // here the failure of precision occurs const double fValBB(fabs(get(b, b))); - if(::basegfx::numeric::fTools::equalZero(fValBB)) + if(::basegfx::fTools::equalZero(fValBB)) { return sal_False; } @@ -384,7 +384,7 @@ namespace basegfx fSum -= get(a, b) * fRow[b]; } } - else if(!::basegfx::numeric::fTools::equalZero(fSum)) + else if(!::basegfx::fTools::equalZero(fSum)) { a2 = a; } @@ -403,7 +403,7 @@ namespace basegfx const double fValueAA(get(a, a)); - if(!::basegfx::numeric::fTools::equalZero(fValueAA)) + if(!::basegfx::fTools::equalZero(fValueAA)) { fRow[a] = fSum / get(a, a); } @@ -422,7 +422,7 @@ namespace basegfx const double fDefault(implGetDefaultValue(a, b)); const double fValueAB(get(a, b)); - if(!::basegfx::numeric::fTools::equal(fDefault, fValueAB)) + if(!::basegfx::fTools::equal(fDefault, fValueAB)) { return sal_False; } @@ -448,14 +448,14 @@ namespace basegfx const double fHomValue(get((RowSize - 1), (RowSize - 1))); - if(::basegfx::numeric::fTools::equalZero(fHomValue)) + if(::basegfx::fTools::equalZero(fHomValue)) { return sal_True; } const double fOne(1.0); - if(::basegfx::numeric::fTools::equal(fOne, fHomValue)) + if(::basegfx::fTools::equal(fOne, fHomValue)) { return sal_True; } @@ -634,7 +634,7 @@ namespace basegfx const double fValueA(get(a, b)); const double fValueB(rMat.get(a, b)); - if(!::basegfx::numeric::fTools::equal(fValueA, fValueB)) + if(!::basegfx::fTools::equal(fValueA, fValueB)) { return sal_False; } diff --git a/basegfx/source/matrix/b2dhommatrix.cxx b/basegfx/source/matrix/b2dhommatrix.cxx index d2175b502db3..ae36adfd72f9 100644 --- a/basegfx/source/matrix/b2dhommatrix.cxx +++ b/basegfx/source/matrix/b2dhommatrix.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dhommatrix.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: thb $ $Date: 2003-11-10 15:10:57 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -81,336 +81,333 @@ namespace basegfx { - namespace matrix + class Impl2DHomMatrix : public ::basegfx::internal::ImplHomMatrixTemplate< 3 > { - class Impl2DHomMatrix : public ::basegfx::internal::ImplHomMatrixTemplate< 3 > - { - }; + }; - static Impl2DHomMatrix& get2DIdentityMatrix() - { - static Impl2DHomMatrix maStatic2DIdentityHomMatrix; - return maStatic2DIdentityHomMatrix; - } + static Impl2DHomMatrix& get2DIdentityMatrix() + { + static Impl2DHomMatrix maStatic2DIdentityHomMatrix; + return maStatic2DIdentityHomMatrix; + } - void B2DHomMatrix::implPrepareChange() + void B2DHomMatrix::implPrepareChange() + { + if(mpM->getRefCount()) { - if(mpM->getRefCount()) - { - mpM->decRefCount(); - mpM = new Impl2DHomMatrix(*mpM); - } + mpM->decRefCount(); + mpM = new Impl2DHomMatrix(*mpM); } + } - B2DHomMatrix::B2DHomMatrix() - : mpM(&get2DIdentityMatrix()) - { - mpM->incRefCount(); - } + B2DHomMatrix::B2DHomMatrix() + : mpM(&get2DIdentityMatrix()) + { + mpM->incRefCount(); + } - B2DHomMatrix::B2DHomMatrix(const B2DHomMatrix& rMat) - : mpM(rMat.mpM) - { - mpM->incRefCount(); - } + B2DHomMatrix::B2DHomMatrix(const B2DHomMatrix& rMat) + : mpM(rMat.mpM) + { + mpM->incRefCount(); + } - B2DHomMatrix::~B2DHomMatrix() - { - if(mpM->getRefCount()) - mpM->decRefCount(); - else - delete mpM; - } + B2DHomMatrix::~B2DHomMatrix() + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + } - B2DHomMatrix& B2DHomMatrix::operator=(const B2DHomMatrix& rMat) - { - if(mpM->getRefCount()) - mpM->decRefCount(); - else - delete mpM; + B2DHomMatrix& B2DHomMatrix::operator=(const B2DHomMatrix& rMat) + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; - mpM = rMat.mpM; - mpM->incRefCount(); + mpM = rMat.mpM; + mpM->incRefCount(); - return *this; - } + return *this; + } - double B2DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const - { - return mpM->get(nRow, nColumn); - } + double B2DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const + { + return mpM->get(nRow, nColumn); + } - void B2DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue) - { - implPrepareChange(); - mpM->set(nRow, nColumn, fValue); - } + void B2DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue) + { + implPrepareChange(); + mpM->set(nRow, nColumn, fValue); + } - sal_Bool B2DHomMatrix::isIdentity() const - { - if(mpM == &get2DIdentityMatrix()) - return sal_True; + sal_Bool B2DHomMatrix::isIdentity() const + { + if(mpM == &get2DIdentityMatrix()) + return sal_True; - return mpM->isIdentity(); - } + return mpM->isIdentity(); + } - void B2DHomMatrix::identity() + void B2DHomMatrix::identity() + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + + mpM = &get2DIdentityMatrix(); + mpM->incRefCount(); + } + + sal_Bool B2DHomMatrix::isInvertible() const + { + return mpM->isInvertible(); + } + + sal_Bool B2DHomMatrix::invert() + { + Impl2DHomMatrix aWork(*mpM); + sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()]; + sal_Int16 nParity; + + if(aWork.ludcmp(pIndex, nParity)) { - if(mpM->getRefCount()) - mpM->decRefCount(); - else - delete mpM; + implPrepareChange(); + mpM->doInvert(aWork, pIndex); + delete pIndex; - mpM = &get2DIdentityMatrix(); - mpM->incRefCount(); + return sal_True; } - sal_Bool B2DHomMatrix::isInvertible() const + delete pIndex; + return sal_False; + } + + sal_Bool B2DHomMatrix::isNormalized() const + { + return mpM->isNormalized(); + } + + void B2DHomMatrix::normalize() + { + if(!mpM->isNormalized()) { - return mpM->isInvertible(); + implPrepareChange(); + mpM->doNormalize(); } + } - sal_Bool B2DHomMatrix::invert() - { - Impl2DHomMatrix aWork(*mpM); - sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()]; - sal_Int16 nParity; + double B2DHomMatrix::determinant() const + { + return mpM->doDeterminant(); + } - if(aWork.ludcmp(pIndex, nParity)) - { - implPrepareChange(); - mpM->doInvert(aWork, pIndex); - delete pIndex; + double B2DHomMatrix::trace() const + { + return mpM->doTrace(); + } - return sal_True; - } + void B2DHomMatrix::transpose() + { + implPrepareChange(); + mpM->doTranspose(); + } - delete pIndex; - return sal_False; - } + B2DHomMatrix& B2DHomMatrix::operator+=(const B2DHomMatrix& rMat) + { + implPrepareChange(); + mpM->doAddMatrix(*rMat.mpM); - sal_Bool B2DHomMatrix::isNormalized() const - { - return mpM->isNormalized(); - } + return *this; + } - void B2DHomMatrix::normalize() - { - if(!mpM->isNormalized()) - { - implPrepareChange(); - mpM->doNormalize(); - } - } + B2DHomMatrix& B2DHomMatrix::operator-=(const B2DHomMatrix& rMat) + { + implPrepareChange(); + mpM->doSubMatrix(*rMat.mpM); - double B2DHomMatrix::determinant() const - { - return mpM->doDeterminant(); - } + return *this; + } - double B2DHomMatrix::trace() const - { - return mpM->doTrace(); - } + B2DHomMatrix& B2DHomMatrix::operator*=(double fValue) + { + const double fOne(1.0); - void B2DHomMatrix::transpose() + if(!::basegfx::fTools::equal(fOne, fValue)) { implPrepareChange(); - mpM->doTranspose(); + mpM->doMulMatrix(fValue); } - B2DHomMatrix& B2DHomMatrix::operator+=(const B2DHomMatrix& rMat) - { - implPrepareChange(); - mpM->doAddMatrix(*rMat.mpM); + return *this; + } - return *this; - } + B2DHomMatrix& B2DHomMatrix::operator/=(double fValue) + { + const double fOne(1.0); - B2DHomMatrix& B2DHomMatrix::operator-=(const B2DHomMatrix& rMat) + if(!::basegfx::fTools::equal(fOne, fValue)) { implPrepareChange(); - mpM->doSubMatrix(*rMat.mpM); - - return *this; + mpM->doMulMatrix(1.0 / fValue); } - B2DHomMatrix& B2DHomMatrix::operator*=(double fValue) - { - const double fOne(1.0); - - if(!::basegfx::numeric::fTools::equal(fOne, fValue)) - { - implPrepareChange(); - mpM->doMulMatrix(fValue); - } + return *this; + } - return *this; - } - - B2DHomMatrix& B2DHomMatrix::operator/=(double fValue) + B2DHomMatrix& B2DHomMatrix::operator*=(const B2DHomMatrix& rMat) + { + if(!rMat.isIdentity()) { - const double fOne(1.0); - - if(!::basegfx::numeric::fTools::equal(fOne, fValue)) - { - implPrepareChange(); - mpM->doMulMatrix(1.0 / fValue); - } - - return *this; + implPrepareChange(); + mpM->doMulMatrix(*rMat.mpM); } - B2DHomMatrix& B2DHomMatrix::operator*=(const B2DHomMatrix& rMat) - { - if(!rMat.isIdentity()) - { - implPrepareChange(); - mpM->doMulMatrix(*rMat.mpM); - } + return *this; + } - return *this; - } + sal_Bool B2DHomMatrix::operator==(const B2DHomMatrix& rMat) const + { + if(mpM == rMat.mpM) + return sal_True; - sal_Bool B2DHomMatrix::operator==(const B2DHomMatrix& rMat) const - { - if(mpM == rMat.mpM) - return sal_True; + return mpM->isEqual(*rMat.mpM); + } - return mpM->isEqual(*rMat.mpM); - } + sal_Bool B2DHomMatrix::operator!=(const B2DHomMatrix& rMat) const + { + if(mpM == rMat.mpM) + return sal_False; + + return !mpM->isEqual(*rMat.mpM); + } - sal_Bool B2DHomMatrix::operator!=(const B2DHomMatrix& rMat) const + void B2DHomMatrix::rotate(double fRadiant) + { + if(!::basegfx::fTools::equalZero(fRadiant)) { - if(mpM == rMat.mpM) - return sal_False; + Impl2DHomMatrix aRotMat(get2DIdentityMatrix()); + double fSin(sin(fRadiant)); + double fCos(cos(fRadiant)); - return !mpM->isEqual(*rMat.mpM); - } + aRotMat.set(0, 0, fCos); + aRotMat.set(1, 1, fCos); + aRotMat.set(1, 0, fSin); + aRotMat.set(0, 1, -fSin); - void B2DHomMatrix::rotate(double fRadiant) - { - if(!::basegfx::numeric::fTools::equalZero(fRadiant)) - { - Impl2DHomMatrix aRotMat(get2DIdentityMatrix()); - double fSin(sin(fRadiant)); - double fCos(cos(fRadiant)); - - aRotMat.set(0, 0, fCos); - aRotMat.set(1, 1, fCos); - aRotMat.set(1, 0, fSin); - aRotMat.set(0, 1, -fSin); - - implPrepareChange(); - mpM->doMulMatrix(aRotMat); - } + implPrepareChange(); + mpM->doMulMatrix(aRotMat); } + } - void B2DHomMatrix::translate(double fX, double fY) + void B2DHomMatrix::translate(double fX, double fY) + { + if(!::basegfx::fTools::equalZero(fX) || !::basegfx::fTools::equalZero(fY)) { - if(!::basegfx::numeric::fTools::equalZero(fX) || !::basegfx::numeric::fTools::equalZero(fY)) - { - Impl2DHomMatrix aTransMat(get2DIdentityMatrix()); + Impl2DHomMatrix aTransMat(get2DIdentityMatrix()); - aTransMat.set(0, 2, fX); - aTransMat.set(1, 2, fY); + aTransMat.set(0, 2, fX); + aTransMat.set(1, 2, fY); - implPrepareChange(); - mpM->doMulMatrix(aTransMat); - } + implPrepareChange(); + mpM->doMulMatrix(aTransMat); } + } - void B2DHomMatrix::scale(double fX, double fY) - { - const double fOne(1.0); + void B2DHomMatrix::scale(double fX, double fY) + { + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equal(fOne, fX) || !::basegfx::numeric::fTools::equal(fOne, fY)) - { - Impl2DHomMatrix aScaleMat(get2DIdentityMatrix()); + if(!::basegfx::fTools::equal(fOne, fX) || !::basegfx::fTools::equal(fOne, fY)) + { + Impl2DHomMatrix aScaleMat(get2DIdentityMatrix()); - aScaleMat.set(0, 0, fX); - aScaleMat.set(1, 1, fY); + aScaleMat.set(0, 0, fX); + aScaleMat.set(1, 1, fY); - implPrepareChange(); - mpM->doMulMatrix(aScaleMat); - } + implPrepareChange(); + mpM->doMulMatrix(aScaleMat); } + } - void B2DHomMatrix::shearX(double fSx) - { - const double fOne(1.0); + void B2DHomMatrix::shearX(double fSx) + { + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equal(fOne, fSx)) - { - Impl2DHomMatrix aShearXMat(get2DIdentityMatrix()); + if(!::basegfx::fTools::equal(fOne, fSx)) + { + Impl2DHomMatrix aShearXMat(get2DIdentityMatrix()); - aShearXMat.set(0, 1, fSx); + aShearXMat.set(0, 1, fSx); - implPrepareChange(); - mpM->doMulMatrix(aShearXMat); - } + implPrepareChange(); + mpM->doMulMatrix(aShearXMat); } + } - void B2DHomMatrix::shearY(double fSy) - { - const double fOne(1.0); + void B2DHomMatrix::shearY(double fSy) + { + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equal(fOne, fSy)) - { - Impl2DHomMatrix aShearYMat(get2DIdentityMatrix()); + if(!::basegfx::fTools::equal(fOne, fSy)) + { + Impl2DHomMatrix aShearYMat(get2DIdentityMatrix()); - aShearYMat.set(1, 0, fSy); + aShearYMat.set(1, 0, fSy); - implPrepareChange(); - mpM->doMulMatrix(aShearYMat); - } + implPrepareChange(); + mpM->doMulMatrix(aShearYMat); } + } - // Decomposition - sal_Bool B2DHomMatrix::decompose(tuple::B2DTuple& rScale, tuple::B2DTuple& rTranslate, double& rRotate, double& rShearX) const - { - // when perspective is used, decompose is not made here - if(!mpM->isLastLineDefault()) - return sal_False; - - // If determinant is zero, decomposition is not possible - if(0.0 == mpM->doDeterminant()) - return sal_False; + // Decomposition + sal_Bool B2DHomMatrix::decompose(B2DTuple& rScale, B2DTuple& rTranslate, double& rRotate, double& rShearX) const + { + // when perspective is used, decompose is not made here + if(!mpM->isLastLineDefault()) + return sal_False; - // copy 2x2 matrix and translate vector to 3x3 matrix - ::basegfx::matrix::B3DHomMatrix a3DHomMat; + // If determinant is zero, decomposition is not possible + if(0.0 == mpM->doDeterminant()) + return sal_False; - a3DHomMat.set(0, 0, get(0, 0)); - a3DHomMat.set(0, 1, get(0, 1)); - a3DHomMat.set(1, 0, get(1, 0)); - a3DHomMat.set(1, 1, get(1, 1)); - a3DHomMat.set(0, 2, get(0, 3)); - a3DHomMat.set(1, 2, get(1, 3)); + // copy 2x2 matrix and translate vector to 3x3 matrix + ::basegfx::B3DHomMatrix a3DHomMat; - ::basegfx::tuple::B3DTuple r3DScale, r3DTranslate, r3DRotate, r3DShear; + a3DHomMat.set(0, 0, get(0, 0)); + a3DHomMat.set(0, 1, get(0, 1)); + a3DHomMat.set(1, 0, get(1, 0)); + a3DHomMat.set(1, 1, get(1, 1)); + a3DHomMat.set(0, 2, get(0, 3)); + a3DHomMat.set(1, 2, get(1, 3)); - if(a3DHomMat.decompose(r3DScale, r3DTranslate, r3DRotate, r3DShear)) - { - // copy scale values - rScale.setX(r3DScale.getX()); - rScale.setY(r3DScale.getY()); + ::basegfx::B3DTuple r3DScale, r3DTranslate, r3DRotate, r3DShear; - // copy shear - rShearX = r3DShear.getX(); + if(a3DHomMat.decompose(r3DScale, r3DTranslate, r3DRotate, r3DShear)) + { + // copy scale values + rScale.setX(r3DScale.getX()); + rScale.setY(r3DScale.getY()); - // copy rotate - rRotate = r3DRotate.getZ(); + // copy shear + rShearX = r3DShear.getX(); - // copy translate - rTranslate.setX(r3DTranslate.getX()); - rTranslate.setY(r3DTranslate.getY()); + // copy rotate + rRotate = r3DRotate.getZ(); - return sal_True; - } + // copy translate + rTranslate.setX(r3DTranslate.getX()); + rTranslate.setY(r3DTranslate.getY()); - return sal_False; + return sal_True; } - } // end of namespace matrix + + return sal_False; + } } // end of namespace basegfx // eof diff --git a/basegfx/source/matrix/b3dhommatrix.cxx b/basegfx/source/matrix/b3dhommatrix.cxx index dee47579741f..b6df9ff51767 100644 --- a/basegfx/source/matrix/b3dhommatrix.cxx +++ b/basegfx/source/matrix/b3dhommatrix.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dhommatrix.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: thb $ $Date: 2003-11-10 15:10:57 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:03 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -73,567 +73,564 @@ namespace basegfx { - namespace matrix + class Impl3DHomMatrix : public ::basegfx::internal::ImplHomMatrixTemplate< 4 > { - class Impl3DHomMatrix : public ::basegfx::internal::ImplHomMatrixTemplate< 4 > - { - }; + }; - static Impl3DHomMatrix& get3DIdentityMatrix() - { - static Impl3DHomMatrix maStatic3DIdentityHomMatrix; - return maStatic3DIdentityHomMatrix; - } + static Impl3DHomMatrix& get3DIdentityMatrix() + { + static Impl3DHomMatrix maStatic3DIdentityHomMatrix; + return maStatic3DIdentityHomMatrix; + } - void B3DHomMatrix::implPrepareChange() + void B3DHomMatrix::implPrepareChange() + { + if(mpM->getRefCount()) { - if(mpM->getRefCount()) - { - mpM->decRefCount(); - mpM = new Impl3DHomMatrix(*mpM); - } + mpM->decRefCount(); + mpM = new Impl3DHomMatrix(*mpM); } + } - B3DHomMatrix::B3DHomMatrix() - : mpM(&get3DIdentityMatrix()) - { - mpM->incRefCount(); - } + B3DHomMatrix::B3DHomMatrix() + : mpM(&get3DIdentityMatrix()) + { + mpM->incRefCount(); + } - B3DHomMatrix::B3DHomMatrix(const B3DHomMatrix& rMat) - : mpM(rMat.mpM) - { - mpM->incRefCount(); - } + B3DHomMatrix::B3DHomMatrix(const B3DHomMatrix& rMat) + : mpM(rMat.mpM) + { + mpM->incRefCount(); + } - B3DHomMatrix::~B3DHomMatrix() - { - if(mpM->getRefCount()) - mpM->decRefCount(); - else - delete mpM; - } + B3DHomMatrix::~B3DHomMatrix() + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + } - B3DHomMatrix& B3DHomMatrix::operator=(const B3DHomMatrix& rMat) - { - if(mpM->getRefCount()) - mpM->decRefCount(); - else - delete mpM; + B3DHomMatrix& B3DHomMatrix::operator=(const B3DHomMatrix& rMat) + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; - mpM = rMat.mpM; - mpM->incRefCount(); + mpM = rMat.mpM; + mpM->incRefCount(); - return *this; - } + return *this; + } - double B3DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const - { - return mpM->get(nRow, nColumn); - } + double B3DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const + { + return mpM->get(nRow, nColumn); + } - void B3DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue) - { - implPrepareChange(); - mpM->set(nRow, nColumn, fValue); - } + void B3DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue) + { + implPrepareChange(); + mpM->set(nRow, nColumn, fValue); + } - sal_Bool B3DHomMatrix::isIdentity() const - { - if(mpM == &get3DIdentityMatrix()) - return sal_True; + sal_Bool B3DHomMatrix::isIdentity() const + { + if(mpM == &get3DIdentityMatrix()) + return sal_True; - return mpM->isIdentity(); - } + return mpM->isIdentity(); + } + + void B3DHomMatrix::identity() + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + + mpM = &get3DIdentityMatrix(); + mpM->incRefCount(); + } + + sal_Bool B3DHomMatrix::isInvertible() const + { + return mpM->isInvertible(); + } + + sal_Bool B3DHomMatrix::invert() + { + Impl3DHomMatrix aWork(*mpM); + sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()]; + sal_Int16 nParity; - void B3DHomMatrix::identity() + if(aWork.ludcmp(pIndex, nParity)) { - if(mpM->getRefCount()) - mpM->decRefCount(); - else - delete mpM; + implPrepareChange(); + mpM->doInvert(aWork, pIndex); + delete pIndex; - mpM = &get3DIdentityMatrix(); - mpM->incRefCount(); + return sal_True; } - sal_Bool B3DHomMatrix::isInvertible() const + delete pIndex; + return sal_False; + } + + sal_Bool B3DHomMatrix::isNormalized() const + { + return mpM->isNormalized(); + } + + void B3DHomMatrix::normalize() + { + if(!mpM->isNormalized()) { - return mpM->isInvertible(); + implPrepareChange(); + mpM->doNormalize(); } + } - sal_Bool B3DHomMatrix::invert() - { - Impl3DHomMatrix aWork(*mpM); - sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()]; - sal_Int16 nParity; + double B3DHomMatrix::determinant() const + { + return mpM->doDeterminant(); + } - if(aWork.ludcmp(pIndex, nParity)) - { - implPrepareChange(); - mpM->doInvert(aWork, pIndex); - delete pIndex; + double B3DHomMatrix::trace() const + { + return mpM->doTrace(); + } - return sal_True; - } + void B3DHomMatrix::transpose() + { + implPrepareChange(); + mpM->doTranspose(); + } - delete pIndex; - return sal_False; - } + B3DHomMatrix& B3DHomMatrix::operator+=(const B3DHomMatrix& rMat) + { + implPrepareChange(); + mpM->doAddMatrix(*rMat.mpM); - sal_Bool B3DHomMatrix::isNormalized() const - { - return mpM->isNormalized(); - } + return *this; + } - void B3DHomMatrix::normalize() - { - if(!mpM->isNormalized()) - { - implPrepareChange(); - mpM->doNormalize(); - } - } + B3DHomMatrix& B3DHomMatrix::operator-=(const B3DHomMatrix& rMat) + { + implPrepareChange(); + mpM->doSubMatrix(*rMat.mpM); - double B3DHomMatrix::determinant() const - { - return mpM->doDeterminant(); - } + return *this; + } - double B3DHomMatrix::trace() const - { - return mpM->doTrace(); - } + B3DHomMatrix& B3DHomMatrix::operator*=(double fValue) + { + const double fOne(1.0); - void B3DHomMatrix::transpose() + if(!::basegfx::fTools::equal(fOne, fValue)) { implPrepareChange(); - mpM->doTranspose(); + mpM->doMulMatrix(fValue); } - B3DHomMatrix& B3DHomMatrix::operator+=(const B3DHomMatrix& rMat) + return *this; + } + + B3DHomMatrix& B3DHomMatrix::operator/=(double fValue) + { + const double fOne(1.0); + + if(!::basegfx::fTools::equal(fOne, fValue)) { implPrepareChange(); - mpM->doAddMatrix(*rMat.mpM); - - return *this; + mpM->doMulMatrix(1.0 / fValue); } - B3DHomMatrix& B3DHomMatrix::operator-=(const B3DHomMatrix& rMat) + return *this; + } + + B3DHomMatrix& B3DHomMatrix::operator*=(const B3DHomMatrix& rMat) + { + if(!rMat.isIdentity()) { implPrepareChange(); - mpM->doSubMatrix(*rMat.mpM); - - return *this; + mpM->doMulMatrix(*rMat.mpM); } - B3DHomMatrix& B3DHomMatrix::operator*=(double fValue) - { - const double fOne(1.0); + return *this; + } - if(!::basegfx::numeric::fTools::equal(fOne, fValue)) - { - implPrepareChange(); - mpM->doMulMatrix(fValue); - } + sal_Bool B3DHomMatrix::operator==(const B3DHomMatrix& rMat) const + { + if(mpM == rMat.mpM) + return sal_True; - return *this; - } + return mpM->isEqual(*rMat.mpM); + } + + sal_Bool B3DHomMatrix::operator!=(const B3DHomMatrix& rMat) const + { + if(mpM == rMat.mpM) + return sal_False; - B3DHomMatrix& B3DHomMatrix::operator/=(double fValue) + return !mpM->isEqual(*rMat.mpM); + } + + void B3DHomMatrix::rotate(double fAngleX,double fAngleY,double fAngleZ) + { + if(!::basegfx::fTools::equalZero(fAngleX) || !::basegfx::fTools::equalZero(fAngleY) || !::basegfx::fTools::equalZero(fAngleZ)) { - const double fOne(1.0); + implPrepareChange(); - if(!::basegfx::numeric::fTools::equal(fOne, fValue)) + if(!::basegfx::fTools::equalZero(fAngleX)) { - implPrepareChange(); - mpM->doMulMatrix(1.0 / fValue); - } + Impl3DHomMatrix aRotMatX(get3DIdentityMatrix()); + double fSin(sin(fAngleX)); + double fCos(cos(fAngleX)); - return *this; - } + aRotMatX.set(1, 1, fCos); + aRotMatX.set(2, 2, fCos); + aRotMatX.set(2, 1, fSin); + aRotMatX.set(1, 2, -fSin); - B3DHomMatrix& B3DHomMatrix::operator*=(const B3DHomMatrix& rMat) - { - if(!rMat.isIdentity()) - { - implPrepareChange(); - mpM->doMulMatrix(*rMat.mpM); + mpM->doMulMatrix(aRotMatX); } - return *this; - } + if(!::basegfx::fTools::equalZero(fAngleY)) + { + Impl3DHomMatrix aRotMatY(get3DIdentityMatrix()); + double fSin(sin(fAngleY)); + double fCos(cos(fAngleY)); - sal_Bool B3DHomMatrix::operator==(const B3DHomMatrix& rMat) const - { - if(mpM == rMat.mpM) - return sal_True; + aRotMatY.set(0, 0, fCos); + aRotMatY.set(2, 2, fCos); + aRotMatY.set(0, 2, fSin); + aRotMatY.set(2, 0, -fSin); - return mpM->isEqual(*rMat.mpM); - } + mpM->doMulMatrix(aRotMatY); + } - sal_Bool B3DHomMatrix::operator!=(const B3DHomMatrix& rMat) const - { - if(mpM == rMat.mpM) - return sal_False; + if(!::basegfx::fTools::equalZero(fAngleZ)) + { + Impl3DHomMatrix aRotMatZ(get3DIdentityMatrix()); + double fSin(sin(fAngleZ)); + double fCos(cos(fAngleZ)); - return !mpM->isEqual(*rMat.mpM); - } + aRotMatZ.set(0, 0, fCos); + aRotMatZ.set(1, 1, fCos); + aRotMatZ.set(1, 0, fSin); + aRotMatZ.set(0, 1, -fSin); - void B3DHomMatrix::rotate(double fAngleX,double fAngleY,double fAngleZ) - { - if(!::basegfx::numeric::fTools::equalZero(fAngleX) || !::basegfx::numeric::fTools::equalZero(fAngleY) || !::basegfx::numeric::fTools::equalZero(fAngleZ)) - { - implPrepareChange(); - - if(!::basegfx::numeric::fTools::equalZero(fAngleX)) - { - Impl3DHomMatrix aRotMatX(get3DIdentityMatrix()); - double fSin(sin(fAngleX)); - double fCos(cos(fAngleX)); - - aRotMatX.set(1, 1, fCos); - aRotMatX.set(2, 2, fCos); - aRotMatX.set(2, 1, fSin); - aRotMatX.set(1, 2, -fSin); - - mpM->doMulMatrix(aRotMatX); - } - - if(!::basegfx::numeric::fTools::equalZero(fAngleY)) - { - Impl3DHomMatrix aRotMatY(get3DIdentityMatrix()); - double fSin(sin(fAngleY)); - double fCos(cos(fAngleY)); - - aRotMatY.set(0, 0, fCos); - aRotMatY.set(2, 2, fCos); - aRotMatY.set(0, 2, fSin); - aRotMatY.set(2, 0, -fSin); - - mpM->doMulMatrix(aRotMatY); - } - - if(!::basegfx::numeric::fTools::equalZero(fAngleZ)) - { - Impl3DHomMatrix aRotMatZ(get3DIdentityMatrix()); - double fSin(sin(fAngleZ)); - double fCos(cos(fAngleZ)); - - aRotMatZ.set(0, 0, fCos); - aRotMatZ.set(1, 1, fCos); - aRotMatZ.set(1, 0, fSin); - aRotMatZ.set(0, 1, -fSin); - - mpM->doMulMatrix(aRotMatZ); - } + mpM->doMulMatrix(aRotMatZ); } } + } - void B3DHomMatrix::translate(double fX, double fY, double fZ) + void B3DHomMatrix::translate(double fX, double fY, double fZ) + { + if(!::basegfx::fTools::equalZero(fX) || !::basegfx::fTools::equalZero(fY) || !::basegfx::fTools::equalZero(fZ)) { - if(!::basegfx::numeric::fTools::equalZero(fX) || !::basegfx::numeric::fTools::equalZero(fY) || !::basegfx::numeric::fTools::equalZero(fZ)) - { - Impl3DHomMatrix aTransMat(get3DIdentityMatrix()); + Impl3DHomMatrix aTransMat(get3DIdentityMatrix()); - aTransMat.set(0, 2, fX); - aTransMat.set(1, 2, fY); - aTransMat.set(2, 2, fZ); + aTransMat.set(0, 2, fX); + aTransMat.set(1, 2, fY); + aTransMat.set(2, 2, fZ); - implPrepareChange(); - mpM->doMulMatrix(aTransMat); - } + implPrepareChange(); + mpM->doMulMatrix(aTransMat); } + } - void B3DHomMatrix::scale(double fX, double fY, double fZ) - { - const double fOne(1.0); + void B3DHomMatrix::scale(double fX, double fY, double fZ) + { + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equal(fOne, fX) || !::basegfx::numeric::fTools::equal(fOne, fY) ||!::basegfx::numeric::fTools::equal(fOne, fZ)) - { - Impl3DHomMatrix aScaleMat(get3DIdentityMatrix()); + if(!::basegfx::fTools::equal(fOne, fX) || !::basegfx::fTools::equal(fOne, fY) ||!::basegfx::fTools::equal(fOne, fZ)) + { + Impl3DHomMatrix aScaleMat(get3DIdentityMatrix()); - aScaleMat.set(0, 0, fX); - aScaleMat.set(1, 1, fY); - aScaleMat.set(2, 2, fZ); + aScaleMat.set(0, 0, fX); + aScaleMat.set(1, 1, fY); + aScaleMat.set(2, 2, fZ); - implPrepareChange(); - mpM->doMulMatrix(aScaleMat); - } + implPrepareChange(); + mpM->doMulMatrix(aScaleMat); } + } - void B3DHomMatrix::shearXY(double fSx, double fSy) - { - const double fOne(1.0); + void B3DHomMatrix::shearXY(double fSx, double fSy) + { + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equal(fOne, fSx) || !::basegfx::numeric::fTools::equal(fOne, fSy)) - { - Impl3DHomMatrix aShearXYMat(get3DIdentityMatrix()); + if(!::basegfx::fTools::equal(fOne, fSx) || !::basegfx::fTools::equal(fOne, fSy)) + { + Impl3DHomMatrix aShearXYMat(get3DIdentityMatrix()); - aShearXYMat.set(0, 2, fSx); - aShearXYMat.set(1, 2, fSy); + aShearXYMat.set(0, 2, fSx); + aShearXYMat.set(1, 2, fSy); - implPrepareChange(); - mpM->doMulMatrix(aShearXYMat); - } + implPrepareChange(); + mpM->doMulMatrix(aShearXYMat); } + } - void B3DHomMatrix::shearYZ(double fSy, double fSz) - { - const double fOne(1.0); + void B3DHomMatrix::shearYZ(double fSy, double fSz) + { + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equal(fOne, fSy) || !::basegfx::numeric::fTools::equal(fOne, fSz)) - { - Impl3DHomMatrix aShearYZMat(get3DIdentityMatrix()); + if(!::basegfx::fTools::equal(fOne, fSy) || !::basegfx::fTools::equal(fOne, fSz)) + { + Impl3DHomMatrix aShearYZMat(get3DIdentityMatrix()); - aShearYZMat.set(1, 0, fSy); - aShearYZMat.set(2, 0, fSz); + aShearYZMat.set(1, 0, fSy); + aShearYZMat.set(2, 0, fSz); - implPrepareChange(); - mpM->doMulMatrix(aShearYZMat); - } + implPrepareChange(); + mpM->doMulMatrix(aShearYZMat); } + } - void B3DHomMatrix::shearXZ(double fSx, double fSz) - { - const double fOne(1.0); + void B3DHomMatrix::shearXZ(double fSx, double fSz) + { + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equal(fOne, fSx) || !::basegfx::numeric::fTools::equal(fOne, fSz)) - { - Impl3DHomMatrix aShearXZMat(get3DIdentityMatrix()); + if(!::basegfx::fTools::equal(fOne, fSx) || !::basegfx::fTools::equal(fOne, fSz)) + { + Impl3DHomMatrix aShearXZMat(get3DIdentityMatrix()); - aShearXZMat.set(0, 1, fSx); - aShearXZMat.set(2, 1, fSz); + aShearXZMat.set(0, 1, fSx); + aShearXZMat.set(2, 1, fSz); - implPrepareChange(); - mpM->doMulMatrix(aShearXZMat); - } + implPrepareChange(); + mpM->doMulMatrix(aShearXZMat); } + } - void B3DHomMatrix::frustum(double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar) + void B3DHomMatrix::frustum(double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar) + { + const double fZero(0.0); + const double fOne(1.0); + + if(!::basegfx::fTools::more(fNear, fZero)) { - const double fZero(0.0); - const double fOne(1.0); + fNear = 0.001; + } - if(!::basegfx::numeric::fTools::more(fNear, fZero)) - { - fNear = 0.001; - } + if(!::basegfx::fTools::more(fFar, fZero)) + { + fFar = fOne; + } - if(!::basegfx::numeric::fTools::more(fFar, fZero)) - { - fFar = fOne; - } + if(::basegfx::fTools::equal(fNear, fFar)) + { + fFar = fNear + fOne; + } - if(::basegfx::numeric::fTools::equal(fNear, fFar)) - { - fFar = fNear + fOne; - } + if(::basegfx::fTools::equal(fLeft, fRight)) + { + fLeft -= fOne; + fRight += fOne; + } - if(::basegfx::numeric::fTools::equal(fLeft, fRight)) - { - fLeft -= fOne; - fRight += fOne; - } + if(::basegfx::fTools::equal(fTop, fBottom)) + { + fBottom -= fOne; + fTop += fOne; + } - if(::basegfx::numeric::fTools::equal(fTop, fBottom)) - { - fBottom -= fOne; - fTop += fOne; - } + Impl3DHomMatrix aFrustumMat(get3DIdentityMatrix()); - Impl3DHomMatrix aFrustumMat(get3DIdentityMatrix()); + aFrustumMat.set(0, 0, 2.0 * fNear / (fRight - fLeft)); + aFrustumMat.set(1, 1, 2.0 * fNear / (fTop - fBottom)); + aFrustumMat.set(0, 2, (fRight + fLeft) / (fRight - fLeft)); + aFrustumMat.set(1, 2, (fTop + fBottom) / (fTop - fBottom)); + aFrustumMat.set(2, 2, -fOne * ((fFar + fNear) / (fFar - fNear))); + aFrustumMat.set(3, 2, -fOne); + aFrustumMat.set(2, 3, -fOne * ((2.0 * fFar * fNear) / (fFar - fNear))); + aFrustumMat.set(3, 3, fZero); - aFrustumMat.set(0, 0, 2.0 * fNear / (fRight - fLeft)); - aFrustumMat.set(1, 1, 2.0 * fNear / (fTop - fBottom)); - aFrustumMat.set(0, 2, (fRight + fLeft) / (fRight - fLeft)); - aFrustumMat.set(1, 2, (fTop + fBottom) / (fTop - fBottom)); - aFrustumMat.set(2, 2, -fOne * ((fFar + fNear) / (fFar - fNear))); - aFrustumMat.set(3, 2, -fOne); - aFrustumMat.set(2, 3, -fOne * ((2.0 * fFar * fNear) / (fFar - fNear))); - aFrustumMat.set(3, 3, fZero); + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; - if(mpM->getRefCount()) - mpM->decRefCount(); - else - delete mpM; + mpM = new Impl3DHomMatrix(aFrustumMat); + } - mpM = new Impl3DHomMatrix(aFrustumMat); + void B3DHomMatrix::ortho(double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar) + { + if(::basegfx::fTools::equal(fNear, fFar)) + { + fFar = fNear + 1.0; } - void B3DHomMatrix::ortho(double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar) + if(::basegfx::fTools::equal(fLeft, fRight)) { - if(::basegfx::numeric::fTools::equal(fNear, fFar)) - { - fFar = fNear + 1.0; - } - - if(::basegfx::numeric::fTools::equal(fLeft, fRight)) - { - fLeft -= 1.0; - fRight += 1.0; - } + fLeft -= 1.0; + fRight += 1.0; + } - if(::basegfx::numeric::fTools::equal(fTop, fBottom)) - { - fBottom -= 1.0; - fTop += 1.0; - } + if(::basegfx::fTools::equal(fTop, fBottom)) + { + fBottom -= 1.0; + fTop += 1.0; + } - Impl3DHomMatrix aOrthoMat(get3DIdentityMatrix()); + Impl3DHomMatrix aOrthoMat(get3DIdentityMatrix()); - aOrthoMat.set(0, 0, 2.0 / (fRight - fLeft)); - aOrthoMat.set(1, 1, 2.0 / (fTop - fBottom)); - aOrthoMat.set(2, 2, -1.0 * (2.0 / (fFar - fNear))); - aOrthoMat.set(0, 3, -1.0 * ((fRight + fLeft) / (fRight - fLeft))); - aOrthoMat.set(1, 3, -1.0 * ((fTop + fBottom) / (fTop - fBottom))); - aOrthoMat.set(2, 3, -1.0 * ((fFar + fNear) / (fFar - fNear))); + aOrthoMat.set(0, 0, 2.0 / (fRight - fLeft)); + aOrthoMat.set(1, 1, 2.0 / (fTop - fBottom)); + aOrthoMat.set(2, 2, -1.0 * (2.0 / (fFar - fNear))); + aOrthoMat.set(0, 3, -1.0 * ((fRight + fLeft) / (fRight - fLeft))); + aOrthoMat.set(1, 3, -1.0 * ((fTop + fBottom) / (fTop - fBottom))); + aOrthoMat.set(2, 3, -1.0 * ((fFar + fNear) / (fFar - fNear))); - if(mpM->getRefCount()) - mpM->decRefCount(); - else - delete mpM; + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; - mpM = new Impl3DHomMatrix(aOrthoMat); - } + mpM = new Impl3DHomMatrix(aOrthoMat); + } - sal_Bool B3DHomMatrix::decompose(tuple::B3DTuple& rScale, tuple::B3DTuple& rTranslate, tuple::B3DTuple& rRotate, tuple::B3DTuple& rShear) const - { - // when perspective is used, decompose is not made here - if(!mpM->isLastLineDefault()) - return sal_False; + sal_Bool B3DHomMatrix::decompose(B3DTuple& rScale, B3DTuple& rTranslate, B3DTuple& rRotate, B3DTuple& rShear) const + { + // when perspective is used, decompose is not made here + if(!mpM->isLastLineDefault()) + return sal_False; - // If determinant is zero, decomposition is not possible - if(0.0 == mpM->doDeterminant()) - return sal_False; + // If determinant is zero, decomposition is not possible + if(0.0 == mpM->doDeterminant()) + return sal_False; - // isolate translation - rTranslate.setX(mpM->get(0, 3)); - rTranslate.setY(mpM->get(1, 3)); - rTranslate.setZ(mpM->get(2, 3)); + // isolate translation + rTranslate.setX(mpM->get(0, 3)); + rTranslate.setY(mpM->get(1, 3)); + rTranslate.setZ(mpM->get(2, 3)); - // correct translate values - rTranslate.correctValues(); + // correct translate values + rTranslate.correctValues(); - // get scale and shear - vector::B3DVector aCol0(mpM->get(0, 0), mpM->get(1, 0), mpM->get(2, 0)); - vector::B3DVector aCol1(mpM->get(0, 1), mpM->get(1, 1), mpM->get(2, 1)); - vector::B3DVector aCol2(mpM->get(0, 2), mpM->get(1, 2), mpM->get(2, 2)); - vector::B3DVector aTemp; + // get scale and shear + B3DVector aCol0(mpM->get(0, 0), mpM->get(1, 0), mpM->get(2, 0)); + B3DVector aCol1(mpM->get(0, 1), mpM->get(1, 1), mpM->get(2, 1)); + B3DVector aCol2(mpM->get(0, 2), mpM->get(1, 2), mpM->get(2, 2)); + B3DVector aTemp; - // get ScaleX - rScale.setX(aCol0.getLength()); - aCol0.normalize(); + // get ScaleX + rScale.setX(aCol0.getLength()); + aCol0.normalize(); - // get ShearXY - rShear.setX(aCol0.scalar(aCol1)); + // get ShearXY + rShear.setX(aCol0.scalar(aCol1)); - if(::basegfx::numeric::fTools::equalZero(rShear.getX())) - { - rShear.setX(0.0); - } - else - { - aTemp.setX(aCol1.getX() - rShear.getX() * aCol0.getX()); - aTemp.setY(aCol1.getY() - rShear.getX() * aCol0.getY()); - aTemp.setZ(aCol1.getZ() - rShear.getX() * aCol0.getZ()); - aCol1 = aTemp; - } + if(::basegfx::fTools::equalZero(rShear.getX())) + { + rShear.setX(0.0); + } + else + { + aTemp.setX(aCol1.getX() - rShear.getX() * aCol0.getX()); + aTemp.setY(aCol1.getY() - rShear.getX() * aCol0.getY()); + aTemp.setZ(aCol1.getZ() - rShear.getX() * aCol0.getZ()); + aCol1 = aTemp; + } - // get ScaleY - rScale.setY(aCol1.getLength()); - aCol1.normalize(); + // get ScaleY + rScale.setY(aCol1.getLength()); + aCol1.normalize(); - const double fShearX(rShear.getX()); + const double fShearX(rShear.getX()); - if(!::basegfx::numeric::fTools::equalZero(fShearX)) - { - rShear.setX(rShear.getX() / rScale.getY()); - } + if(!::basegfx::fTools::equalZero(fShearX)) + { + rShear.setX(rShear.getX() / rScale.getY()); + } - // get ShearXZ - rShear.setY(aCol0.scalar(aCol2)); + // get ShearXZ + rShear.setY(aCol0.scalar(aCol2)); - if(::basegfx::numeric::fTools::equalZero(rShear.getY())) - { - rShear.setY(0.0); - } - else - { - aTemp.setX(aCol2.getX() - rShear.getY() * aCol0.getX()); - aTemp.setY(aCol2.getY() - rShear.getY() * aCol0.getY()); - aTemp.setZ(aCol2.getZ() - rShear.getY() * aCol0.getZ()); - aCol2 = aTemp; - } + if(::basegfx::fTools::equalZero(rShear.getY())) + { + rShear.setY(0.0); + } + else + { + aTemp.setX(aCol2.getX() - rShear.getY() * aCol0.getX()); + aTemp.setY(aCol2.getY() - rShear.getY() * aCol0.getY()); + aTemp.setZ(aCol2.getZ() - rShear.getY() * aCol0.getZ()); + aCol2 = aTemp; + } - // get ShearYZ - rShear.setZ(aCol1.scalar(aCol2)); + // get ShearYZ + rShear.setZ(aCol1.scalar(aCol2)); - if(::basegfx::numeric::fTools::equalZero(rShear.getZ())) - { - rShear.setZ(0.0); - } - else - { - aTemp.setX(aCol2.getX() - rShear.getZ() * aCol1.getX()); - aTemp.setY(aCol2.getY() - rShear.getZ() * aCol1.getY()); - aTemp.setZ(aCol2.getZ() - rShear.getZ() * aCol1.getZ()); - aCol2 = aTemp; - } + if(::basegfx::fTools::equalZero(rShear.getZ())) + { + rShear.setZ(0.0); + } + else + { + aTemp.setX(aCol2.getX() - rShear.getZ() * aCol1.getX()); + aTemp.setY(aCol2.getY() - rShear.getZ() * aCol1.getY()); + aTemp.setZ(aCol2.getZ() - rShear.getZ() * aCol1.getZ()); + aCol2 = aTemp; + } - // get ScaleZ - rScale.setZ(aCol2.getLength()); - aCol2.normalize(); + // get ScaleZ + rScale.setZ(aCol2.getLength()); + aCol2.normalize(); - const double fShearY(rShear.getY()); + const double fShearY(rShear.getY()); - if(!::basegfx::numeric::fTools::equalZero(fShearY)) - { - rShear.setY(rShear.getY() / rScale.getZ()); - } + if(!::basegfx::fTools::equalZero(fShearY)) + { + rShear.setY(rShear.getY() / rScale.getZ()); + } - const double fShearZ(rShear.getZ()); + const double fShearZ(rShear.getZ()); - if(!::basegfx::numeric::fTools::equalZero(fShearZ)) - { - rShear.setZ(rShear.getZ() / rScale.getZ()); - } + if(!::basegfx::fTools::equalZero(fShearZ)) + { + rShear.setZ(rShear.getZ() / rScale.getZ()); + } - // correct shear values - rShear.correctValues(); + // correct shear values + rShear.correctValues(); - // Coordinate system flip? - if(0.0 > aCol0.scalar(aCol1.getPerpendicular(aCol2))) - { - rScale = -rScale; - aCol0 = -aCol0; - aCol1 = -aCol1; - aCol2 = -aCol2; - } + // Coordinate system flip? + if(0.0 > aCol0.scalar(aCol1.getPerpendicular(aCol2))) + { + rScale = -rScale; + aCol0 = -aCol0; + aCol1 = -aCol1; + aCol2 = -aCol2; + } - // correct scale values - rScale.correctValues(1.0); + // correct scale values + rScale.correctValues(1.0); - // Get rotations - rRotate.setY(asin(-aCol0.getZ())); + // Get rotations + rRotate.setY(asin(-aCol0.getZ())); - if(::basegfx::numeric::fTools::equalZero(cos(rRotate.getY()))) - { - rRotate.setX(atan2(aCol1.getX(), aCol1.getY())); - rRotate.setZ(0.0); - } - else - { - rRotate.setX(atan2(aCol1.getZ(), aCol2.getZ())); - rRotate.setZ(atan2(aCol0.getY(), aCol0.getX())); - } + if(::basegfx::fTools::equalZero(cos(rRotate.getY()))) + { + rRotate.setX(atan2(aCol1.getX(), aCol1.getY())); + rRotate.setZ(0.0); + } + else + { + rRotate.setX(atan2(aCol1.getZ(), aCol2.getZ())); + rRotate.setZ(atan2(aCol0.getY(), aCol0.getX())); + } - // corrcet rotate values - rRotate.correctValues(); + // corrcet rotate values + rRotate.correctValues(); - return sal_True; - } - } // end of namespace matrix + return sal_True; + } } // end of namespace basegfx // eof diff --git a/basegfx/source/numeric/ftools.cxx b/basegfx/source/numeric/ftools.cxx index 9470c249a756..c39ee766a2bc 100644 --- a/basegfx/source/numeric/ftools.cxx +++ b/basegfx/source/numeric/ftools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftools.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aw $ $Date: 2003-10-31 10:13:56 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:03 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,11 +65,8 @@ namespace basegfx { - namespace numeric - { - // init static member of class fTools - double ::basegfx::numeric::fTools::mfSmallValue = 0.000000001; - } // end of namespace numeric + // init static member of class fTools + double ::basegfx::fTools::mfSmallValue = 0.000000001; } // end of namespace basegfx // eof diff --git a/basegfx/source/point/b2dhompoint.cxx b/basegfx/source/point/b2dhompoint.cxx index 575657491120..cda1e6f356b5 100644 --- a/basegfx/source/point/b2dhompoint.cxx +++ b/basegfx/source/point/b2dhompoint.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dhompoint.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-10 11:45:49 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -73,230 +73,227 @@ namespace basegfx { - namespace point + sal_Bool B2DHomPoint::implIsHomogenized() const { - sal_Bool B2DHomPoint::implIsHomogenized() const - { - const double fOne(1.0); - return ::basegfx::numeric::fTools::equal(fOne, mfW); - } + const double fOne(1.0); + return ::basegfx::fTools::equal(fOne, mfW); + } - void B2DHomPoint::implHomogenize() - { - const double fFactor(1.0 / mfW); - maTuple.setX(maTuple.getX() * fFactor); - maTuple.setY(maTuple.getY() * fFactor); - mfW = 1.0; - } + void B2DHomPoint::implHomogenize() + { + const double fFactor(1.0 / mfW); + maTuple.setX(maTuple.getX() * fFactor); + maTuple.setY(maTuple.getY() * fFactor); + mfW = 1.0; + } - void B2DHomPoint::implTestAndHomogenize() const - { - if(!implIsHomogenized()) - ((B2DHomPoint*)this)->implHomogenize(); - } + void B2DHomPoint::implTestAndHomogenize() const + { + if(!implIsHomogenized()) + ((B2DHomPoint*)this)->implHomogenize(); + } - B2DPoint B2DHomPoint::getB2DPoint() const - { - implTestAndHomogenize(); - return B2DPoint(maTuple.getX(), maTuple.getY()); - } + B2DPoint B2DHomPoint::getB2DPoint() const + { + implTestAndHomogenize(); + return B2DPoint(maTuple.getX(), maTuple.getY()); + } - double B2DHomPoint::getX() const - { - implTestAndHomogenize(); - return maTuple.getX(); - } + double B2DHomPoint::getX() const + { + implTestAndHomogenize(); + return maTuple.getX(); + } - double B2DHomPoint::getY() const - { - implTestAndHomogenize(); - return maTuple.getY(); - } + double B2DHomPoint::getY() const + { + implTestAndHomogenize(); + return maTuple.getY(); + } - void B2DHomPoint::setX(double fX) - { - maTuple.setX(implIsHomogenized() ? fX : fX * mfW ); - } + void B2DHomPoint::setX(double fX) + { + maTuple.setX(implIsHomogenized() ? fX : fX * mfW ); + } - void B2DHomPoint::setY(double fY) - { - maTuple.setY(implIsHomogenized() ? fY : fY * mfW ); - } + void B2DHomPoint::setY(double fY) + { + maTuple.setY(implIsHomogenized() ? fY : fY * mfW ); + } - B2DHomPoint& B2DHomPoint::operator+=( const B2DHomPoint& rPnt ) - { - maTuple.setX(getX() * rPnt.mfW + rPnt.getX() * mfW); - maTuple.setY(getY() * rPnt.mfW + rPnt.getY() * mfW); - mfW = mfW * rPnt.mfW; + B2DHomPoint& B2DHomPoint::operator+=( const B2DHomPoint& rPnt ) + { + maTuple.setX(getX() * rPnt.mfW + rPnt.getX() * mfW); + maTuple.setY(getY() * rPnt.mfW + rPnt.getY() * mfW); + mfW = mfW * rPnt.mfW; - return *this; - } + return *this; + } - B2DHomPoint& B2DHomPoint::operator-=( const B2DHomPoint& rPnt ) - { - maTuple.setX(getX() * rPnt.mfW - rPnt.getX() * mfW); - maTuple.setY(getY() * rPnt.mfW - rPnt.getY() * mfW); - mfW = mfW * rPnt.mfW; + B2DHomPoint& B2DHomPoint::operator-=( const B2DHomPoint& rPnt ) + { + maTuple.setX(getX() * rPnt.mfW - rPnt.getX() * mfW); + maTuple.setY(getY() * rPnt.mfW - rPnt.getY() * mfW); + mfW = mfW * rPnt.mfW; - return *this; - } + return *this; + } - B2DHomPoint& B2DHomPoint::operator*=(double t) + B2DHomPoint& B2DHomPoint::operator*=(double t) + { + if(!::basegfx::fTools::equalZero(t)) { - if(!::basegfx::numeric::fTools::equalZero(t)) - { - mfW /= t; - } - - return *this; + mfW /= t; } - B2DHomPoint& B2DHomPoint::operator*=( const matrix::B2DHomMatrix& rMat ) - { - const double fTempX( rMat.get(0,0)*maTuple.getX() + - rMat.get(0,1)*maTuple.getY() + - rMat.get(0,2)*mfW ); - - const double fTempY( rMat.get(1,0)*maTuple.getX() + - rMat.get(1,1)*maTuple.getY() + - rMat.get(1,2)*mfW ); - - const double fTempZ( rMat.get(2,0)*maTuple.getX() + - rMat.get(2,1)*maTuple.getY() + - rMat.get(2,2)*mfW ); - maTuple.setX( fTempX ); - maTuple.setY( fTempY ); - mfW = fTempZ; - - return *this; - } + return *this; + } - B2DHomPoint& B2DHomPoint::operator/=(double t) - { - mfW *= t; - return *this; - } + B2DHomPoint& B2DHomPoint::operator*=( const B2DHomMatrix& rMat ) + { + const double fTempX( rMat.get(0,0)*maTuple.getX() + + rMat.get(0,1)*maTuple.getY() + + rMat.get(0,2)*mfW ); - B2DHomPoint& B2DHomPoint::operator-(void) - { - mfW = -mfW; - return *this; - } + const double fTempY( rMat.get(1,0)*maTuple.getX() + + rMat.get(1,1)*maTuple.getY() + + rMat.get(1,2)*mfW ); - sal_Bool B2DHomPoint::operator==( const B2DHomPoint& rPnt ) const - { - implTestAndHomogenize(); - return (maTuple == rPnt.maTuple); - } + const double fTempZ( rMat.get(2,0)*maTuple.getX() + + rMat.get(2,1)*maTuple.getY() + + rMat.get(2,2)*mfW ); + maTuple.setX( fTempX ); + maTuple.setY( fTempY ); + mfW = fTempZ; - sal_Bool B2DHomPoint::operator!=( const B2DHomPoint& rPnt ) const - { - implTestAndHomogenize(); - return (maTuple != rPnt.maTuple); - } + return *this; + } - B2DHomPoint& B2DHomPoint::operator=( const B2DHomPoint& rPnt ) - { - maTuple = rPnt.maTuple; - mfW = rPnt.mfW; - return *this; - } + B2DHomPoint& B2DHomPoint::operator/=(double t) + { + mfW *= t; + return *this; + } - B2DHomPoint min(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) - { - B2DHomPoint aMin( - (rVecB.getX() < rVecA.getX()) ? rVecB.getX() : rVecA.getX(), - (rVecB.getY() < rVecA.getY()) ? rVecB.getY() : rVecA.getY()); - return aMin; - } + B2DHomPoint& B2DHomPoint::operator-(void) + { + mfW = -mfW; + return *this; + } - B2DHomPoint max(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) - { - B2DHomPoint aMax( - (rVecB.getX() > rVecA.getX()) ? rVecB.getX() : rVecA.getX(), - (rVecB.getY() > rVecA.getY()) ? rVecB.getY() : rVecA.getY()); - return aMax; - } - B2DHomPoint abs(const B2DHomPoint& rVec) - { - B2DHomPoint aAbs( - (0.0 > rVec.getX()) ? -rVec.getX() : rVec.getX(), - (0.0 > rVec.getY()) ? -rVec.getY() : rVec.getY()); - return aAbs; - } + sal_Bool B2DHomPoint::operator==( const B2DHomPoint& rPnt ) const + { + implTestAndHomogenize(); + return (maTuple == rPnt.maTuple); + } - B2DHomPoint interpolate(B2DHomPoint& rOld1, B2DHomPoint& rOld2, double t) - { - B2DHomPoint aInt( - ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), - ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY()); - return aInt; - } + sal_Bool B2DHomPoint::operator!=( const B2DHomPoint& rPnt ) const + { + implTestAndHomogenize(); + return (maTuple != rPnt.maTuple); + } - B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2) - { - B2DHomPoint aAvg( - (rOld1.getX() + rOld2.getX()) * 0.5, - (rOld1.getY() + rOld2.getY()) * 0.5); - return aAvg; - } + B2DHomPoint& B2DHomPoint::operator=( const B2DHomPoint& rPnt ) + { + maTuple = rPnt.maTuple; + mfW = rPnt.mfW; + return *this; + } - B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2, B2DHomPoint& rOld3) - { - B2DHomPoint aAvg( - (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), - (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0)); - return aAvg; - } + B2DHomPoint min(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) + { + B2DHomPoint aMin( + (rVecB.getX() < rVecA.getX()) ? rVecB.getX() : rVecA.getX(), + (rVecB.getY() < rVecA.getY()) ? rVecB.getY() : rVecA.getY()); + return aMin; + } - B2DHomPoint operator+(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) - { - B2DHomPoint aSum(rVecA); - aSum += rVecB; - return aSum; - } + B2DHomPoint max(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) + { + B2DHomPoint aMax( + (rVecB.getX() > rVecA.getX()) ? rVecB.getX() : rVecA.getX(), + (rVecB.getY() > rVecA.getY()) ? rVecB.getY() : rVecA.getY()); + return aMax; + } + B2DHomPoint abs(const B2DHomPoint& rVec) + { + B2DHomPoint aAbs( + (0.0 > rVec.getX()) ? -rVec.getX() : rVec.getX(), + (0.0 > rVec.getY()) ? -rVec.getY() : rVec.getY()); + return aAbs; + } - B2DHomPoint operator-(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) - { - B2DHomPoint aSub(rVecA); - aSub -= rVecB; - return aSub; - } + B2DHomPoint interpolate(B2DHomPoint& rOld1, B2DHomPoint& rOld2, double t) + { + B2DHomPoint aInt( + ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), + ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY()); + return aInt; + } - B2DHomPoint operator*(const B2DHomPoint& rVec, double t) - { - B2DHomPoint aNew(rVec); - aNew *= t; - return aNew; - } + B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2) + { + B2DHomPoint aAvg( + (rOld1.getX() + rOld2.getX()) * 0.5, + (rOld1.getY() + rOld2.getY()) * 0.5); + return aAvg; + } - B2DHomPoint operator*(double t, const B2DHomPoint& rVec) - { - B2DHomPoint aNew(rVec); - aNew *= t; - return aNew; - } + B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2, B2DHomPoint& rOld3) + { + B2DHomPoint aAvg( + (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), + (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0)); + return aAvg; + } - B2DHomPoint operator*( const matrix::B2DHomMatrix& rMat, const B2DHomPoint& rPoint ) - { - B2DHomPoint aNew(rPoint); - return aNew*=rMat; - } + B2DHomPoint operator+(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) + { + B2DHomPoint aSum(rVecA); + aSum += rVecB; + return aSum; + } - B2DHomPoint operator/(const B2DHomPoint& rVec, double t) - { - B2DHomPoint aNew(rVec); - aNew /= t; - return aNew; - } + B2DHomPoint operator-(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) + { + B2DHomPoint aSub(rVecA); + aSub -= rVecB; + return aSub; + } - B2DHomPoint operator/(double t, const B2DHomPoint& rVec) - { - B2DHomPoint aNew(rVec); - aNew /= t; - return aNew; - } - } // end of namespace point + B2DHomPoint operator*(const B2DHomPoint& rVec, double t) + { + B2DHomPoint aNew(rVec); + aNew *= t; + return aNew; + } + + B2DHomPoint operator*(double t, const B2DHomPoint& rVec) + { + B2DHomPoint aNew(rVec); + aNew *= t; + return aNew; + } + + B2DHomPoint operator*( const B2DHomMatrix& rMat, const B2DHomPoint& rPoint ) + { + B2DHomPoint aNew(rPoint); + return aNew*=rMat; + } + + B2DHomPoint operator/(const B2DHomPoint& rVec, double t) + { + B2DHomPoint aNew(rVec); + aNew /= t; + return aNew; + } + + B2DHomPoint operator/(double t, const B2DHomPoint& rVec) + { + B2DHomPoint aNew(rVec); + aNew /= t; + return aNew; + } } // end of namespace basegfx // eof diff --git a/basegfx/source/point/b2dpoint.cxx b/basegfx/source/point/b2dpoint.cxx index 34c14f89bdac..dab49a9fe392 100644 --- a/basegfx/source/point/b2dpoint.cxx +++ b/basegfx/source/point/b2dpoint.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpoint.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-06 16:30:28 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,29 +69,26 @@ namespace basegfx { - namespace point + B2DPoint& B2DPoint::operator=( const ::basegfx::B2DTuple& rPoint ) { - B2DPoint& B2DPoint::operator=( const ::basegfx::tuple::B2DTuple& rPoint ) - { - mfX = rPoint.getX(); - mfY = rPoint.getY(); - return *this; - } + mfX = rPoint.getX(); + mfY = rPoint.getY(); + return *this; + } - B2DPoint& B2DPoint::operator*=( const ::basegfx::matrix::B2DHomMatrix& rMat ) - { - const double fTempX( rMat.get(0,0)*mfX + - rMat.get(0,1)*mfY + - rMat.get(0,2) ); - const double fTempY( rMat.get(1,0)*mfX + - rMat.get(1,1)*mfY + - rMat.get(1,2) ); - mfX = fTempX; - mfY = fTempY; + B2DPoint& B2DPoint::operator*=( const ::basegfx::B2DHomMatrix& rMat ) + { + const double fTempX( rMat.get(0,0)*mfX + + rMat.get(0,1)*mfY + + rMat.get(0,2) ); + const double fTempY( rMat.get(1,0)*mfX + + rMat.get(1,1)*mfY + + rMat.get(1,2) ); + mfX = fTempX; + mfY = fTempY; - return *this; - } - } // end of namespace point + return *this; + } } // end of namespace basegfx // eof diff --git a/basegfx/source/point/b3dhompoint.cxx b/basegfx/source/point/b3dhompoint.cxx index 07570ebd8208..7069ea73a9ba 100644 --- a/basegfx/source/point/b3dhompoint.cxx +++ b/basegfx/source/point/b3dhompoint.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dhompoint.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aw $ $Date: 2003-10-31 10:13:57 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,17 +65,14 @@ namespace basegfx { - namespace point + void B3DHomPoint::implHomogenize() { - void B3DHomPoint::implHomogenize() - { - const double fFactor(1.0 / mfW); - maTuple.setX(maTuple.getX() * fFactor); - maTuple.setY(maTuple.getY() * fFactor); - maTuple.setZ(maTuple.getZ() * fFactor); - mfW = 1.0; - } - } // end of namespace point + const double fFactor(1.0 / mfW); + maTuple.setX(maTuple.getX() * fFactor); + maTuple.setY(maTuple.getY() * fFactor); + maTuple.setZ(maTuple.getZ() * fFactor); + mfW = 1.0; + } } // end of namespace basegfx // eof diff --git a/basegfx/source/point/b3dpoint.cxx b/basegfx/source/point/b3dpoint.cxx index 6d6471ffa07d..9ece7171af62 100644 --- a/basegfx/source/point/b3dpoint.cxx +++ b/basegfx/source/point/b3dpoint.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpoint.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:10 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,29 +69,26 @@ namespace basegfx { - namespace point + B3DPoint& B3DPoint::operator*=( const ::basegfx::B3DHomMatrix& rMat ) { - B3DPoint& B3DPoint::operator*=( const ::basegfx::matrix::B3DHomMatrix& rMat ) - { - const double fTempX(rMat.get(0,0)*mfX + - rMat.get(0,1)*mfY + - rMat.get(0,2)*mfZ + - rMat.get(0,3)); - const double fTempY(rMat.get(1,0)*mfX + - rMat.get(1,1)*mfY + - rMat.get(1,2)*mfZ + - rMat.get(1,3)); - const double fTempZ(rMat.get(2,0)*mfX + - rMat.get(2,1)*mfY + - rMat.get(2,2)*mfZ + - rMat.get(2,3)); - mfX = fTempX; - mfY = fTempY; - mfZ = fTempZ; + const double fTempX(rMat.get(0,0)*mfX + + rMat.get(0,1)*mfY + + rMat.get(0,2)*mfZ + + rMat.get(0,3)); + const double fTempY(rMat.get(1,0)*mfX + + rMat.get(1,1)*mfY + + rMat.get(1,2)*mfZ + + rMat.get(1,3)); + const double fTempZ(rMat.get(2,0)*mfX + + rMat.get(2,1)*mfY + + rMat.get(2,2)*mfZ + + rMat.get(2,3)); + mfX = fTempX; + mfY = fTempY; + mfZ = fTempZ; - return *this; - } - } // end of namespace point + return *this; + } } // end of namespace basegfx // eof diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx index 7a9b477081f5..0dcbeaa7a3a2 100644 --- a/basegfx/source/polygon/b2dpolygon.cxx +++ b/basegfx/source/polygon/b2dpolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygon.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:10 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:05 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -86,17 +86,17 @@ class CoordinateData2D { - ::basegfx::point::B2DPoint maPoint; + ::basegfx::B2DPoint maPoint; public: CoordinateData2D() {} - CoordinateData2D(const ::basegfx::point::B2DPoint& rData) : maPoint(rData) {} + CoordinateData2D(const ::basegfx::B2DPoint& rData) : maPoint(rData) {} ~CoordinateData2D() {} - const ::basegfx::point::B2DPoint& getCoordinate() const { return maPoint; } - void setCoordinate(const ::basegfx::point::B2DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } + const ::basegfx::B2DPoint& getCoordinate() const { return maPoint; } + void setCoordinate(const ::basegfx::B2DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } sal_Bool operator==(const CoordinateData2D& rData ) const { return (maPoint == rData.getCoordinate()); } - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) { maPoint *= rMatrix; } + void transform(const ::basegfx::B2DHomMatrix& rMatrix) { maPoint *= rMatrix; } }; ////////////////////////////////////////////////////////////////////////////// @@ -137,12 +137,12 @@ public: return (maVector == rCandidate.maVector); } - const ::basegfx::point::B2DPoint& getCoordinate(sal_uInt32 nIndex) const + const ::basegfx::B2DPoint& getCoordinate(sal_uInt32 nIndex) const { return maVector[nIndex].getCoordinate(); } - void setCoordinate(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rValue) + void setCoordinate(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue) { maVector[nIndex].setCoordinate(rValue); } @@ -233,7 +233,7 @@ public: } } - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + void transform(const ::basegfx::B2DHomMatrix& rMatrix) { CoordinateData2DVector::iterator aStart(maVector.begin()); CoordinateData2DVector::iterator aEnd(maVector.end()); @@ -249,18 +249,18 @@ public: class ControlVectorPair2D { - ::basegfx::vector::B2DVector maVectorA; - ::basegfx::vector::B2DVector maVectorB; + ::basegfx::B2DVector maVectorA; + ::basegfx::B2DVector maVectorB; public: ControlVectorPair2D() {} ~ControlVectorPair2D() {} - const ::basegfx::vector::B2DVector& getVectorA() const { return maVectorA; } - void setVectorA(const ::basegfx::vector::B2DVector& rValue) { if(rValue != maVectorA) maVectorA = rValue; } + const ::basegfx::B2DVector& getVectorA() const { return maVectorA; } + void setVectorA(const ::basegfx::B2DVector& rValue) { if(rValue != maVectorA) maVectorA = rValue; } - const ::basegfx::vector::B2DVector& getVectorB() const { return maVectorB; } - void setVectorB(const ::basegfx::vector::B2DVector& rValue) { if(rValue != maVectorB) maVectorB = rValue; } + const ::basegfx::B2DVector& getVectorB() const { return maVectorB; } + void setVectorB(const ::basegfx::B2DVector& rValue) { if(rValue != maVectorB) maVectorB = rValue; } sal_Bool operator==(const ControlVectorPair2D& rData ) const { return (maVectorA == rData.getVectorA() && maVectorB == rData.getVectorB()); } @@ -329,12 +329,12 @@ public: return (0L != mnUsedVectors); } - const ::basegfx::vector::B2DVector& getVectorA(sal_uInt32 nIndex) const + const ::basegfx::B2DVector& getVectorA(sal_uInt32 nIndex) const { return maVector[nIndex].getVectorA(); } - void setVectorA(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) + void setVectorA(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) { sal_Bool bWasUsed(mnUsedVectors && !maVector[nIndex].getVectorA().equalZero()); sal_Bool bIsUsed(!rValue.equalZero()); @@ -347,7 +347,7 @@ public: } else { - maVector[nIndex].setVectorA(::basegfx::vector::B2DVector::getEmptyVector()); + maVector[nIndex].setVectorA(::basegfx::B2DVector::getEmptyVector()); mnUsedVectors--; } } @@ -361,12 +361,12 @@ public: } } - const ::basegfx::vector::B2DVector& getVectorB(sal_uInt32 nIndex) const + const ::basegfx::B2DVector& getVectorB(sal_uInt32 nIndex) const { return maVector[nIndex].getVectorB(); } - void setVectorB(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) + void setVectorB(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) { sal_Bool bWasUsed(mnUsedVectors && !maVector[nIndex].getVectorB().equalZero()); sal_Bool bIsUsed(!rValue.equalZero()); @@ -379,7 +379,7 @@ public: } else { - maVector[nIndex].setVectorB(::basegfx::vector::B2DVector::getEmptyVector()); + maVector[nIndex].setVectorB(::basegfx::B2DVector::getEmptyVector()); mnUsedVectors--; } } @@ -601,17 +601,17 @@ public: return sal_False; } - const ::basegfx::point::B2DPoint& getPoint(sal_uInt32 nIndex) const + const ::basegfx::B2DPoint& getPoint(sal_uInt32 nIndex) const { return maPoints.getCoordinate(nIndex); } - void setPoint(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rValue) + void setPoint(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue) { maPoints.setCoordinate(nIndex, rValue); } - void insert(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rPoint, sal_uInt32 nCount) { if(nCount) { @@ -626,7 +626,7 @@ public: } } - const ::basegfx::vector::B2DVector& getControlVectorA(sal_uInt32 nIndex) const + const ::basegfx::B2DVector& getControlVectorA(sal_uInt32 nIndex) const { if(mpControlVector) { @@ -634,11 +634,11 @@ public: } else { - return ::basegfx::vector::B2DVector::getEmptyVector(); + return ::basegfx::B2DVector::getEmptyVector(); } } - void setControlVectorA(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) + void setControlVectorA(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) { if(!mpControlVector) { @@ -665,7 +665,7 @@ public: return (mpControlVector && mpControlVector->isUsed()); } - const ::basegfx::vector::B2DVector& getControlVectorB(sal_uInt32 nIndex) const + const ::basegfx::B2DVector& getControlVectorB(sal_uInt32 nIndex) const { if(mpControlVector) { @@ -673,11 +673,11 @@ public: } else { - return ::basegfx::vector::B2DVector::getEmptyVector(); + return ::basegfx::B2DVector::getEmptyVector(); } } - void setControlVectorB(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) + void setControlVectorB(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) { if(!mpControlVector) { @@ -775,10 +775,10 @@ public: const sal_uInt32 nVectorSource(nCoorSource ? nCoorSource - 1L : nCount - 1L); // get source data - const ::basegfx::point::B2DPoint& rSourceCoor = pCoordinateCopy->getCoordinate(nCoorSource); - const ::basegfx::point::B2DPoint& rVectorSourceCoor = pCoordinateCopy->getCoordinate(nVectorSource); - const ::basegfx::vector::B2DVector& rVectorSourceA = pVectorCopy->getVectorA(nVectorSource); - const ::basegfx::vector::B2DVector& rVectorSourceB = pVectorCopy->getVectorB(nVectorSource); + const ::basegfx::B2DPoint& rSourceCoor = pCoordinateCopy->getCoordinate(nCoorSource); + const ::basegfx::B2DPoint& rVectorSourceCoor = pCoordinateCopy->getCoordinate(nVectorSource); + const ::basegfx::B2DVector& rVectorSourceA = pVectorCopy->getVectorA(nVectorSource); + const ::basegfx::B2DVector& rVectorSourceB = pVectorCopy->getVectorB(nVectorSource); // copy point data maPoints.setCoordinate(a, rSourceCoor); @@ -787,12 +787,12 @@ public: if(rVectorSourceA.equalZero()) { // unused, use zero vector - mpControlVector->setVectorB(a, ::basegfx::vector::B2DVector::getEmptyVector()); + mpControlVector->setVectorB(a, ::basegfx::B2DVector::getEmptyVector()); } else { // calculate new vector relative to new point - ::basegfx::vector::B2DVector aNewVectorB((rVectorSourceA + rVectorSourceCoor) - rSourceCoor); + ::basegfx::B2DVector aNewVectorB((rVectorSourceA + rVectorSourceCoor) - rSourceCoor); mpControlVector->setVectorB(a, aNewVectorB); } @@ -800,12 +800,12 @@ public: if(rVectorSourceB.equalZero()) { // unused, use zero vector - mpControlVector->setVectorA(a, ::basegfx::vector::B2DVector::getEmptyVector()); + mpControlVector->setVectorA(a, ::basegfx::B2DVector::getEmptyVector()); } else { // calculate new vector relative to new point - ::basegfx::vector::B2DVector aNewVectorA((rVectorSourceB + rVectorSourceCoor) - rSourceCoor); + ::basegfx::B2DVector aNewVectorA((rVectorSourceB + rVectorSourceCoor) - rSourceCoor); mpControlVector->setVectorA(a, aNewVectorA); } } @@ -939,28 +939,28 @@ public: } } - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + void transform(const ::basegfx::B2DHomMatrix& rMatrix) { if(mpControlVector) { for(sal_uInt32 a(0L); a < maPoints.count(); a++) { - ::basegfx::point::B2DPoint aCandidate = maPoints.getCoordinate(a); + ::basegfx::B2DPoint aCandidate = maPoints.getCoordinate(a); if(mpControlVector->isUsed()) { - const ::basegfx::vector::B2DVector& rVectorA(mpControlVector->getVectorA(a)); - const ::basegfx::vector::B2DVector& rVectorB(mpControlVector->getVectorB(a)); + const ::basegfx::B2DVector& rVectorA(mpControlVector->getVectorA(a)); + const ::basegfx::B2DVector& rVectorB(mpControlVector->getVectorB(a)); if(!rVectorA.equalZero()) { - ::basegfx::vector::B2DVector aVectorA(rMatrix * rVectorA); + ::basegfx::B2DVector aVectorA(rMatrix * rVectorA); mpControlVector->setVectorA(a, aVectorA); } if(!rVectorB.equalZero()) { - ::basegfx::vector::B2DVector aVectorB(rMatrix * rVectorB); + ::basegfx::B2DVector aVectorB(rMatrix * rVectorB); mpControlVector->setVectorB(a, aVectorB); } } @@ -986,294 +986,291 @@ public: namespace basegfx { - namespace polygon - { - // init static default Polygon - static ImplB2DPolygon maStaticDefaultPolygon; + // init static default Polygon + static ImplB2DPolygon maStaticDefaultPolygon; - void B2DPolygon::implForceUniqueCopy() + void B2DPolygon::implForceUniqueCopy() + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - mpPolygon = new ImplB2DPolygon(*mpPolygon); - } + mpPolygon->decRefCount(); + mpPolygon = new ImplB2DPolygon(*mpPolygon); } + } - B2DPolygon::B2DPolygon() - : mpPolygon(&maStaticDefaultPolygon) - { - mpPolygon->incRefCount(); - } + B2DPolygon::B2DPolygon() + : mpPolygon(&maStaticDefaultPolygon) + { + mpPolygon->incRefCount(); + } + + B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon) + : mpPolygon(rPolygon.mpPolygon) + { + mpPolygon->incRefCount(); + } + + B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) + : mpPolygon(new ImplB2DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + { + OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B2DPolygon constructor outside range (!)"); + } - B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon) - : mpPolygon(rPolygon.mpPolygon) + B2DPolygon::~B2DPolygon() + { + if(mpPolygon->getRefCount()) { - mpPolygon->incRefCount(); + mpPolygon->decRefCount(); } - - B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) - : mpPolygon(new ImplB2DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + else { - OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B2DPolygon constructor outside range (!)"); + delete mpPolygon; } + } - B2DPolygon::~B2DPolygon() + B2DPolygon& B2DPolygon::operator=(const B2DPolygon& rPolygon) + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - } - else - { - delete mpPolygon; - } + mpPolygon->decRefCount(); } - - B2DPolygon& B2DPolygon::operator=(const B2DPolygon& rPolygon) + else { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - } - else - { - delete mpPolygon; - } - - mpPolygon = rPolygon.mpPolygon; - mpPolygon->incRefCount(); - - return *this; + delete mpPolygon; } - sal_Bool B2DPolygon::operator==(const B2DPolygon& rPolygon) const - { - if(mpPolygon == rPolygon.mpPolygon) - { - return sal_True; - } + mpPolygon = rPolygon.mpPolygon; + mpPolygon->incRefCount(); - return mpPolygon->isEqual(*(rPolygon.mpPolygon)); - } + return *this; + } - sal_Bool B2DPolygon::operator!=(const B2DPolygon& rPolygon) const + sal_Bool B2DPolygon::operator==(const B2DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) { - if(mpPolygon == rPolygon.mpPolygon) - { - return sal_False; - } - - return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); + return sal_True; } - sal_uInt32 B2DPolygon::count() const + return mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } + + sal_Bool B2DPolygon::operator!=(const B2DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) { - return mpPolygon->count(); + return sal_False; } - ::basegfx::point::B2DPoint B2DPolygon::getB2DPoint(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } - return mpPolygon->getPoint(nIndex); - } + sal_uInt32 B2DPolygon::count() const + { + return mpPolygon->count(); + } - void B2DPolygon::setB2DPoint(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rValue) - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + ::basegfx::B2DPoint B2DPolygon::getB2DPoint(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - if(mpPolygon->getPoint(nIndex) != rValue) - { - implForceUniqueCopy(); - mpPolygon->setPoint(nIndex, rValue); - } - } + return mpPolygon->getPoint(nIndex); + } - void B2DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount) - { - OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + void B2DPolygon::setB2DPoint(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - if(nCount) - { - implForceUniqueCopy(); - mpPolygon->insert(nIndex, rPoint, nCount); - } + if(mpPolygon->getPoint(nIndex) != rValue) + { + implForceUniqueCopy(); + mpPolygon->setPoint(nIndex, rValue); } + } + + void B2DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rPoint, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); - void B2DPolygon::append(const ::basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount) + if(nCount) { - if(nCount) - { - implForceUniqueCopy(); - mpPolygon->insert(mpPolygon->count(), rPoint, nCount); - } + implForceUniqueCopy(); + mpPolygon->insert(nIndex, rPoint, nCount); } + } - ::basegfx::vector::B2DVector B2DPolygon::getControlVectorA(sal_uInt32 nIndex) const + void B2DPolygon::append(const ::basegfx::B2DPoint& rPoint, sal_uInt32 nCount) + { + if(nCount) { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - - return mpPolygon->getControlVectorA(nIndex); + implForceUniqueCopy(); + mpPolygon->insert(mpPolygon->count(), rPoint, nCount); } + } - void B2DPolygon::setControlVectorA(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + ::basegfx::B2DVector B2DPolygon::getControlVectorA(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - if(mpPolygon->getControlVectorA(nIndex) != rValue) - { - implForceUniqueCopy(); - mpPolygon->setControlVectorA(nIndex, rValue); - } - } + return mpPolygon->getControlVectorA(nIndex); + } - ::basegfx::vector::B2DVector B2DPolygon::getControlVectorB(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + void B2DPolygon::setControlVectorA(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - return mpPolygon->getControlVectorB(nIndex); + if(mpPolygon->getControlVectorA(nIndex) != rValue) + { + implForceUniqueCopy(); + mpPolygon->setControlVectorA(nIndex, rValue); } + } - void B2DPolygon::setControlVectorB(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + ::basegfx::B2DVector B2DPolygon::getControlVectorB(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - if(mpPolygon->getControlVectorB(nIndex) != rValue) - { - implForceUniqueCopy(); - mpPolygon->setControlVectorB(nIndex, rValue); - } - } + return mpPolygon->getControlVectorB(nIndex); + } - sal_Bool B2DPolygon::areControlPointsUsed() const + void B2DPolygon::setControlVectorB(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + if(mpPolygon->getControlVectorB(nIndex) != rValue) { - return mpPolygon->areControlPointsUsed(); + implForceUniqueCopy(); + mpPolygon->setControlVectorB(nIndex, rValue); } + } - void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) - { - OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + sal_Bool B2DPolygon::areControlPointsUsed() const + { + return mpPolygon->areControlPointsUsed(); + } - if(rPoly.count()) - { - implForceUniqueCopy(); + void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); - if(!nCount) - { - nCount = rPoly.count(); - } + if(rPoly.count()) + { + implForceUniqueCopy(); - if(0L == nIndex2 && nCount == rPoly.count()) - { - mpPolygon->insert(nIndex, *rPoly.mpPolygon); - } - else - { - OSL_ENSURE(nIndex2 + nCount > rPoly.mpPolygon->count(), "B2DPolygon Insert outside range (!)"); - ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); - mpPolygon->insert(nIndex, aTempPoly); - } + if(!nCount) + { + nCount = rPoly.count(); } - } - void B2DPolygon::append(const B2DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) - { - if(rPoly.count()) + if(0L == nIndex2 && nCount == rPoly.count()) { - implForceUniqueCopy(); - - if(!nCount) - { - nCount = rPoly.count(); - } - - if(0L == nIndex && nCount == rPoly.count()) - { - mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); - } - else - { - OSL_ENSURE(nIndex + nCount > rPoly.mpPolygon->count(), "B2DPolygon Append outside range (!)"); - ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); - mpPolygon->insert(mpPolygon->count(), aTempPoly); - } + mpPolygon->insert(nIndex, *rPoly.mpPolygon); + } + else + { + OSL_ENSURE(nIndex2 + nCount > rPoly.mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); + mpPolygon->insert(nIndex, aTempPoly); } } + } - void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + void B2DPolygon::append(const B2DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(rPoly.count()) { - OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B2DPolygon Remove outside range (!)"); + implForceUniqueCopy(); - if(nCount) + if(!nCount) { - implForceUniqueCopy(); - mpPolygon->remove(nIndex, nCount); + nCount = rPoly.count(); } - } - void B2DPolygon::clear() - { - if(mpPolygon->getRefCount()) + if(0L == nIndex && nCount == rPoly.count()) { - mpPolygon->decRefCount(); + mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); } else { - delete mpPolygon; + OSL_ENSURE(nIndex + nCount > rPoly.mpPolygon->count(), "B2DPolygon Append outside range (!)"); + ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); + mpPolygon->insert(mpPolygon->count(), aTempPoly); } - - mpPolygon = &maStaticDefaultPolygon; - mpPolygon->incRefCount(); } + } - sal_Bool B2DPolygon::isClosed() const + void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B2DPolygon Remove outside range (!)"); + + if(nCount) { - return mpPolygon->isClosed(); + implForceUniqueCopy(); + mpPolygon->remove(nIndex, nCount); } + } - void B2DPolygon::setClosed(sal_Bool bNew) + void B2DPolygon::clear() + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->isClosed() != bNew) - { - implForceUniqueCopy(); - mpPolygon->setClosed(bNew); - } + mpPolygon->decRefCount(); + } + else + { + delete mpPolygon; } - void B2DPolygon::flip() + mpPolygon = &maStaticDefaultPolygon; + mpPolygon->incRefCount(); + } + + sal_Bool B2DPolygon::isClosed() const + { + return mpPolygon->isClosed(); + } + + void B2DPolygon::setClosed(sal_Bool bNew) + { + if(mpPolygon->isClosed() != bNew) { - if(mpPolygon->count() > 1) - { - implForceUniqueCopy(); - mpPolygon->flip(); - } + implForceUniqueCopy(); + mpPolygon->setClosed(bNew); } + } - sal_Bool B2DPolygon::hasDoublePoints() const + void B2DPolygon::flip() + { + if(mpPolygon->count() > 1) { - return mpPolygon->hasDoublePoints(); + implForceUniqueCopy(); + mpPolygon->flip(); } + } - void B2DPolygon::removeDoublePoints() + sal_Bool B2DPolygon::hasDoublePoints() const + { + return mpPolygon->hasDoublePoints(); + } + + void B2DPolygon::removeDoublePoints() + { + if(mpPolygon->count() > 1) { - if(mpPolygon->count() > 1) - { - implForceUniqueCopy(); - mpPolygon->removeDoublePointsAtBeginEnd(); - mpPolygon->removeDoublePointsWholeTrack(); - } + implForceUniqueCopy(); + mpPolygon->removeDoublePointsAtBeginEnd(); + mpPolygon->removeDoublePointsWholeTrack(); } + } - void B2DPolygon::transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + void B2DPolygon::transform(const ::basegfx::B2DHomMatrix& rMatrix) + { + if(mpPolygon->count()) { - if(mpPolygon->count()) - { - implForceUniqueCopy(); - mpPolygon->transform(rMatrix); - } + implForceUniqueCopy(); + mpPolygon->transform(rMatrix); } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx index c2a6faf8909a..6f5ef6e89fba 100644 --- a/basegfx/source/polygon/b2dpolygontools.cxx +++ b/basegfx/source/polygon/b2dpolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygontools.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:11 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:05 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,10 @@ #include <basegfx/polygon/b2dpolygon.hxx> #endif +#ifndef _BGFX_POLYGON_B2DPOLYPOLYGON_HXX +#include <basegfx/polygon/b2dpolypolygon.hxx> +#endif + #ifndef _BGFX_NUMERIC_FTOOLS_HXX #include <basegfx/numeric/ftools.hxx> #endif @@ -91,925 +95,993 @@ namespace basegfx { - namespace polygon + namespace tools { - namespace tools + // B2DPolygon tools + void checkClosed(B2DPolygon& rCandidate) { - // B2DPolygon tools - void checkClosed(polygon::B2DPolygon& rCandidate) + while(rCandidate.count() > 1L + && rCandidate.getB2DPoint(0L).equal(rCandidate.getB2DPoint(rCandidate.count() - 1L))) { - while(rCandidate.count() > 1L - && rCandidate.getB2DPoint(0L).equal(rCandidate.getB2DPoint(rCandidate.count() - 1L))) - { - rCandidate.setClosed(sal_True); - rCandidate.remove(rCandidate.count() - 1L); - } + rCandidate.setClosed(sal_True); + rCandidate.remove(rCandidate.count() - 1L); } + } + + // Get index of outmost point (e.g. biggest X and biggest Y) + sal_uInt32 getIndexOfOutmostPoint(const ::basegfx::B2DPolygon& rCandidate) + { + sal_uInt32 nRetval(0L); - // Get index of outmost point (e.g. biggest X and biggest Y) - sal_uInt32 getIndexOfOutmostPoint(const ::basegfx::polygon::B2DPolygon& rCandidate) + if(rCandidate.count()) { - sal_uInt32 nRetval(0L); + ::basegfx::B2DPoint aOutmostPoint(rCandidate.getB2DPoint(0L)); - if(rCandidate.count()) + for(sal_uInt32 a(1L); a < rCandidate.count(); a++) { - ::basegfx::point::B2DPoint aOutmostPoint(rCandidate.getB2DPoint(0L)); + ::basegfx::B2DPoint rPoint(rCandidate.getB2DPoint(a)); - for(sal_uInt32 a(1L); a < rCandidate.count(); a++) + if(::basegfx::fTools::more(rPoint.getX(), aOutmostPoint.getX())) { - ::basegfx::point::B2DPoint rPoint(rCandidate.getB2DPoint(a)); - - if(::basegfx::numeric::fTools::more(rPoint.getX(), aOutmostPoint.getX())) + nRetval = a; + aOutmostPoint = rPoint; + } + else + { + if(::basegfx::fTools::more(rPoint.getY(), aOutmostPoint.getY())) { nRetval = a; aOutmostPoint = rPoint; } - else - { - if(::basegfx::numeric::fTools::more(rPoint.getY(), aOutmostPoint.getY())) - { - nRetval = a; - aOutmostPoint = rPoint; - } - } } } - - return nRetval; } - // Get successor and predecessor indices. Returning the same index means there - // is none. Same for successor. - sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate) - { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + return nRetval; + } - if(nIndex) - { - return nIndex - 1L; - } - else if(rCandidate.count()) - { - return rCandidate.count() - 1L; - } - else - { - return nIndex; - } - } + // Get successor and predecessor indices. Returning the same index means there + // is none. Same for successor. + sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate) + if(nIndex) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - - if(nIndex + 1L < rCandidate.count()) - { - return nIndex + 1L; - } - else - { - return 0L; - } + return nIndex - 1L; } - - sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate) + else if(rCandidate.count()) { - sal_uInt32 nNewIndex(nIndex); - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - - if(rCandidate.count() > 1) - { - nNewIndex = getIndexOfPredecessor(nIndex, rCandidate); - ::basegfx::point::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); + return rCandidate.count() - 1L; + } + else + { + return nIndex; + } + } - while(nNewIndex != nIndex - && aPoint.equal(rCandidate.getB2DPoint(nNewIndex))) - { - nNewIndex = getIndexOfPredecessor(nNewIndex, rCandidate); - } - } + sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - return nNewIndex; + if(nIndex + 1L < rCandidate.count()) + { + return nIndex + 1L; } + else + { + return 0L; + } + } + + sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate) + { + sal_uInt32 nNewIndex(nIndex); + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate) + if(rCandidate.count() > 1) { - sal_uInt32 nNewIndex(nIndex); - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + nNewIndex = getIndexOfPredecessor(nIndex, rCandidate); + ::basegfx::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); - if(rCandidate.count() > 1) + while(nNewIndex != nIndex + && aPoint.equal(rCandidate.getB2DPoint(nNewIndex))) { - nNewIndex = getIndexOfSuccessor(nIndex, rCandidate); - ::basegfx::point::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); - - while(nNewIndex != nIndex - && aPoint.equal(rCandidate.getB2DPoint(nNewIndex))) - { - nNewIndex = getIndexOfSuccessor(nNewIndex, rCandidate); - } + nNewIndex = getIndexOfPredecessor(nNewIndex, rCandidate); } - - return nNewIndex; } - ::basegfx::vector::B2DVectorOrientation getOrientation(const ::basegfx::polygon::B2DPolygon& rCandidate) + return nNewIndex; + } + + sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate) + { + sal_uInt32 nNewIndex(nIndex); + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + + if(rCandidate.count() > 1) { - ::basegfx::vector::B2DVectorOrientation eRetval(::basegfx::vector::ORIENTATION_NEUTRAL); + nNewIndex = getIndexOfSuccessor(nIndex, rCandidate); + ::basegfx::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); - if(rCandidate.count() > 2) + while(nNewIndex != nIndex + && aPoint.equal(rCandidate.getB2DPoint(nNewIndex))) { - sal_uInt32 nIndex = getIndexOfOutmostPoint(rCandidate); - eRetval = getPointOrientation(rCandidate, nIndex); + nNewIndex = getIndexOfSuccessor(nNewIndex, rCandidate); } - - return eRetval; } - ::basegfx::vector::B2DVectorContinuity getContinuityInPoint(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex) + return nNewIndex; + } + + ::basegfx::B2DVectorOrientation getOrientation(const ::basegfx::B2DPolygon& rCandidate) + { + ::basegfx::B2DVectorOrientation eRetval(::basegfx::ORIENTATION_NEUTRAL); + + if(rCandidate.count() > 2) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - ::basegfx::vector::B2DVectorContinuity eRetval(::basegfx::vector::CONTINUITY_NONE); + sal_uInt32 nIndex = getIndexOfOutmostPoint(rCandidate); + eRetval = getPointOrientation(rCandidate, nIndex); + } - if(rCandidate.count() > 1L && rCandidate.areControlPointsUsed()) - { - sal_uInt32 nPrevInd(getIndexOfPredecessor(nIndex, rCandidate)); - const ::basegfx::vector::B2DVector aForwardVector(rCandidate.getControlVectorA(nIndex)); - const ::basegfx::vector::B2DVector aBackVector(rCandidate.getControlVectorB(nPrevInd)); + return eRetval; + } - eRetval = ::basegfx::vector::getContinuity(aBackVector, aForwardVector); - } + ::basegfx::B2DVectorContinuity getContinuityInPoint(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + ::basegfx::B2DVectorContinuity eRetval(::basegfx::CONTINUITY_NONE); + + if(rCandidate.count() > 1L && rCandidate.areControlPointsUsed()) + { + sal_uInt32 nPrevInd(getIndexOfPredecessor(nIndex, rCandidate)); + const ::basegfx::B2DVector aForwardVector(rCandidate.getControlVectorA(nIndex)); + const ::basegfx::B2DVector aBackVector(rCandidate.getControlVectorB(nPrevInd)); - return eRetval; + eRetval = ::basegfx::getContinuity(aBackVector, aForwardVector); } - ::basegfx::polygon::B2DPolygon adaptiveSubdivideByDistance(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistanceBound) + return eRetval; + } + + ::basegfx::B2DPolygon adaptiveSubdivideByDistance(const ::basegfx::B2DPolygon& rCandidate, double fDistanceBound) + { + ::basegfx::B2DPolygon aRetval(rCandidate); + + if(aRetval.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolygon aRetval(rCandidate); + const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); + aRetval.clear(); - if(aRetval.areControlPointsUsed()) + for(sal_uInt32 a(0L); a < nPointCount; a++) { - const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); - aRetval.clear(); + const ::basegfx::B2DVector aVectorA(rCandidate.getControlVectorA(a)); + const ::basegfx::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(!aVectorA.equalZero() || !aVectorB.equalZero()) { - const ::basegfx::vector::B2DVector aVectorA(rCandidate.getControlVectorA(a)); - const ::basegfx::vector::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - - if(!aVectorA.equalZero() || !aVectorB.equalZero()) - { - // vectors are used, get points - const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate)); - ::basegfx::point::B2DPoint aPointA(rCandidate.getB2DPoint(a)); - ::basegfx::point::B2DPoint aPointB(rCandidate.getB2DPoint(nNext)); - - // build CubicBezier segment - ::basegfx::curve::B2DCubicBezier aBezier( - aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB); - - // generate DistanceBound - double fBound; + // vectors are used, get points + const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate)); + ::basegfx::B2DPoint aPointA(rCandidate.getB2DPoint(a)); + ::basegfx::B2DPoint aPointB(rCandidate.getB2DPoint(nNext)); - if(0.0 == fDistanceBound) - { - // If not set, calculate rough length of bezier segment by taking - // half of the sum of the edge and the control polygon - ::basegfx::vector::B2DVector aSimpleDistance(aPointB - aPointA); - ::basegfx::vector::B2DVector aTripleDistanceTop((aPointB + aVectorB) - (aPointA + aVectorA)); - const double fRoughLength( - (aSimpleDistance.getLength() - + (aVectorA.getLength() + aVectorB.getLength() + aTripleDistanceTop.getLength())) / 2.0); - - // take 1/100th of the rouch curve length - fBound = fRoughLength * 0.01; - } - else - { - // use given bound value - fBound = fDistanceBound; - } + // build CubicBezier segment + ::basegfx::B2DCubicBezier aBezier( + aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB); - // make sure bound value is not too small. The base units are 1/100th mm, thus - // just make sure it's not smaller then 1/100th of that - if(fBound < 0.01) - { - fBound = 0.01; - } + // generate DistanceBound + double fBound; - // call adaptive subdivide - ::basegfx::curve::adaptiveSubdivideByDistance(aRetval, aBezier, fBound); + if(0.0 == fDistanceBound) + { + // If not set, calculate rough length of bezier segment by taking + // half of the sum of the edge and the control polygon + ::basegfx::B2DVector aSimpleDistance(aPointB - aPointA); + ::basegfx::B2DVector aTripleDistanceTop((aPointB + aVectorB) - (aPointA + aVectorA)); + const double fRoughLength( + (aSimpleDistance.getLength() + + (aVectorA.getLength() + aVectorB.getLength() + aTripleDistanceTop.getLength())) / 2.0); + + // take 1/100th of the rouch curve length + fBound = fRoughLength * 0.01; } else { - // no vectors used, add point - aRetval.append(rCandidate.getB2DPoint(a)); + // use given bound value + fBound = fDistanceBound; + } + + // make sure bound value is not too small. The base units are 1/100th mm, thus + // just make sure it's not smaller then 1/100th of that + if(fBound < 0.01) + { + fBound = 0.01; } - } - // check closed flag, aRetval was cleared and thus it may be invalid. - if(aRetval.isClosed() != rCandidate.isClosed()) + // call adaptive subdivide + ::basegfx::adaptiveSubdivideByDistance(aRetval, aBezier, fBound); + } + else { - aRetval.setClosed(rCandidate.isClosed()); + // no vectors used, add point + aRetval.append(rCandidate.getB2DPoint(a)); } } - return aRetval; + // check closed flag, aRetval was cleared and thus it may be invalid. + if(aRetval.isClosed() != rCandidate.isClosed()) + { + aRetval.setClosed(rCandidate.isClosed()); + } } - ::basegfx::polygon::B2DPolygon adaptiveSubdivideByAngle(const ::basegfx::polygon::B2DPolygon& rCandidate, double fAngleBound) + return aRetval; + } + + ::basegfx::B2DPolygon adaptiveSubdivideByAngle(const ::basegfx::B2DPolygon& rCandidate, double fAngleBound) + { + ::basegfx::B2DPolygon aRetval(rCandidate); + + if(aRetval.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolygon aRetval(rCandidate); + const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); + aRetval.clear(); - if(aRetval.areControlPointsUsed()) + for(sal_uInt32 a(0L); a < nPointCount; a++) { - const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); - aRetval.clear(); + const ::basegfx::B2DVector aVectorA(rCandidate.getControlVectorA(a)); + const ::basegfx::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(!aVectorA.equalZero() || !aVectorB.equalZero()) { - const ::basegfx::vector::B2DVector aVectorA(rCandidate.getControlVectorA(a)); - const ::basegfx::vector::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - - if(!aVectorA.equalZero() || !aVectorB.equalZero()) - { - // vectors are used, get points - const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate)); - ::basegfx::point::B2DPoint aPointA(rCandidate.getB2DPoint(a)); - ::basegfx::point::B2DPoint aPointB(rCandidate.getB2DPoint(nNext)); + // vectors are used, get points + const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate)); + ::basegfx::B2DPoint aPointA(rCandidate.getB2DPoint(a)); + ::basegfx::B2DPoint aPointB(rCandidate.getB2DPoint(nNext)); - // build CubicBezier segment - ::basegfx::curve::B2DCubicBezier aBezier( - aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB); + // build CubicBezier segment + ::basegfx::B2DCubicBezier aBezier( + aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB); - // generate AngleBound - double fBound(fAngleBound); + // generate AngleBound + double fBound(fAngleBound); - // make sure angle bound is not too small - if(::basegfx::numeric::fTools::less(fAngleBound, 0.1)) - { - fAngleBound = 0.1; - } - - // call adaptive subdivide - ::basegfx::curve::adaptiveSubdivideByAngle(aRetval, aBezier, fBound); - } - else + // make sure angle bound is not too small + if(::basegfx::fTools::less(fAngleBound, 0.1)) { - // no vectors used, add point - aRetval.append(rCandidate.getB2DPoint(a)); + fAngleBound = 0.1; } - } - // check closed flag, aRetval was cleared and thus it may be invalid. - if(aRetval.isClosed() != rCandidate.isClosed()) + // call adaptive subdivide + ::basegfx::adaptiveSubdivideByAngle(aRetval, aBezier, fBound); + } + else { - aRetval.setClosed(rCandidate.isClosed()); + // no vectors used, add point + aRetval.append(rCandidate.getB2DPoint(a)); } } - return aRetval; + // check closed flag, aRetval was cleared and thus it may be invalid. + if(aRetval.isClosed() != rCandidate.isClosed()) + { + aRetval.setClosed(rCandidate.isClosed()); + } } - sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::point::B2DPoint& rPoint, sal_Bool bWithBorder) + return aRetval; + } + + sal_Bool isInside(const ::basegfx::B2DPolygon& rCandidate, const ::basegfx::B2DPoint& rPoint, sal_Bool bWithBorder) + { + sal_Bool bRetval(sal_False); + const sal_uInt32 nPointCount(rCandidate.count()); + + for(sal_uInt32 a(0L); a < nPointCount; a++) { - sal_Bool bRetval(sal_False); - const sal_uInt32 nPointCount(rCandidate.count()); + const ::basegfx::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(bWithBorder && aCurrentPoint.equal(rPoint)) { - const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); + return sal_True; + } - if(bWithBorder && aCurrentPoint.equal(rPoint)) - { - return sal_True; - } + // cross-over in Y? + const ::basegfx::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); + const sal_Bool bCompYA(::basegfx::fTools::more(aPreviousPoint.getY(), rPoint.getY())); + const sal_Bool bCompYB(::basegfx::fTools::more(aCurrentPoint.getY(), rPoint.getY())); - // cross-over in Y? - const ::basegfx::point::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); - const sal_Bool bCompYA(::basegfx::numeric::fTools::more(aPreviousPoint.getY(), rPoint.getY())); - const sal_Bool bCompYB(::basegfx::numeric::fTools::more(aCurrentPoint.getY(), rPoint.getY())); + if(bCompYA != bCompYB) + { + const sal_Bool bCompXA(::basegfx::fTools::more(aPreviousPoint.getX(), rPoint.getX())); + const sal_Bool bCompXB(::basegfx::fTools::more(aCurrentPoint.getX(), rPoint.getX())); - if(bCompYA != bCompYB) + if(bCompXA == bCompXB) { - const sal_Bool bCompXA(::basegfx::numeric::fTools::more(aPreviousPoint.getX(), rPoint.getX())); - const sal_Bool bCompXB(::basegfx::numeric::fTools::more(aCurrentPoint.getX(), rPoint.getX())); + if(bCompXA) + { + bRetval = !bRetval; + } + } + else + { + const double fCompare = + aCurrentPoint.getX() - (aCurrentPoint.getY() - rPoint.getY()) * + (aPreviousPoint.getX() - aCurrentPoint.getX()) / + (aPreviousPoint.getY() - aCurrentPoint.getY()); - if(bCompXA == bCompXB) + if(bWithBorder && ::basegfx::fTools::more(fCompare, rPoint.getX())) { - if(bCompXA) - { - bRetval = !bRetval; - } + bRetval = !bRetval; } - else + else if(::basegfx::fTools::moreOrEqual(fCompare, rPoint.getX())) { - const double fCompare = - aCurrentPoint.getX() - (aCurrentPoint.getY() - rPoint.getY()) * - (aPreviousPoint.getX() - aCurrentPoint.getX()) / - (aPreviousPoint.getY() - aCurrentPoint.getY()); - - if(bWithBorder && ::basegfx::numeric::fTools::more(fCompare, rPoint.getX())) - { - bRetval = !bRetval; - } - else if(::basegfx::numeric::fTools::moreOrEqual(fCompare, rPoint.getX())) - { - bRetval = !bRetval; - } + bRetval = !bRetval; } } } - - return bRetval; } - sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::polygon::B2DPolygon& rPolygon, sal_Bool bWithBorder) + return bRetval; + } + + sal_Bool isInside(const ::basegfx::B2DPolygon& rCandidate, const ::basegfx::B2DPolygon& rPolygon, sal_Bool bWithBorder) + { + const sal_uInt32 nPointCount(rPolygon.count()); + + for(sal_uInt32 a(0L); a < nPointCount; a++) { - const sal_uInt32 nPointCount(rPolygon.count()); + const ::basegfx::B2DPoint aTestPoint(rPolygon.getB2DPoint(a)); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(!isInside(rCandidate, aTestPoint, bWithBorder)) { - const ::basegfx::point::B2DPoint aTestPoint(rPolygon.getB2DPoint(a)); - - if(!isInside(rCandidate, aTestPoint, bWithBorder)) - { - return sal_False; - } + return sal_False; } - - return sal_True; } - ::basegfx::range::B2DRange getRange(const ::basegfx::polygon::B2DPolygon& rCandidate) - { - ::basegfx::range::B2DRange aRetval; - const sal_uInt32 nPointCount(rCandidate.count()); + return sal_True; + } + + ::basegfx::B2DRange getRange(const ::basegfx::B2DPolygon& rCandidate) + { + ::basegfx::B2DRange aRetval; + const sal_uInt32 nPointCount(rCandidate.count()); - if(rCandidate.areControlPointsUsed()) + if(rCandidate.areControlPointsUsed()) + { + for(sal_uInt32 a(0L); a < nPointCount; a++) { - for(sal_uInt32 a(0L); a < nPointCount; a++) - { - const ::basegfx::point::B2DPoint aTestPoint(rCandidate.getB2DPoint(a)); - const ::basegfx::vector::B2DVector aVectorA(rCandidate.getControlVectorA(a)); - const ::basegfx::vector::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - aRetval.expand(aTestPoint); + const ::basegfx::B2DPoint aTestPoint(rCandidate.getB2DPoint(a)); + const ::basegfx::B2DVector aVectorA(rCandidate.getControlVectorA(a)); + const ::basegfx::B2DVector aVectorB(rCandidate.getControlVectorB(a)); + aRetval.expand(aTestPoint); - if(!aVectorA.equalZero()) - { - aRetval.expand(aTestPoint + aVectorA); - } + if(!aVectorA.equalZero()) + { + aRetval.expand(aTestPoint + aVectorA); + } - if(!aVectorB.equalZero()) - { - const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); - const ::basegfx::point::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - aRetval.expand(aNextPoint + aVectorB); - } + if(!aVectorB.equalZero()) + { + const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); + const ::basegfx::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); + aRetval.expand(aNextPoint + aVectorB); } } - else + } + else + { + for(sal_uInt32 a(0L); a < nPointCount; a++) { - for(sal_uInt32 a(0L); a < nPointCount; a++) - { - const ::basegfx::point::B2DPoint aTestPoint(rCandidate.getB2DPoint(a)); - aRetval.expand(aTestPoint); - } + const ::basegfx::B2DPoint aTestPoint(rCandidate.getB2DPoint(a)); + aRetval.expand(aTestPoint); } - - return aRetval; } - double getArea(const ::basegfx::polygon::B2DPolygon& rCandidate) - { - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); + return aRetval; + } - if(nPointCount > 2) + double getArea(const ::basegfx::B2DPolygon& rCandidate) + { + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); + + if(nPointCount > 2) + { + for(sal_uInt32 a(0L); a < nPointCount; a++) { - for(sal_uInt32 a(0L); a < nPointCount; a++) - { - const ::basegfx::point::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); - const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); + const ::basegfx::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); + const ::basegfx::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); - fRetval += aPreviousPoint.getX() * aCurrentPoint.getY(); - fRetval -= aPreviousPoint.getY() * aCurrentPoint.getX(); - } + fRetval += aPreviousPoint.getX() * aCurrentPoint.getY(); + fRetval -= aPreviousPoint.getY() * aCurrentPoint.getX(); + } - fRetval /= 2.0; + fRetval /= 2.0; - const double fZero(0.0); + const double fZero(0.0); - if(::basegfx::numeric::fTools::less(fRetval, fZero)) - { - fRetval = -fRetval; - } + if(::basegfx::fTools::less(fRetval, fZero)) + { + fRetval = -fRetval; } - - return fRetval; } - double getEdgeLength(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex) - { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); + return fRetval; + } + + double getEdgeLength(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); - if(nIndex < nPointCount) + if(nIndex < nPointCount) + { + if(rCandidate.isClosed() || nIndex + 1 != nPointCount) { - if(rCandidate.isClosed() || nIndex + 1 != nPointCount) - { - const sal_uInt32 nNextIndex(nIndex + 1 == nPointCount ? 0L : nIndex + 1L); - const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(nIndex)); - const ::basegfx::point::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - const ::basegfx::vector::B2DVector aVector(aNextPoint - aCurrentPoint); - fRetval = aVector.getLength(); - } + const sal_uInt32 nNextIndex(nIndex + 1 == nPointCount ? 0L : nIndex + 1L); + const ::basegfx::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(nIndex)); + const ::basegfx::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); + const ::basegfx::B2DVector aVector(aNextPoint - aCurrentPoint); + fRetval = aVector.getLength(); } + } + + return fRetval; + } - return fRetval; + double getLength(const ::basegfx::B2DPolygon& rCandidate) + { + // This method may also be implemented using a loop over getEdgeLength, but + // since this would cause a lot of sqare roots to be solved it is much better + // to sum up the quadrats first and then use a singe suare root (if necessary) + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); + const sal_uInt32 nLoopCount(rCandidate.isClosed() ? nPointCount : nPointCount - 1L); + + for(sal_uInt32 a(0L); a < nLoopCount; a++) + { + const sal_uInt32 nNextIndex(a + 1 == nPointCount ? 0L : a + 1L); + const ::basegfx::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); + const ::basegfx::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); + const ::basegfx::B2DVector aVector(aNextPoint - aCurrentPoint); + fRetval += aVector.scalar(aVector); } - double getLength(const ::basegfx::polygon::B2DPolygon& rCandidate) + if(!::basegfx::fTools::equalZero(fRetval)) { - // This method may also be implemented using a loop over getEdgeLength, but - // since this would cause a lot of sqare roots to be solved it is much better - // to sum up the quadrats first and then use a singe suare root (if necessary) - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); - const sal_uInt32 nLoopCount(rCandidate.isClosed() ? nPointCount : nPointCount - 1L); + const double fOne(1.0); - for(sal_uInt32 a(0L); a < nLoopCount; a++) + if(!::basegfx::fTools::equal(fOne, fRetval)) { - const sal_uInt32 nNextIndex(a + 1 == nPointCount ? 0L : a + 1L); - const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); - const ::basegfx::point::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - const ::basegfx::vector::B2DVector aVector(aNextPoint - aCurrentPoint); - fRetval += aVector.scalar(aVector); + fRetval = sqrt(fRetval); } + } - if(!::basegfx::numeric::fTools::equalZero(fRetval)) - { - const double fOne(1.0); + return fRetval; + } - if(!::basegfx::numeric::fTools::equal(fOne, fRetval)) - { - fRetval = sqrt(fRetval); - } - } - - return fRetval; - } + ::basegfx::B2DPoint getPositionAbsolute(const ::basegfx::B2DPolygon& rCandidate, double fDistance, double fLength) + { + ::basegfx::B2DPoint aRetval; + const sal_uInt32 nPointCount(rCandidate.count()); - ::basegfx::point::B2DPoint getPositionAbsolute(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistance, double fLength) + if(nPointCount > 1L) { - ::basegfx::point::B2DPoint aRetval; - const sal_uInt32 nPointCount(rCandidate.count()); + sal_uInt32 nIndex(0L); + sal_Bool bIndexDone(sal_False); + const double fZero(0.0); + double fEdgeLength(fZero); - if(nPointCount > 1L) + // get length if not given + if(::basegfx::fTools::equalZero(fLength)) { - sal_uInt32 nIndex(0L); - sal_Bool bIndexDone(sal_False); - const double fZero(0.0); - double fEdgeLength(fZero); + fLength = getLength(rCandidate); + } - // get length if not given - if(::basegfx::numeric::fTools::equalZero(fLength)) + // handle fDistance < 0.0 + if(::basegfx::fTools::less(fDistance, fZero)) + { + if(rCandidate.isClosed()) { - fLength = getLength(rCandidate); + // if fDistance < 0.0 increment with multiple of fLength + sal_uInt32 nCount(sal_uInt32(-fDistance / fLength)); + fDistance += double(nCount + 1L) * fLength; } + else + { + // crop to polygon start + fDistance = fZero; + bIndexDone = sal_True; + } + } - // handle fDistance < 0.0 - if(::basegfx::numeric::fTools::less(fDistance, fZero)) + // handle fDistance >= fLength + if(::basegfx::fTools::moreOrEqual(fDistance, fLength)) + { + if(rCandidate.isClosed()) { - if(rCandidate.isClosed()) - { - // if fDistance < 0.0 increment with multiple of fLength - sal_uInt32 nCount(sal_uInt32(-fDistance / fLength)); - fDistance += double(nCount + 1L) * fLength; - } - else - { - // crop to polygon start - fDistance = fZero; - bIndexDone = sal_True; - } + // if fDistance >= fLength decrement with multiple of fLength + sal_uInt32 nCount(sal_uInt32(fDistance / fLength)); + fDistance -= (double)(nCount) * fLength; + } + else + { + // crop to polygon end + fDistance = fZero; + nIndex = nPointCount - 1L; + bIndexDone = sal_True; } + } - // handle fDistance >= fLength - if(::basegfx::numeric::fTools::moreOrEqual(fDistance, fLength)) + // look for correct index. fDistance is now [0.0 .. fLength[ + if(!bIndexDone) + { + do { - if(rCandidate.isClosed()) + // get length of next edge + fEdgeLength = getEdgeLength(rCandidate, nIndex); + + if(::basegfx::fTools::moreOrEqual(fDistance, fEdgeLength)) { - // if fDistance >= fLength decrement with multiple of fLength - sal_uInt32 nCount(sal_uInt32(fDistance / fLength)); - fDistance -= (double)(nCount) * fLength; + // go to next edge + fDistance -= fEdgeLength; + nIndex++; } else { - // crop to polygon end - fDistance = fZero; - nIndex = nPointCount - 1L; + // it's on this edge, stop bIndexDone = sal_True; } - } - - // look for correct index. fDistance is now [0.0 .. fLength[ - if(!bIndexDone) - { - do - { - // get length of next edge - fEdgeLength = getEdgeLength(rCandidate, nIndex); + } while (!bIndexDone); + } - if(::basegfx::numeric::fTools::moreOrEqual(fDistance, fEdgeLength)) - { - // go to next edge - fDistance -= fEdgeLength; - nIndex++; - } - else - { - // it's on this edge, stop - bIndexDone = sal_True; - } - } while (!bIndexDone); - } + // get the point using nIndex + aRetval = rCandidate.getB2DPoint(nIndex); - // get the point using nIndex - aRetval = rCandidate.getB2DPoint(nIndex); + // if fDistance != 0.0, move that length on the edge. The edge + // length is in fEdgeLength. + if(!::basegfx::fTools::equalZero(fDistance)) + { + sal_uInt32 nNextIndex(getIndexOfSuccessor(nIndex, rCandidate)); + const ::basegfx::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); + double fRelative(fZero); - // if fDistance != 0.0, move that length on the edge. The edge - // length is in fEdgeLength. - if(!::basegfx::numeric::fTools::equalZero(fDistance)) + if(!::basegfx::fTools::equalZero(fEdgeLength)) { - sal_uInt32 nNextIndex(getIndexOfSuccessor(nIndex, rCandidate)); - const ::basegfx::point::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - double fRelative(fZero); - - if(!::basegfx::numeric::fTools::equalZero(fEdgeLength)) - { - fRelative = fDistance / fEdgeLength; - } - - // add calculated average value to the return value - aRetval += ::basegfx::tuple::average(aRetval, aNextPoint, fRelative); + fRelative = fDistance / fEdgeLength; } - } - return aRetval; + // add calculated average value to the return value + aRetval = ::basegfx::interpolate(aRetval, aNextPoint, fRelative); + } } - ::basegfx::point::B2DPoint getPositionRelative(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistance, double fLength) - { - // get length if not given - if(::basegfx::numeric::fTools::equalZero(fLength)) - { - fLength = getLength(rCandidate); - } + return aRetval; + } - // multiply fDistance with real length to get absolute position and - // use getPositionAbsolute - return getPositionAbsolute(rCandidate, fDistance * fLength, fLength); + ::basegfx::B2DPoint getPositionRelative(const ::basegfx::B2DPolygon& rCandidate, double fDistance, double fLength) + { + // get length if not given + if(::basegfx::fTools::equalZero(fLength)) + { + fLength = getLength(rCandidate); } - ::basegfx::vector::B2DVectorOrientation getPointOrientation(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex) + // multiply fDistance with real length to get absolute position and + // use getPositionAbsolute + return getPositionAbsolute(rCandidate, fDistance * fLength, fLength); + } + + ::basegfx::B2DVectorOrientation getPointOrientation(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + ::basegfx::B2DVectorOrientation eRetval(::basegfx::ORIENTATION_NEUTRAL); + + if(rCandidate.count() > 2) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - ::basegfx::vector::B2DVectorOrientation eRetval(::basegfx::vector::ORIENTATION_NEUTRAL); + sal_uInt32 nIndPrev = getIndexOfDifferentPredecessor(nIndex, rCandidate); - if(rCandidate.count() > 2) + if(nIndPrev != nIndex) { - sal_uInt32 nIndPrev = getIndexOfDifferentPredecessor(nIndex, rCandidate); + sal_uInt32 nIndNext = getIndexOfDifferentSuccessor(nIndex, rCandidate); - if(nIndPrev != nIndex) + if(nIndNext != nIndex && nIndNext != nIndPrev) { - sal_uInt32 nIndNext = getIndexOfDifferentSuccessor(nIndex, rCandidate); - - if(nIndNext != nIndex && nIndNext != nIndPrev) - { - ::basegfx::point::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); - ::basegfx::vector::B2DVector aVecPrev(rCandidate.getB2DPoint(nIndPrev) - aPoint); - ::basegfx::vector::B2DVector aVecNext(rCandidate.getB2DPoint(nIndNext) - aPoint); - eRetval = ::basegfx::vector::getOrientation(aVecPrev, aVecNext); - } + ::basegfx::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); + ::basegfx::B2DVector aVecPrev(rCandidate.getB2DPoint(nIndPrev) - aPoint); + ::basegfx::B2DVector aVecNext(rCandidate.getB2DPoint(nIndNext) - aPoint); + eRetval = ::basegfx::getOrientation(aVecPrev, aVecNext); } } - - return eRetval; } - CutFlagValue findCut( - const ::basegfx::polygon::B2DPolygon& rCandidate, - sal_uInt32 nIndex1, sal_uInt32 nIndex2, - CutFlagValue aCutFlags, - double* pCut1, double* pCut2) - { - CutFlagValue aRetval(CUTFLAG_NONE); - const sal_uInt32 nPointCount(rCandidate.count()); + return eRetval; + } - if(nIndex1 < nPointCount && nIndex2 < nPointCount && nIndex1 != nIndex2) - { - sal_uInt32 nEnd1(getIndexOfSuccessor(nIndex1, rCandidate)); - sal_uInt32 nEnd2(getIndexOfSuccessor(nIndex2, rCandidate)); + CutFlagValue findCut( + const ::basegfx::B2DPolygon& rCandidate, + sal_uInt32 nIndex1, sal_uInt32 nIndex2, + CutFlagValue aCutFlags, + double* pCut1, double* pCut2) + { + CutFlagValue aRetval(CUTFLAG_NONE); + const sal_uInt32 nPointCount(rCandidate.count()); - const ::basegfx::point::B2DPoint aStart1(rCandidate.getB2DPoint(nIndex1)); - const ::basegfx::point::B2DPoint aEnd1(rCandidate.getB2DPoint(nEnd1)); - const ::basegfx::vector::B2DVector aVector1(aEnd1 - aStart1); + if(nIndex1 < nPointCount && nIndex2 < nPointCount && nIndex1 != nIndex2) + { + sal_uInt32 nEnd1(getIndexOfSuccessor(nIndex1, rCandidate)); + sal_uInt32 nEnd2(getIndexOfSuccessor(nIndex2, rCandidate)); - const ::basegfx::point::B2DPoint aStart2(rCandidate.getB2DPoint(nIndex2)); - const ::basegfx::point::B2DPoint aEnd2(rCandidate.getB2DPoint(nEnd2)); - const ::basegfx::vector::B2DVector aVector2(aEnd2 - aStart2); + const ::basegfx::B2DPoint aStart1(rCandidate.getB2DPoint(nIndex1)); + const ::basegfx::B2DPoint aEnd1(rCandidate.getB2DPoint(nEnd1)); + const ::basegfx::B2DVector aVector1(aEnd1 - aStart1); - aRetval = findCut( - aStart1, aVector1, aStart2, aVector2, - aCutFlags, pCut1, pCut2); - } + const ::basegfx::B2DPoint aStart2(rCandidate.getB2DPoint(nIndex2)); + const ::basegfx::B2DPoint aEnd2(rCandidate.getB2DPoint(nEnd2)); + const ::basegfx::B2DVector aVector2(aEnd2 - aStart2); - return aRetval; + aRetval = findCut( + aStart1, aVector1, aStart2, aVector2, + aCutFlags, pCut1, pCut2); } - CutFlagValue findCut( - const ::basegfx::polygon::B2DPolygon& rCandidate1, sal_uInt32 nIndex1, - const ::basegfx::polygon::B2DPolygon& rCandidate2, sal_uInt32 nIndex2, - CutFlagValue aCutFlags, - double* pCut1, double* pCut2) - { - CutFlagValue aRetval(CUTFLAG_NONE); - const sal_uInt32 nPointCount1(rCandidate1.count()); - const sal_uInt32 nPointCount2(rCandidate2.count()); + return aRetval; + } - if(nIndex1 < nPointCount1 && nIndex2 < nPointCount2) - { - sal_uInt32 nEnd1(getIndexOfSuccessor(nIndex1, rCandidate1)); - sal_uInt32 nEnd2(getIndexOfSuccessor(nIndex2, rCandidate2)); + CutFlagValue findCut( + const ::basegfx::B2DPolygon& rCandidate1, sal_uInt32 nIndex1, + const ::basegfx::B2DPolygon& rCandidate2, sal_uInt32 nIndex2, + CutFlagValue aCutFlags, + double* pCut1, double* pCut2) + { + CutFlagValue aRetval(CUTFLAG_NONE); + const sal_uInt32 nPointCount1(rCandidate1.count()); + const sal_uInt32 nPointCount2(rCandidate2.count()); - const ::basegfx::point::B2DPoint aStart1(rCandidate1.getB2DPoint(nIndex1)); - const ::basegfx::point::B2DPoint aEnd1(rCandidate1.getB2DPoint(nEnd1)); - const ::basegfx::vector::B2DVector aVector1(aEnd1 - aStart1); + if(nIndex1 < nPointCount1 && nIndex2 < nPointCount2) + { + sal_uInt32 nEnd1(getIndexOfSuccessor(nIndex1, rCandidate1)); + sal_uInt32 nEnd2(getIndexOfSuccessor(nIndex2, rCandidate2)); - const ::basegfx::point::B2DPoint aStart2(rCandidate2.getB2DPoint(nIndex2)); - const ::basegfx::point::B2DPoint aEnd2(rCandidate2.getB2DPoint(nEnd2)); - const ::basegfx::vector::B2DVector aVector2(aEnd2 - aStart2); + const ::basegfx::B2DPoint aStart1(rCandidate1.getB2DPoint(nIndex1)); + const ::basegfx::B2DPoint aEnd1(rCandidate1.getB2DPoint(nEnd1)); + const ::basegfx::B2DVector aVector1(aEnd1 - aStart1); - aRetval = findCut( - aStart1, aVector1, aStart2, aVector2, - aCutFlags, pCut1, pCut2); - } + const ::basegfx::B2DPoint aStart2(rCandidate2.getB2DPoint(nIndex2)); + const ::basegfx::B2DPoint aEnd2(rCandidate2.getB2DPoint(nEnd2)); + const ::basegfx::B2DVector aVector2(aEnd2 - aStart2); - return aRetval; + aRetval = findCut( + aStart1, aVector1, aStart2, aVector2, + aCutFlags, pCut1, pCut2); } - CutFlagValue findCut( - const ::basegfx::point::B2DPoint& rEdge1Start, const ::basegfx::vector::B2DVector& rEdge1Delta, - const ::basegfx::point::B2DPoint& rEdge2Start, const ::basegfx::vector::B2DVector& rEdge2Delta, - CutFlagValue aCutFlags, - double* pCut1, double* pCut2) - { - CutFlagValue aRetval(CUTFLAG_NONE); - double fCut1(0.0); - double fCut2(0.0); - sal_Bool bFinished(!((sal_Bool)(aCutFlags & CUTFLAG_ALL))); + return aRetval; + } - // test for same points? - if(!bFinished - && (aCutFlags & (CUTFLAG_START1|CUTFLAG_END1)) - && (aCutFlags & (CUTFLAG_START2|CUTFLAG_END2))) + CutFlagValue findCut( + const ::basegfx::B2DPoint& rEdge1Start, const ::basegfx::B2DVector& rEdge1Delta, + const ::basegfx::B2DPoint& rEdge2Start, const ::basegfx::B2DVector& rEdge2Delta, + CutFlagValue aCutFlags, + double* pCut1, double* pCut2) + { + CutFlagValue aRetval(CUTFLAG_NONE); + double fCut1(0.0); + double fCut2(0.0); + sal_Bool bFinished(!((sal_Bool)(aCutFlags & CUTFLAG_ALL))); + + // test for same points? + if(!bFinished + && (aCutFlags & (CUTFLAG_START1|CUTFLAG_END1)) + && (aCutFlags & (CUTFLAG_START2|CUTFLAG_END2))) + { + // same startpoint? + if(!bFinished && (aCutFlags & (CUTFLAG_START1|CUTFLAG_START2)) == (CUTFLAG_START1|CUTFLAG_START2)) { - // same startpoint? - if(!bFinished && (aCutFlags & (CUTFLAG_START1|CUTFLAG_START2)) == (CUTFLAG_START1|CUTFLAG_START2)) + if(rEdge1Start.equal(rEdge2Start)) { - if(rEdge1Start.equal(rEdge2Start)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_START1|CUTFLAG_START2); - } + bFinished = sal_True; + aRetval = (CUTFLAG_START1|CUTFLAG_START2); } + } - // same endpoint? - if(!bFinished && (aCutFlags & (CUTFLAG_END1|CUTFLAG_END2)) == (CUTFLAG_END1|CUTFLAG_END2)) - { - const ::basegfx::point::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); - const ::basegfx::point::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); + // same endpoint? + if(!bFinished && (aCutFlags & (CUTFLAG_END1|CUTFLAG_END2)) == (CUTFLAG_END1|CUTFLAG_END2)) + { + const ::basegfx::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); + const ::basegfx::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); - if(aEnd1.equal(aEnd2)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_END1|CUTFLAG_END2); - fCut1 = fCut2 = 1.0; - } + if(aEnd1.equal(aEnd2)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_END1|CUTFLAG_END2); + fCut1 = fCut2 = 1.0; } + } - // startpoint1 == endpoint2? - if(!bFinished && (aCutFlags & (CUTFLAG_START1|CUTFLAG_END2)) == (CUTFLAG_START1|CUTFLAG_END2)) - { - const ::basegfx::point::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); + // startpoint1 == endpoint2? + if(!bFinished && (aCutFlags & (CUTFLAG_START1|CUTFLAG_END2)) == (CUTFLAG_START1|CUTFLAG_END2)) + { + const ::basegfx::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); - if(rEdge1Start.equal(aEnd2)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_START1|CUTFLAG_END2); - fCut1 = 0.0; - fCut2 = 1.0; - } + if(rEdge1Start.equal(aEnd2)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_START1|CUTFLAG_END2); + fCut1 = 0.0; + fCut2 = 1.0; } + } - // startpoint2 == endpoint1? - if(!bFinished&& (aCutFlags & (CUTFLAG_START2|CUTFLAG_END1)) == (CUTFLAG_START2|CUTFLAG_END1)) - { - const ::basegfx::point::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); + // startpoint2 == endpoint1? + if(!bFinished&& (aCutFlags & (CUTFLAG_START2|CUTFLAG_END1)) == (CUTFLAG_START2|CUTFLAG_END1)) + { + const ::basegfx::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); - if(rEdge2Start.equal(aEnd1)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_START2|CUTFLAG_END1); - fCut1 = 1.0; - fCut2 = 0.0; - } + if(rEdge2Start.equal(aEnd1)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_START2|CUTFLAG_END1); + fCut1 = 1.0; + fCut2 = 0.0; } } + } - if(!bFinished && (aCutFlags & CUTFLAG_LINE)) + if(!bFinished && (aCutFlags & CUTFLAG_LINE)) + { + if(!bFinished && (aCutFlags & CUTFLAG_START1)) { - if(!bFinished && (aCutFlags & CUTFLAG_START1)) + // start1 on line 2 ? + if(isPointOnEdge(rEdge1Start, rEdge2Start, rEdge2Delta, &fCut2)) { - // start1 on line 2 ? - if(isPointOnEdge(rEdge1Start, rEdge2Start, rEdge2Delta, &fCut2)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_LINE|CUTFLAG_START1); - } + bFinished = sal_True; + aRetval = (CUTFLAG_LINE|CUTFLAG_START1); } + } - if(!bFinished && (aCutFlags & CUTFLAG_START2)) + if(!bFinished && (aCutFlags & CUTFLAG_START2)) + { + // start2 on line 1 ? + if(isPointOnEdge(rEdge2Start, rEdge1Start, rEdge1Delta, &fCut1)) { - // start2 on line 1 ? - if(isPointOnEdge(rEdge2Start, rEdge1Start, rEdge1Delta, &fCut1)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_LINE|CUTFLAG_START2); - } + bFinished = sal_True; + aRetval = (CUTFLAG_LINE|CUTFLAG_START2); } + } - if(!bFinished && (aCutFlags & CUTFLAG_END1)) - { - // end1 on line 2 ? - const ::basegfx::point::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); + if(!bFinished && (aCutFlags & CUTFLAG_END1)) + { + // end1 on line 2 ? + const ::basegfx::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); - if(isPointOnEdge(aEnd1, rEdge2Start, rEdge2Delta, &fCut2)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_LINE|CUTFLAG_END1); - } + if(isPointOnEdge(aEnd1, rEdge2Start, rEdge2Delta, &fCut2)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_LINE|CUTFLAG_END1); } + } - if(!bFinished && (aCutFlags & CUTFLAG_END2)) - { - // end2 on line 1 ? - const ::basegfx::point::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); + if(!bFinished && (aCutFlags & CUTFLAG_END2)) + { + // end2 on line 1 ? + const ::basegfx::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); - if(isPointOnEdge(aEnd2, rEdge1Start, rEdge1Delta, &fCut1)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_LINE|CUTFLAG_END2); - } + if(isPointOnEdge(aEnd2, rEdge1Start, rEdge1Delta, &fCut1)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_LINE|CUTFLAG_END2); } + } + + if(!bFinished) + { + // cut in line1, line2 ? + fCut1 = (rEdge1Delta.getX() * rEdge2Delta.getY()) - (rEdge1Delta.getY() * rEdge2Delta.getX()); - if(!bFinished) + if(!::basegfx::fTools::equalZero(fCut1)) { - // cut in line1, line2 ? - fCut1 = (rEdge1Delta.getX() * rEdge2Delta.getY()) - (rEdge1Delta.getY() * rEdge2Delta.getX()); + fCut1 = (rEdge2Delta.getY() * (rEdge2Start.getX() - rEdge1Start.getX()) + + rEdge2Delta.getX() * (rEdge1Start.getY() - rEdge2Start.getY())) / fCut1; - if(!::basegfx::numeric::fTools::equalZero(fCut1)) - { - fCut1 = (rEdge2Delta.getY() * (rEdge2Start.getX() - rEdge1Start.getX()) - + rEdge2Delta.getX() * (rEdge1Start.getY() - rEdge2Start.getY())) / fCut1; + const double fZero(0.0); + const double fOne(1.0); - const double fZero(0.0); - const double fOne(1.0); + // inside parameter range edge1 AND fCut2 is calcable + if(::basegfx::fTools::more(fCut1, fZero) && ::basegfx::fTools::less(fCut1, fOne) + && (!::basegfx::fTools::equalZero(rEdge2Delta.getX()) || !::basegfx::fTools::equalZero(rEdge2Delta.getY()))) + { + // take the mopre precise calculation of the two possible + if(fabs(rEdge2Delta.getX()) > fabs(rEdge2Delta.getY())) + { + fCut2 = (rEdge1Start.getX() + fCut1 + * rEdge1Delta.getX() - rEdge2Start.getX()) / rEdge2Delta.getX(); + } + else + { + fCut2 = (rEdge1Start.getY() + fCut1 + * rEdge1Delta.getY() - rEdge2Start.getY()) / rEdge2Delta.getY(); + } - // inside parameter range edge1 AND fCut2 is calcable - if(::basegfx::numeric::fTools::more(fCut1, fZero) && ::basegfx::numeric::fTools::less(fCut1, fOne) - && (!::basegfx::numeric::fTools::equalZero(rEdge2Delta.getX()) || !::basegfx::numeric::fTools::equalZero(rEdge2Delta.getY()))) + // inside parameter range edge2, too + if(::basegfx::fTools::more(fCut2, fZero) && ::basegfx::fTools::less(fCut2, fOne)) { - // take the mopre precise calculation of the two possible - if(fabs(rEdge2Delta.getX()) > fabs(rEdge2Delta.getY())) - { - fCut2 = (rEdge1Start.getX() + fCut1 - * rEdge1Delta.getX() - rEdge2Start.getX()) / rEdge2Delta.getX(); - } - else - { - fCut2 = (rEdge1Start.getY() + fCut1 - * rEdge1Delta.getY() - rEdge2Start.getY()) / rEdge2Delta.getY(); - } - - // inside parameter range edge2, too - if(::basegfx::numeric::fTools::more(fCut2, fZero) && ::basegfx::numeric::fTools::less(fCut2, fOne)) - { - bFinished = sal_True; - aRetval = CUTFLAG_LINE; - } + bFinished = sal_True; + aRetval = CUTFLAG_LINE; } } } } + } - // copy values if wanted - if(pCut1) - { - *pCut1 = fCut1; - } - - if(pCut2) - { - *pCut2 = fCut2; - } - - return aRetval; + // copy values if wanted + if(pCut1) + { + *pCut1 = fCut1; } - sal_Bool isPointOnEdge( - const ::basegfx::point::B2DPoint& rPoint, - const ::basegfx::point::B2DPoint& rEdgeStart, - const ::basegfx::vector::B2DVector& rEdgeDelta, - double* pCut) + if(pCut2) { - sal_Bool bDeltaXIsZero(::basegfx::numeric::fTools::equalZero(rEdgeDelta.getX())); - sal_Bool bDeltaYIsZero(::basegfx::numeric::fTools::equalZero(rEdgeDelta.getY())); - const double fZero(0.0); - const double fOne(1.0); + *pCut2 = fCut2; + } - if(bDeltaXIsZero && bDeltaYIsZero) - { - // no line, just a point - return sal_False; - } - else if(bDeltaXIsZero) + return aRetval; + } + + sal_Bool isPointOnEdge( + const ::basegfx::B2DPoint& rPoint, + const ::basegfx::B2DPoint& rEdgeStart, + const ::basegfx::B2DVector& rEdgeDelta, + double* pCut) + { + sal_Bool bDeltaXIsZero(::basegfx::fTools::equalZero(rEdgeDelta.getX())); + sal_Bool bDeltaYIsZero(::basegfx::fTools::equalZero(rEdgeDelta.getY())); + const double fZero(0.0); + const double fOne(1.0); + + if(bDeltaXIsZero && bDeltaYIsZero) + { + // no line, just a point + return sal_False; + } + else if(bDeltaXIsZero) + { + // vertical line + if(::basegfx::fTools::equal(rPoint.getX(), rEdgeStart.getX())) { - // vertical line - if(::basegfx::numeric::fTools::equal(rPoint.getX(), rEdgeStart.getX())) - { - double fValue = (rPoint.getY() - rEdgeStart.getY()) / rEdgeDelta.getY(); + double fValue = (rPoint.getY() - rEdgeStart.getY()) / rEdgeDelta.getY(); - if(::basegfx::numeric::fTools::more(fValue, fZero) && ::basegfx::numeric::fTools::less(fValue, fOne)) + if(::basegfx::fTools::more(fValue, fZero) && ::basegfx::fTools::less(fValue, fOne)) + { + if(pCut) { - if(pCut) - { - *pCut = fValue; - } - - return sal_True; + *pCut = fValue; } + + return sal_True; } } - else if(bDeltaYIsZero) + } + else if(bDeltaYIsZero) + { + // horizontal line + if(::basegfx::fTools::equal(rPoint.getY(), rEdgeStart.getY())) { - // horizontal line - if(::basegfx::numeric::fTools::equal(rPoint.getY(), rEdgeStart.getY())) - { - double fValue = (rPoint.getX() - rEdgeStart.getX()) / rEdgeDelta.getX(); + double fValue = (rPoint.getX() - rEdgeStart.getX()) / rEdgeDelta.getX(); - if(::basegfx::numeric::fTools::more(fValue, fZero) - && ::basegfx::numeric::fTools::less(fValue, fOne)) + if(::basegfx::fTools::more(fValue, fZero) + && ::basegfx::fTools::less(fValue, fOne)) + { + if(pCut) { - if(pCut) - { - *pCut = fValue; - } - - return sal_True; + *pCut = fValue; } + + return sal_True; } } - else + } + else + { + // any angle line + double fTOne = (rPoint.getX() - rEdgeStart.getX()) / rEdgeDelta.getX(); + double fTTwo = (rPoint.getY() - rEdgeStart.getY()) / rEdgeDelta.getY(); + + if(::basegfx::fTools::equal(fTOne, fTTwo)) { - // any angle line - double fTOne = (rPoint.getX() - rEdgeStart.getX()) / rEdgeDelta.getX(); - double fTTwo = (rPoint.getY() - rEdgeStart.getY()) / rEdgeDelta.getY(); + // same parameter representation, point is on line. Take + // middle value for better results + double fValue = (fTOne + fTTwo) / 2.0; - if(::basegfx::numeric::fTools::equal(fTOne, fTTwo)) + if(::basegfx::fTools::more(fValue, fZero) && ::basegfx::fTools::less(fValue, fOne)) { - // same parameter representation, point is on line. Take - // middle value for better results - double fValue = (fTOne + fTTwo) / 2.0; + // point is inside line bounds, too + if(pCut) + { + *pCut = fValue; + } + + return sal_True; + } + } + } - if(::basegfx::numeric::fTools::more(fValue, fZero) && ::basegfx::numeric::fTools::less(fValue, fOne)) + return sal_False; + } + + ::basegfx::B2DPolyPolygon applyLineDashing(const ::basegfx::B2DPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen) + { + ::basegfx::B2DPolyPolygon aRetval; + + if(rCandidate.count() && fFullDashDotLen > 0.0) + { + const sal_uInt32 nCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); + sal_uInt32 nDashDotIndex(0L); + double fDashDotLength(raDashDotArray[nDashDotIndex]); + + for(sal_uInt32 a(0L); a < nCount; a++) + { + const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); + const ::basegfx::B2DPoint aStart(rCandidate.getB2DPoint(a)); + const ::basegfx::B2DPoint aEnd(rCandidate.getB2DPoint(nNextIndex)); + const ::basegfx::B2DVector aVector(aEnd - aStart); + double fLength(aVector.getLength()); + double fPosOnVector(0.0); + + while(fLength >= fDashDotLength) + { + // handle [fPosOnVector .. fPosOnVector+fDashDotLength] + if(nDashDotIndex % 2) { - // point is inside line bounds, too - if(pCut) + ::basegfx::B2DPolygon aResult; + + // add start point + if(fPosOnVector == 0.0) + { + aResult.append(aStart); + } + else { - *pCut = fValue; + aResult.append(aStart + (aVector * fPosOnVector)); } - return sal_True; + // add end point + aResult.append(aStart + (aVector * (fPosOnVector + fDashDotLength))); + + // add line to PolyPolygon + aRetval.append(aResult); } + + // consume from fDashDotLength + fPosOnVector += fDashDotLength; + fLength -= fDashDotLength; + nDashDotIndex = (nDashDotIndex + 1L) % raDashDotArray.size(); + fDashDotLength = raDashDotArray[nDashDotIndex]; } - } - return sal_False; + // handle [fPosOnVector .. fPosOnVector+fLength (bzw. end)] + if((fLength > 0.0) && (nDashDotIndex % 2)) + { + ::basegfx::B2DPolygon aResult; + + // add start and end point + const ::basegfx::B2DPoint aPosA(aStart + (aVector * fPosOnVector)); + aResult.append(aPosA); + + // add line to PolyPolygon + aRetval.append(aResult); + } + + // consume from fDashDotLength + fDashDotLength -= fLength; + } } - } // end of namespace tools - } // end of namespace polygon + + return aRetval; + } + } // end of namespace tools } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b2dpolypolygon.cxx b/basegfx/source/polygon/b2dpolypolygon.cxx index 301d5a68edd8..f6fcbd9c0e55 100644 --- a/basegfx/source/polygon/b2dpolypolygon.cxx +++ b/basegfx/source/polygon/b2dpolypolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygon.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:11 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -81,7 +81,7 @@ class ImplB2DPolyPolygon { - typedef ::std::vector< ::basegfx::polygon::B2DPolygon > PolygonVector; + typedef ::std::vector< ::basegfx::B2DPolygon > PolygonVector; PolygonVector maPolygons; sal_uInt32 mnRefCount; @@ -127,17 +127,17 @@ public: return sal_True; } - const ::basegfx::polygon::B2DPolygon& getB2DPolygon(sal_uInt32 nIndex) const + const ::basegfx::B2DPolygon& getB2DPolygon(sal_uInt32 nIndex) const { return maPolygons[nIndex]; } - void setB2DPolygon(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rPolygon) + void setB2DPolygon(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rPolygon) { maPolygons[nIndex] = rPolygon; } - void insert(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rPolygon, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rPolygon, sal_uInt32 nCount) { if(nCount) { @@ -148,7 +148,7 @@ public: } } - void insert(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolyPolygon& rPolyPolygon) + void insert(sal_uInt32 nIndex, const ::basegfx::B2DPolyPolygon& rPolyPolygon) { const sal_uInt32 nCount = rPolyPolygon.count(); @@ -209,7 +209,7 @@ public: } } - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + void transform(const ::basegfx::B2DHomMatrix& rMatrix) { for(sal_uInt32 a(0L); a < maPolygons.size(); a++) { @@ -222,247 +222,244 @@ public: namespace basegfx { - namespace polygon - { - // init static default Polygon - static ImplB2DPolyPolygon maStaticDefaultPolyPolygon; + // init static default Polygon + static ImplB2DPolyPolygon maStaticDefaultPolyPolygon; - void B2DPolyPolygon::implForceUniqueCopy() + void B2DPolyPolygon::implForceUniqueCopy() + { + if(mpPolyPolygon->getRefCount()) { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - mpPolyPolygon = new ImplB2DPolyPolygon(*mpPolyPolygon); - } + mpPolyPolygon->decRefCount(); + mpPolyPolygon = new ImplB2DPolyPolygon(*mpPolyPolygon); } + } - B2DPolyPolygon::B2DPolyPolygon() - : mpPolyPolygon(&maStaticDefaultPolyPolygon) - { - mpPolyPolygon->incRefCount(); - } + B2DPolyPolygon::B2DPolyPolygon() + : mpPolyPolygon(&maStaticDefaultPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } - B2DPolyPolygon::B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon) - : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + B2DPolyPolygon::B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon) + : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } + + B2DPolyPolygon::~B2DPolyPolygon() + { + if(mpPolyPolygon->getRefCount()) { - mpPolyPolygon->incRefCount(); + mpPolyPolygon->decRefCount(); } - - B2DPolyPolygon::~B2DPolyPolygon() + else { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } + delete mpPolyPolygon; } + } - B2DPolyPolygon& B2DPolyPolygon::operator=(const B2DPolyPolygon& rPolyPolygon) + B2DPolyPolygon& B2DPolyPolygon::operator=(const B2DPolyPolygon& rPolyPolygon) + { + if(mpPolyPolygon->getRefCount()) { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } - - mpPolyPolygon = rPolyPolygon.mpPolyPolygon; - mpPolyPolygon->incRefCount(); - - return *this; + mpPolyPolygon->decRefCount(); } - - sal_Bool B2DPolyPolygon::operator==(const B2DPolyPolygon& rPolyPolygon) const + else { - if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) - { - return sal_True; - } - - return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + delete mpPolyPolygon; } - sal_Bool B2DPolyPolygon::operator!=(const B2DPolyPolygon& rPolyPolygon) const - { - if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) - { - return sal_False; - } + mpPolyPolygon = rPolyPolygon.mpPolyPolygon; + mpPolyPolygon->incRefCount(); - return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); - } + return *this; + } - sal_uInt32 B2DPolyPolygon::count() const + sal_Bool B2DPolyPolygon::operator==(const B2DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) { - return mpPolyPolygon->count(); + return sal_True; } - B2DPolygon B2DPolyPolygon::getB2DPolygon(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); + return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } - return mpPolyPolygon->getB2DPolygon(nIndex); + sal_Bool B2DPolyPolygon::operator!=(const B2DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) + { + return sal_False; } - void B2DPolyPolygon::setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon) - { - OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); + return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } - if(mpPolyPolygon->getB2DPolygon(nIndex) != rPolygon) - { - implForceUniqueCopy(); - mpPolyPolygon->setB2DPolygon(nIndex, rPolygon); - } - } + sal_uInt32 B2DPolyPolygon::count() const + { + return mpPolyPolygon->count(); + } - sal_Bool B2DPolyPolygon::areControlPointsUsed() const - { - for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++) - { - const ::basegfx::polygon::B2DPolygon& rPolygon = mpPolyPolygon->getB2DPolygon(a); + B2DPolygon B2DPolyPolygon::getB2DPolygon(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); - if(rPolygon.areControlPointsUsed()) - { - return sal_True; - } - } + return mpPolyPolygon->getB2DPolygon(nIndex); + } - return sal_False; + void B2DPolyPolygon::setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon) + { + OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); + + if(mpPolyPolygon->getB2DPolygon(nIndex) != rPolygon) + { + implForceUniqueCopy(); + mpPolyPolygon->setB2DPolygon(nIndex, rPolygon); } + } - void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount) + sal_Bool B2DPolyPolygon::areControlPointsUsed() const + { + for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++) { - OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); + const ::basegfx::B2DPolygon& rPolygon = mpPolyPolygon->getB2DPolygon(a); - if(nCount) + if(rPolygon.areControlPointsUsed()) { - implForceUniqueCopy(); - mpPolyPolygon->insert(nIndex, rPolygon, nCount); + return sal_True; } } - void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount) + return sal_False; + } + + void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); + + if(nCount) { - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolygon, nCount); } + } - void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon) + void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount) + { + if(nCount) { - OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); - - if(rPolyPolygon.count()) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(nIndex, rPolyPolygon); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); } + } + + void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon) + { + OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); - void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon) + if(rPolyPolygon.count()) { - if(rPolyPolygon.count()) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolyPolygon); } + } - void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon) + { + if(rPolyPolygon.count()) { - OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)"); - - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->remove(nIndex, nCount); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); } + } - void B2DPolyPolygon::clear() - { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } + void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)"); - mpPolyPolygon = &maStaticDefaultPolyPolygon; - mpPolyPolygon->incRefCount(); + if(nCount) + { + implForceUniqueCopy(); + mpPolyPolygon->remove(nIndex, nCount); } + } - sal_Bool B2DPolyPolygon::isClosed() const + void B2DPolyPolygon::clear() + { + if(mpPolyPolygon->getRefCount()) + { + mpPolyPolygon->decRefCount(); + } + else { - sal_Bool bRetval(sal_True); + delete mpPolyPolygon; + } - // PolyPOlygon is closed when all contained Polygons are closed or - // no Polygon exists. - for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++) - { - if(!(mpPolyPolygon->getB2DPolygon(a)).isClosed()) - { - bRetval = sal_False; - } - } + mpPolyPolygon = &maStaticDefaultPolyPolygon; + mpPolyPolygon->incRefCount(); + } - return bRetval; - } + sal_Bool B2DPolyPolygon::isClosed() const + { + sal_Bool bRetval(sal_True); - void B2DPolyPolygon::setClosed(sal_Bool bNew) + // PolyPOlygon is closed when all contained Polygons are closed or + // no Polygon exists. + for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++) { - if(bNew != isClosed()) + if(!(mpPolyPolygon->getB2DPolygon(a)).isClosed()) { - implForceUniqueCopy(); - mpPolyPolygon->setClosed(bNew); + bRetval = sal_False; } } - void B2DPolyPolygon::flip() + return bRetval; + } + + void B2DPolyPolygon::setClosed(sal_Bool bNew) + { + if(bNew != isClosed()) { implForceUniqueCopy(); - mpPolyPolygon->flip(); + mpPolyPolygon->setClosed(bNew); } + } - sal_Bool B2DPolyPolygon::hasDoublePoints() const - { - sal_Bool bRetval(sal_False); - - for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++) - { - if((mpPolyPolygon->getB2DPolygon(a)).hasDoublePoints()) - { - bRetval = sal_True; - } - } + void B2DPolyPolygon::flip() + { + implForceUniqueCopy(); + mpPolyPolygon->flip(); + } - return bRetval; - } + sal_Bool B2DPolyPolygon::hasDoublePoints() const + { + sal_Bool bRetval(sal_False); - void B2DPolyPolygon::removeDoublePoints() + for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++) { - if(hasDoublePoints()) + if((mpPolyPolygon->getB2DPolygon(a)).hasDoublePoints()) { - implForceUniqueCopy(); - mpPolyPolygon->removeDoublePoints(); + bRetval = sal_True; } } - void B2DPolyPolygon::transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + return bRetval; + } + + void B2DPolyPolygon::removeDoublePoints() + { + if(hasDoublePoints()) { implForceUniqueCopy(); - mpPolyPolygon->transform(rMatrix); + mpPolyPolygon->removeDoublePoints(); } - } // end of namespace polygon + } + + void B2DPolyPolygon::transform(const ::basegfx::B2DHomMatrix& rMatrix) + { + implForceUniqueCopy(); + mpPolyPolygon->transform(rMatrix); + } } // end of namespace basegfx // eof diff --git a/basegfx/source/polygon/b2dpolypolygoncutter.cxx b/basegfx/source/polygon/b2dpolypolygoncutter.cxx index a86bfce3d937..17d1c476acbf 100644 --- a/basegfx/source/polygon/b2dpolypolygoncutter.cxx +++ b/basegfx/source/polygon/b2dpolypolygoncutter.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygoncutter.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:12 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -88,231 +88,228 @@ namespace basegfx { - namespace polygon + B2DPolygonNode::B2DPolygonNode(const ::basegfx::B2DPoint& rPosition, B2DPolygonNode* pPrevious) + : maPosition(rPosition) { - B2DPolygonNode::B2DPolygonNode(const ::basegfx::point::B2DPoint& rPosition, B2DPolygonNode* pPrevious) - : maPosition(rPosition) - { - mpListPrevious = this; - mpListNext = this; + mpListPrevious = this; + mpListNext = this; - if(pPrevious) - { - mpNext = pPrevious->getNext(); - mpPrevious = pPrevious; - mpNext->mpPrevious = this; - mpPrevious->mpNext = this; - } - else - { - mpPrevious = mpNext = this; - } + if(pPrevious) + { + mpNext = pPrevious->getNext(); + mpPrevious = pPrevious; + mpNext->mpPrevious = this; + mpPrevious->mpNext = this; } - - B2DPolygonNode::~B2DPolygonNode() + else { - if(mpNext != this) - { - mpPrevious->mpNext = mpNext; - mpNext->mpPrevious = mpPrevious; - } + mpPrevious = mpNext = this; } + } - void B2DPolygonNode::calcMinMaxX(double& fMaxAX, double& fMinAX) const + B2DPolygonNode::~B2DPolygonNode() + { + if(mpNext != this) { - if(maPosition.getX() > mpNext->maPosition.getX()) - { - fMaxAX = maPosition.getX(); - fMinAX = mpNext->maPosition.getX(); - } - else - { - fMaxAX = mpNext->maPosition.getX(); - fMinAX = maPosition.getX(); - } + mpPrevious->mpNext = mpNext; + mpNext->mpPrevious = mpPrevious; } + } - void B2DPolygonNode::calcMinMaxY(double& fMaxAY, double& fMinAY) const + void B2DPolygonNode::calcMinMaxX(double& fMaxAX, double& fMinAX) const + { + if(maPosition.getX() > mpNext->maPosition.getX()) { - if(maPosition.getY() > mpNext->maPosition.getY()) - { - fMaxAY = maPosition.getY(); - fMinAY = mpNext->maPosition.getY(); - } - else - { - fMaxAY = mpNext->maPosition.getY(); - fMinAY = maPosition.getY(); - } + fMaxAX = maPosition.getX(); + fMinAX = mpNext->maPosition.getX(); + } + else + { + fMaxAX = mpNext->maPosition.getX(); + fMinAX = maPosition.getX(); } + } - void B2DPolygonNode::swapNextPointers(B2DPolygonNode* pCand) + void B2DPolygonNode::calcMinMaxY(double& fMaxAY, double& fMinAY) const + { + if(maPosition.getY() > mpNext->maPosition.getY()) { - B2DPolygonNode* pTemporary = mpNext; - mpNext = pCand->mpNext; - pCand->mpNext = pTemporary; - mpNext->mpPrevious = this; - pCand->mpNext->mpPrevious = pCand; + fMaxAY = maPosition.getY(); + fMinAY = mpNext->maPosition.getY(); + } + else + { + fMaxAY = mpNext->maPosition.getY(); + fMinAY = maPosition.getY(); } + } - void B2DPolygonNode::addToList(B2DPolygonNode*& rpList) + void B2DPolygonNode::swapNextPointers(B2DPolygonNode* pCand) + { + B2DPolygonNode* pTemporary = mpNext; + mpNext = pCand->mpNext; + pCand->mpNext = pTemporary; + mpNext->mpPrevious = this; + pCand->mpNext->mpPrevious = pCand; + } + + void B2DPolygonNode::addToList(B2DPolygonNode*& rpList) + { + if(rpList) { - if(rpList) - { - mpListNext = rpList->mpListNext; - rpList->mpListNext = this; - mpListPrevious = rpList; - mpListNext->mpListPrevious = this; - } - else - { - rpList = this; - } + mpListNext = rpList->mpListNext; + rpList->mpListNext = this; + mpListPrevious = rpList; + mpListNext->mpListPrevious = this; + } + else + { + rpList = this; } + } - void B2DPolygonNode::remFromList(B2DPolygonNode*& rpList) + void B2DPolygonNode::remFromList(B2DPolygonNode*& rpList) + { + if(mpListNext != this) { - if(mpListNext != this) + if(rpList == this) { - if(rpList == this) - { - rpList = mpListPrevious; - } - - mpListPrevious->mpListNext = mpListNext; - mpListNext->mpListPrevious = mpListPrevious; - mpListNext = mpListPrevious = this; + rpList = mpListPrevious; } - else + + mpListPrevious->mpListNext = mpListNext; + mpListNext->mpListPrevious = mpListPrevious; + mpListNext = mpListPrevious = this; + } + else + { + if(rpList == this) { - if(rpList == this) - { - rpList = 0L; - } + rpList = 0L; } } + } - sal_Bool B2DPolygonNode::getOrientation() const - { - const B2DPolygonNode* pOutmost = this; - const B2DPolygonNode* pCurrent = this->getNext(); + sal_Bool B2DPolygonNode::getOrientation() const + { + const B2DPolygonNode* pOutmost = this; + const B2DPolygonNode* pCurrent = this->getNext(); - while(pCurrent != this) + while(pCurrent != this) + { + if(::basegfx::fTools::more(pOutmost->getPosition().getX(), pCurrent->getPosition().getX())) { - if(::basegfx::numeric::fTools::more(pOutmost->getPosition().getX(), pCurrent->getPosition().getX())) + if(pCurrent->getPosition().getX() < pOutmost->getPosition().getX()) + { + pOutmost = pCurrent; + } + else { - if(pCurrent->getPosition().getX() < pOutmost->getPosition().getX()) + if(pCurrent->getPosition().getY() < pOutmost->getPosition().getY()) { pOutmost = pCurrent; } - else - { - if(pCurrent->getPosition().getY() < pOutmost->getPosition().getY()) - { - pOutmost = pCurrent; - } - } } - - // next node - pCurrent = pCurrent->getNext(); } - ::basegfx::vector::B2DVector aVec1(pOutmost->getPrevious()->getPosition() - pOutmost->getPosition()); - ::basegfx::vector::B2DVector aVec2(pOutmost->getNext()->getPosition() - pOutmost->getPosition()); - return sal_Bool(::basegfx::numeric::fTools::more(aVec1.getX() * aVec2.getY(), aVec1.getY() * aVec2.getX())); + // next node + pCurrent = pCurrent->getNext(); } - void B2DPolygonNode::swapOrientation() - { - B2DPolygonNode* pCurrent = this; + ::basegfx::B2DVector aVec1(pOutmost->getPrevious()->getPosition() - pOutmost->getPosition()); + ::basegfx::B2DVector aVec2(pOutmost->getNext()->getPosition() - pOutmost->getPosition()); + return sal_Bool(::basegfx::fTools::more(aVec1.getX() * aVec2.getY(), aVec1.getY() * aVec2.getX())); + } - do { - pCurrent->swapPreviousNext(); - pCurrent = pCurrent->getPrevious(); - } while(pCurrent != this); - } + void B2DPolygonNode::swapOrientation() + { + B2DPolygonNode* pCurrent = this; - ::basegfx::range::B2DRange B2DPolygonNode::getRange() const - { - ::basegfx::range::B2DRange aRetval; - const B2DPolygonNode* pCurrent = this; + do { + pCurrent->swapPreviousNext(); + pCurrent = pCurrent->getPrevious(); + } while(pCurrent != this); + } - do { - aRetval.expand(pCurrent->getPosition()); - pCurrent = pCurrent->getPrevious(); - } while(pCurrent != this); + ::basegfx::B2DRange B2DPolygonNode::getRange() const + { + ::basegfx::B2DRange aRetval; + const B2DPolygonNode* pCurrent = this; - return aRetval; - } + do { + aRetval.expand(pCurrent->getPosition()); + pCurrent = pCurrent->getPrevious(); + } while(pCurrent != this); - sal_Bool B2DPolygonNode::isInside(const ::basegfx::point::B2DPoint& rPoint, sal_Bool bWithBorder) const + return aRetval; + } + + sal_Bool B2DPolygonNode::isInside(const ::basegfx::B2DPoint& rPoint, sal_Bool bWithBorder) const + { + sal_Bool bInside(sal_False); + const B2DPolygonNode* pCurrent = this; + + do { - sal_Bool bInside(sal_False); - const B2DPolygonNode* pCurrent = this; + if(bWithBorder && pCurrent->getPosition().equal(rPoint)) + { + return sal_True; + } + + B2DPolygonNode* pNext = pCurrent->getNext(); + const sal_Bool bCompYA(::basegfx::fTools::more(pCurrent->getPosition().getY(), rPoint.getY())); + const sal_Bool bCompYB(::basegfx::fTools::more(pNext->getPosition().getY(), rPoint.getY())); - do + if(bCompYA != bCompYB) { - if(bWithBorder && pCurrent->getPosition().equal(rPoint)) + const sal_Bool bCompXA(::basegfx::fTools::more(pCurrent->getPosition().getX(), rPoint.getX())); + const sal_Bool bCompXB(::basegfx::fTools::more(pNext->getPosition().getX(), rPoint.getX())); + + if(bCompXA == bCompXB) { - return sal_True; + if(bCompXA) + { + bInside = !bInside; + } } - - B2DPolygonNode* pNext = pCurrent->getNext(); - const sal_Bool bCompYA(::basegfx::numeric::fTools::more(pCurrent->getPosition().getY(), rPoint.getY())); - const sal_Bool bCompYB(::basegfx::numeric::fTools::more(pNext->getPosition().getY(), rPoint.getY())); - - if(bCompYA != bCompYB) + else { - const sal_Bool bCompXA(::basegfx::numeric::fTools::more(pCurrent->getPosition().getX(), rPoint.getX())); - const sal_Bool bCompXB(::basegfx::numeric::fTools::more(pNext->getPosition().getX(), rPoint.getX())); + double fCmp = + pNext->getPosition().getX() - (pNext->getPosition().getY() - rPoint.getY()) * + (pCurrent->getPosition().getX() - pNext->getPosition().getX()) / + (pCurrent->getPosition().getY() - pNext->getPosition().getY()); - if(bCompXA == bCompXB) + if(bWithBorder && ::basegfx::fTools::more(fCmp, rPoint.getX())) { - if(bCompXA) - { - bInside = !bInside; - } + bInside = !bInside; } - else + else if(::basegfx::fTools::moreOrEqual(fCmp, rPoint.getX())) { - double fCmp = - pNext->getPosition().getX() - (pNext->getPosition().getY() - rPoint.getY()) * - (pCurrent->getPosition().getX() - pNext->getPosition().getX()) / - (pCurrent->getPosition().getY() - pNext->getPosition().getY()); - - if(bWithBorder && ::basegfx::numeric::fTools::more(fCmp, rPoint.getX())) - { - bInside = !bInside; - } - else if(::basegfx::numeric::fTools::moreOrEqual(fCmp, rPoint.getX())) - { - bInside = !bInside; - } + bInside = !bInside; } } + } - // next edge - pCurrent = pNext; + // next edge + pCurrent = pNext; - } while(pCurrent != this); + } while(pCurrent != this); - return bInside; - } + return bInside; + } - sal_Bool B2DPolygonNode::isPolygonInside(B2DPolygonNode* pPoly, sal_Bool bWithBorder) const - { - B2DPolygonNode* pTest = pPoly; - sal_Bool bAllAInside(sal_True); + sal_Bool B2DPolygonNode::isPolygonInside(B2DPolygonNode* pPoly, sal_Bool bWithBorder) const + { + B2DPolygonNode* pTest = pPoly; + sal_Bool bAllAInside(sal_True); - do { - bAllAInside = isInside(pTest->getPosition(), bWithBorder); - pTest = pTest->getNext(); - } while(bAllAInside && pTest != pPoly); + do { + bAllAInside = isInside(pTest->getPosition(), bWithBorder); + pTest = pTest->getNext(); + } while(bAllAInside && pTest != pPoly); - return bAllAInside; - } - } // end of namespace polygon + return bAllAInside; + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -320,26 +317,23 @@ namespace basegfx namespace basegfx { - namespace polygon + void B2DSimpleCut::solve() { - void B2DSimpleCut::solve() - { - mpLeft->swapNextPointers(mpRight); + mpLeft->swapNextPointers(mpRight); - if(mbCorrectOrientation) + if(mbCorrectOrientation) + { + if(mpLeft->getOrientation() != mbOrientation) { - if(mpLeft->getOrientation() != mbOrientation) - { - mpLeft->swapOrientation(); - } + mpLeft->swapOrientation(); + } - if(mpRight->getOrientation() != mbOrientation) - { - mpRight->swapOrientation(); - } + if(mpRight->getOrientation() != mbOrientation) + { + mpRight->swapOrientation(); } } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -347,27 +341,24 @@ namespace basegfx namespace basegfx { - namespace polygon + void B2DClipExtraPolygonInfo::init(B2DPolygonNode* pNew) { - void B2DClipExtraPolygonInfo::init(B2DPolygonNode* pNew) + maRange = pNew->getRange(); + mbOrientation = pNew->getOrientation(); + mnDepth = (mbOrientation) ? 0L : -1L; + } + + void B2DClipExtraPolygonInfo::changeDepth(sal_Bool bOrientation) + { + if(bOrientation) { - maRange = pNew->getRange(); - mbOrientation = pNew->getOrientation(); - mnDepth = (mbOrientation) ? 0L : -1L; + mnDepth++; } - - void B2DClipExtraPolygonInfo::changeDepth(sal_Bool bOrientation) + else { - if(bOrientation) - { - mnDepth++; - } - else - { - mnDepth--; - } + mnDepth--; } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -375,772 +366,769 @@ namespace basegfx namespace basegfx { - namespace polygon + B2DPolyPolygonCutter::~B2DPolyPolygonCutter() { - B2DPolyPolygonCutter::~B2DPolyPolygonCutter() + for(sal_uInt32 a(0L); a < maPolygonList.size(); a++) { - for(sal_uInt32 a(0L); a < maPolygonList.size(); a++) - { - delete maPolygonList[a]; - } - - maPolygonList.clear(); + delete maPolygonList[a]; } - void B2DPolyPolygonCutter::removeIncludedPolygons(sal_Bool bUseOr) + maPolygonList.clear(); + } + + void B2DPolyPolygonCutter::removeIncludedPolygons(sal_Bool bUseOr) + { + const sal_uInt32 aCount(maPolygonList.size()); + B2DClipExtraPolygonInfo* pInfos = new B2DClipExtraPolygonInfo[aCount]; + sal_uInt32 a, b; + + // fill infos + for(a = 0L; a < aCount; a++) { - const sal_uInt32 aCount(maPolygonList.size()); - B2DClipExtraPolygonInfo* pInfos = new B2DClipExtraPolygonInfo[aCount]; - sal_uInt32 a, b; + pInfos[a].init(maPolygonList[a]); + } - // fill infos - for(a = 0L; a < aCount; a++) - { - pInfos[a].init(maPolygonList[a]); - } + // get all includes + for(a = 0L; a < aCount; a++) + { + B2DClipExtraPolygonInfo& rInfoA = pInfos[a]; - // get all includes - for(a = 0L; a < aCount; a++) + for(b = 0L; b < aCount; b++) { - B2DClipExtraPolygonInfo& rInfoA = pInfos[a]; + B2DClipExtraPolygonInfo& rInfoB = pInfos[b]; - for(b = 0L; b < aCount; b++) + if(a != b && doRangesInclude(rInfoA.getRange(), rInfoB.getRange())) { - B2DClipExtraPolygonInfo& rInfoB = pInfos[b]; - - if(a != b && doRangesInclude(rInfoA.getRange(), rInfoB.getRange())) + // volume B in A, test pA, pB for inclusion, with border + if(maPolygonList[a]->isPolygonInside(maPolygonList[b], sal_True)) { - // volume B in A, test pA, pB for inclusion, with border - if(maPolygonList[a]->isPolygonInside(maPolygonList[b], sal_True)) - { - // pB is inside pA - rInfoB.changeDepth(rInfoA.getOrientation()); - } + // pB is inside pA + rInfoB.changeDepth(rInfoA.getOrientation()); } } } + } - // delete removable - for(a = 0L, b = 0L; a < aCount; a++) - { - B2DClipExtraPolygonInfo& rInfo = pInfos[a]; + // delete removable + for(a = 0L, b = 0L; a < aCount; a++) + { + B2DClipExtraPolygonInfo& rInfo = pInfos[a]; - if((bUseOr && rInfo.getDepth() != 0L) || (!bUseOr && rInfo.getDepth() < 1L)) - { - B2DPolygonNodeVector::iterator aPosition(maPolygonList.begin() + b); - B2DPolygonNode* pCandidate = *aPosition; - maPolygonList.erase(aPosition); - deletePolygon(pCandidate); - } - else - { - b++; - } + if((bUseOr && rInfo.getDepth() != 0L) || (!bUseOr && rInfo.getDepth() < 1L)) + { + B2DPolygonNodeVector::iterator aPosition(maPolygonList.begin() + b); + B2DPolygonNode* pCandidate = *aPosition; + maPolygonList.erase(aPosition); + deletePolygon(pCandidate); + } + else + { + b++; } - - // delete infos - delete[] pInfos; } - void B2DPolyPolygonCutter::solveAllCuts(B2DSimpleCutVector& rCuts) - { - B2DPolygonNode* pNewList = 0L; - - // add all nodes of polys to list - polysToList(pNewList); + // delete infos + delete[] pInfos; + } - // solve cuts - B2DSimpleCutVector::iterator aCandidate(rCuts.begin()); + void B2DPolyPolygonCutter::solveAllCuts(B2DSimpleCutVector& rCuts) + { + B2DPolygonNode* pNewList = 0L; - for(; aCandidate < rCuts.end(); aCandidate++) - { - B2DSimpleCut* pCut = *aCandidate; - pCut->solve(); - delete pCut; - } + // add all nodes of polys to list + polysToList(pNewList); - rCuts.clear(); + // solve cuts + B2DSimpleCutVector::iterator aCandidate(rCuts.begin()); - // extract polys - listToPolys(pNewList); + for(; aCandidate < rCuts.end(); aCandidate++) + { + B2DSimpleCut* pCut = *aCandidate; + pCut->solve(); + delete pCut; } - void B2DPolyPolygonCutter::polysToList(B2DPolygonNode*& rpList) - { - B2DPolygonNodeVector::iterator aCandidate(maPolygonList.begin()); + rCuts.clear(); - for(; aCandidate != maPolygonList.end(); aCandidate++) - { - addAllNodes(*aCandidate, rpList); - } + // extract polys + listToPolys(pNewList); + } - maPolygonList.clear(); - } + void B2DPolyPolygonCutter::polysToList(B2DPolygonNode*& rpList) + { + B2DPolygonNodeVector::iterator aCandidate(maPolygonList.begin()); - void B2DPolyPolygonCutter::listToPolys(B2DPolygonNode*& rpList) + for(; aCandidate != maPolygonList.end(); aCandidate++) { - while(rpList) - { - // get one - B2DPolygonNode* pNew = extractNextPolygon(rpList); - - if(pNew) - { - maPolygonList.push_back(pNew); - } - } + addAllNodes(*aCandidate, rpList); } - B2DPolygonNode* B2DPolyPolygonCutter::createNewPolygon(const B2DPolygon& rPolygon) + maPolygonList.clear(); + } + + void B2DPolyPolygonCutter::listToPolys(B2DPolygonNode*& rpList) + { + while(rpList) { - B2DPolygonNode* pRetval = NULL; + // get one + B2DPolygonNode* pNew = extractNextPolygon(rpList); - for(sal_uInt32 a(0L); a < rPolygon.count(); a++) + if(pNew) { - ::basegfx::point::B2DPoint aPoint(rPolygon.getB2DPoint(a)); - pRetval = new B2DPolygonNode(aPoint, pRetval); + maPolygonList.push_back(pNew); } - - return pRetval; } + } + + B2DPolygonNode* B2DPolyPolygonCutter::createNewPolygon(const B2DPolygon& rPolygon) + { + B2DPolygonNode* pRetval = NULL; - void B2DPolyPolygonCutter::deletePolygon(B2DPolygonNode* pCand) + for(sal_uInt32 a(0L); a < rPolygon.count(); a++) { - B2DPolygonNode* pPoly = pCand; + ::basegfx::B2DPoint aPoint(rPolygon.getB2DPoint(a)); + pRetval = new B2DPolygonNode(aPoint, pRetval); + } - while(pPoly) - { - B2DPolygonNode* pNext = pPoly->getNext(); + return pRetval; + } - if(pNext == pPoly) - { - pNext = 0L; - } + void B2DPolyPolygonCutter::deletePolygon(B2DPolygonNode* pCand) + { + B2DPolygonNode* pPoly = pCand; + + while(pPoly) + { + B2DPolygonNode* pNext = pPoly->getNext(); - delete pPoly; - pPoly = pNext; + if(pNext == pPoly) + { + pNext = 0L; } + + delete pPoly; + pPoly = pNext; } + } - void B2DPolyPolygonCutter::addAllNodes(B2DPolygonNode* pPolygon, B2DPolygonNode*& rpList) - { - B2DPolygonNode* pAct = pPolygon; + void B2DPolyPolygonCutter::addAllNodes(B2DPolygonNode* pPolygon, B2DPolygonNode*& rpList) + { + B2DPolygonNode* pAct = pPolygon; - do { - pAct->addToList(rpList); - pAct = pAct->getNext(); - } while(pAct != pPolygon); - } + do { + pAct->addToList(rpList); + pAct = pAct->getNext(); + } while(pAct != pPolygon); + } - void B2DPolyPolygonCutter::addPolyPolygon(const B2DPolyPolygon& rPolyPolygon, sal_Bool bForceOrientation) + void B2DPolyPolygonCutter::addPolyPolygon(const B2DPolyPolygon& rPolyPolygon, sal_Bool bForceOrientation) + { + for(sal_uInt32 a(0L); a < rPolyPolygon.count(); a++) { - for(sal_uInt32 a(0L); a < rPolyPolygon.count(); a++) - { - B2DPolygon aCandidate = rPolyPolygon.getB2DPolygon(a); - aCandidate.removeDoublePoints(); + B2DPolygon aCandidate = rPolyPolygon.getB2DPolygon(a); + aCandidate.removeDoublePoints(); - if(!aCandidate.isClosed() || aCandidate.count() < 3) - { - maNotClosedPolygons.append(aCandidate); - } - else + if(!aCandidate.isClosed() || aCandidate.count() < 3) + { + maNotClosedPolygons.append(aCandidate); + } + else + { + if(bForceOrientation) { - if(bForceOrientation) - { - ::basegfx::vector::B2DVectorOrientation aOrientation = - ::basegfx::polygon::tools::getOrientation(aCandidate); + ::basegfx::B2DVectorOrientation aOrientation = + ::basegfx::tools::getOrientation(aCandidate); - if(::basegfx::vector::ORIENTATION_POSITIVE != aOrientation) - { - aCandidate.flip(); - } + if(::basegfx::ORIENTATION_POSITIVE != aOrientation) + { + aCandidate.flip(); } - - B2DPolygonNode* pNew = createNewPolygon(aCandidate); - maPolygonList.push_back(pNew); } + + B2DPolygonNode* pNew = createNewPolygon(aCandidate); + maPolygonList.push_back(pNew); } } + } + + void B2DPolyPolygonCutter::getPolyPolygon(B2DPolyPolygon& rPolyPolygon) + { + B2DPolygonNodeVector::iterator aCandidate(maPolygonList.begin()); - void B2DPolyPolygonCutter::getPolyPolygon(B2DPolyPolygon& rPolyPolygon) + for(; aCandidate < maPolygonList.end(); aCandidate++) { - B2DPolygonNodeVector::iterator aCandidate(maPolygonList.begin()); + B2DPolygonNode* pCand = *aCandidate; + B2DPolygonNode* pAct = pCand; + sal_uInt32 nCount(0L); + + do { + nCount++; + pAct = pAct->getNext(); + } while(pAct != pCand); - for(; aCandidate < maPolygonList.end(); aCandidate++) + if(nCount > 2L) { - B2DPolygonNode* pCand = *aCandidate; - B2DPolygonNode* pAct = pCand; - sal_uInt32 nCount(0L); + B2DPolygon aNewPolygon; do { - nCount++; + aNewPolygon.append(pAct->getPosition()); pAct = pAct->getNext(); } while(pAct != pCand); - if(nCount > 2L) - { - B2DPolygon aNewPolygon; + aNewPolygon.setClosed(sal_True); + rPolyPolygon.append(aNewPolygon); + } - do { - aNewPolygon.append(pAct->getPosition()); - pAct = pAct->getNext(); - } while(pAct != pCand); + deletePolygon(pCand); + } - aNewPolygon.setClosed(sal_True); - rPolyPolygon.append(aNewPolygon); - } + maPolygonList.clear(); - deletePolygon(pCand); - } + while(maNotClosedPolygons.count()) + { + rPolyPolygon.append(maNotClosedPolygons.getB2DPolygon(0L)); + maNotClosedPolygons.remove(0L); + } + } - maPolygonList.clear(); + B2DSimpleCut* B2DPolyPolygonCutter::getExistingCut(B2DSimpleCutVector& rTmpCuts, B2DPolygonNode* pA, B2DPolygonNode* pB) + { + for(sal_uInt32 a(0L); a < rTmpCuts.size(); a++) + { + B2DSimpleCut* pCand = rTmpCuts[a]; - while(maNotClosedPolygons.count()) + if(pCand->isSameCut(pA, pB)) { - rPolyPolygon.append(maNotClosedPolygons.getB2DPolygon(0L)); - maNotClosedPolygons.remove(0L); + return pCand; } } - B2DSimpleCut* B2DPolyPolygonCutter::getExistingCut(B2DSimpleCutVector& rTmpCuts, B2DPolygonNode* pA, B2DPolygonNode* pB) - { - for(sal_uInt32 a(0L); a < rTmpCuts.size(); a++) - { - B2DSimpleCut* pCand = rTmpCuts[a]; + return 0L; + } - if(pCand->isSameCut(pA, pB)) - { - return pCand; - } - } + B2DPolygonNode* B2DPolyPolygonCutter::extractNextPolygon(B2DPolygonNode*& rpList) + { + B2DPolygonNode* pStart = rpList; + + // remove all nodes of this poly from list + B2DPolygonNode* pAct = pStart; + sal_uInt32 nNumNodes(0L); + + do { + pAct->remFromList(rpList); + pAct = pAct->getNext(); + nNumNodes++; + } while(pAct != pStart); + if(nNumNodes < 3L) + { + deletePolygon(pStart); return 0L; } - - B2DPolygonNode* B2DPolyPolygonCutter::extractNextPolygon(B2DPolygonNode*& rpList) + else { - B2DPolygonNode* pStart = rpList; - - // remove all nodes of this poly from list - B2DPolygonNode* pAct = pStart; - sal_uInt32 nNumNodes(0L); - - do { - pAct->remFromList(rpList); - pAct = pAct->getNext(); - nNumNodes++; - } while(pAct != pStart); - - if(nNumNodes < 3L) - { - deletePolygon(pStart); - return 0L; - } - else - { - return pStart; - } + return pStart; } + } - void B2DPolyPolygonCutter::removeSelfIntersections() + void B2DPolyPolygonCutter::removeSelfIntersections() + { + B2DSimpleCutVector aCuts; + B2DSimpleCutVector aNewCuts; + B2DPolygonNode* pCand; + B2DPolygonNode* pA; + B2DPolygonNode* pB; + double fMaxAX, fMinAX, fMaxAY, fMinAY; + double fMaxBX, fMinBX, fMaxBY, fMinBY; + double fCut; + + // first job: Find all cuts and add points there + for(sal_uInt32 a(0L); a < maPolygonList.size(); a++) { - B2DSimpleCutVector aCuts; - B2DSimpleCutVector aNewCuts; - B2DPolygonNode* pCand; - B2DPolygonNode* pA; - B2DPolygonNode* pB; - double fMaxAX, fMinAX, fMaxAY, fMinAY; - double fMaxBX, fMinBX, fMaxBY, fMinBY; - double fCut; - - // first job: Find all cuts and add points there - for(sal_uInt32 a(0L); a < maPolygonList.size(); a++) - { - pCand = maPolygonList[a]; - pA = pCand; + pCand = maPolygonList[a]; + pA = pCand; + + // one run to find same start positions (so there is no need to + // search for existing cuts in main loop) + do { + pB = pA->getNext(); - // one run to find same start positions (so there is no need to - // search for existing cuts in main loop) do { - pB = pA->getNext(); + if(isSamePos(pA->getPosition(), pB->getPosition())) + { + aNewCuts.push_back(new B2DSimpleCut(pA, pB, sal_True, pCand->getOrientation())); + } - do { - if(isSamePos(pA->getPosition(), pB->getPosition())) - { - aNewCuts.push_back(new B2DSimpleCut(pA, pB, sal_True, pCand->getOrientation())); - } + // next B + pB = pB->getNext(); + } while(pB != pCand); - // next B - pB = pB->getNext(); - } while(pB != pCand); + // next A + pA = pA->getNext(); + } while(pA->getNext() != pCand); - // next A - pA = pA->getNext(); - } while(pA->getNext() != pCand); + // second run to find real cuts + pA = pCand; - // second run to find real cuts - pA = pCand; + do { + // get bounds for this edge in poly + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); + pB = pA->getNext(); do { - // get bounds for this edge in poly - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); - pB = pA->getNext(); + pB->calcMinMaxX(fMaxBX, fMinBX); - do { - pB->calcMinMaxX(fMaxBX, fMinBX); + if(::basegfx::fTools::more(fMaxBX, fMinAX) + && ::basegfx::fTools::more(fMaxAX, fMinBX)) + { + pB->calcMinMaxY(fMaxBY, fMinBY); - if(::basegfx::numeric::fTools::more(fMaxBX, fMinAX) - && ::basegfx::numeric::fTools::more(fMaxAX, fMinBX)) + if(::basegfx::fTools::more(fMaxBY, fMinAY) + && ::basegfx::fTools::more(fMaxAY, fMinBY)) { - pB->calcMinMaxY(fMaxBY, fMinBY); - - if(::basegfx::numeric::fTools::more(fMaxBY, fMinAY) - && ::basegfx::numeric::fTools::more(fMaxAY, fMinBY)) + if(!isSamePos(pA->getPosition(), pB->getPosition())) { - if(!isSamePos(pA->getPosition(), pB->getPosition())) - { - const ::basegfx::vector::B2DVector aVectorA(pA->getNext()->getPosition() - pA->getPosition()); - const ::basegfx::vector::B2DVector aVectorB(pB->getNext()->getPosition() - pB->getPosition()); + const ::basegfx::B2DVector aVectorA(pA->getNext()->getPosition() - pA->getPosition()); + const ::basegfx::B2DVector aVectorB(pB->getNext()->getPosition() - pB->getPosition()); - if(::basegfx::polygon::tools::findCut(pA->getPosition(), aVectorA, pB->getPosition(), aVectorB, CUTFLAG_LINE, &fCut)) + if(::basegfx::tools::findCut(pA->getPosition(), aVectorA, pB->getPosition(), aVectorB, CUTFLAG_LINE, &fCut)) + { + // crossover, two new points + ::basegfx::B2DPoint aNewPos(::basegfx::interpolate(pA->getPosition(), pA->getNext()->getPosition(), fCut)); + B2DPolygonNode* pCutLo = new B2DPolygonNode(aNewPos, pA); + B2DPolygonNode* pCutHi = new B2DPolygonNode(aNewPos, pB); + aNewCuts.push_back(new B2DSimpleCut(pCutLo, pCutHi, sal_True, pCand->getOrientation())); + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); + } + else + { + if(::basegfx::tools::isPointOnEdge(pA->getPosition(), pB->getPosition(), aVectorB, &fCut)) { - // crossover, two new points - ::basegfx::point::B2DPoint aNewPos(::basegfx::tuple::interpolate(pA->getPosition(), pA->getNext()->getPosition(), fCut)); - B2DPolygonNode* pCutLo = new B2DPolygonNode(aNewPos, pA); - B2DPolygonNode* pCutHi = new B2DPolygonNode(aNewPos, pB); - aNewCuts.push_back(new B2DSimpleCut(pCutLo, pCutHi, sal_True, pCand->getOrientation())); - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); + // startpoint A at edge B, one new point + B2DPolygonNode* pCutHi = new B2DPolygonNode(pA->getPosition(), pB); + aNewCuts.push_back(new B2DSimpleCut(pA, pCutHi, sal_True, pCand->getOrientation())); } - else + else if(::basegfx::tools::isPointOnEdge(pB->getPosition(), pA->getPosition(), aVectorA, &fCut)) { - if(::basegfx::polygon::tools::isPointOnEdge(pA->getPosition(), pB->getPosition(), aVectorB, &fCut)) - { - // startpoint A at edge B, one new point - B2DPolygonNode* pCutHi = new B2DPolygonNode(pA->getPosition(), pB); - aNewCuts.push_back(new B2DSimpleCut(pA, pCutHi, sal_True, pCand->getOrientation())); - } - else if(::basegfx::polygon::tools::isPointOnEdge(pB->getPosition(), pA->getPosition(), aVectorA, &fCut)) - { - // startpoint B at edge A, one new point - B2DPolygonNode* pCutLo = new B2DPolygonNode(pB->getPosition(), pA); - aNewCuts.push_back(new B2DSimpleCut(pCutLo, pB, sal_True, pCand->getOrientation())); - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); - } + // startpoint B at edge A, one new point + B2DPolygonNode* pCutLo = new B2DPolygonNode(pB->getPosition(), pA); + aNewCuts.push_back(new B2DSimpleCut(pCutLo, pB, sal_True, pCand->getOrientation())); + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); } } } } + } - // next B - pB = pB->getNext(); - } while(pB != pCand); + // next B + pB = pB->getNext(); + } while(pB != pCand); - // next A - pA = pA->getNext(); - } while(pA->getNext() != pCand); + // next A + pA = pA->getNext(); + } while(pA->getNext() != pCand); - // copy new cuts to cuts - aCuts.insert(aCuts.begin(), aNewCuts.begin(), aNewCuts.end()); - aNewCuts.clear(); - } + // copy new cuts to cuts + aCuts.insert(aCuts.begin(), aNewCuts.begin(), aNewCuts.end()); + aNewCuts.clear(); + } - // second job: if there were cuts, split polys - if(aCuts.size()) - { - solveAllCuts(aCuts); - } + // second job: if there were cuts, split polys + if(aCuts.size()) + { + solveAllCuts(aCuts); } + } - sal_Bool B2DPolyPolygonCutter::isCrossover(B2DPolygonNode* pA, B2DPolygonNode* pB) + sal_Bool B2DPolyPolygonCutter::isCrossover(B2DPolygonNode* pA, B2DPolygonNode* pB) + { + // build entering vectors + ::basegfx::B2DVector aVecA(pA->getPrevious()->getPosition() - pA->getPosition()); + ::basegfx::B2DVector aVecB(pB->getPrevious()->getPosition() - pA->getPosition()); + aVecA.normalize(); + aVecB.normalize(); + double fDegreeA2 = atan2(aVecA.getY(), aVecA.getX()); + double fDegreeB2 = atan2(aVecB.getY(), aVecB.getX()); + + // build leaving vectors + aVecA = pA->getNext()->getPosition() - pA->getPosition(); + aVecB = pB->getNext()->getPosition() - pA->getPosition(); + aVecA.normalize(); + aVecB.normalize(); + double fDegreeA1 = atan2(aVecA.getY(), aVecA.getX()); + double fDegreeB1 = atan2(aVecB.getY(), aVecB.getX()); + + // compare + if(fDegreeA1 > fDegreeA2) { - // build entering vectors - ::basegfx::vector::B2DVector aVecA(pA->getPrevious()->getPosition() - pA->getPosition()); - ::basegfx::vector::B2DVector aVecB(pB->getPrevious()->getPosition() - pA->getPosition()); - aVecA.normalize(); - aVecB.normalize(); - double fDegreeA2 = atan2(aVecA.getY(), aVecA.getX()); - double fDegreeB2 = atan2(aVecB.getY(), aVecB.getX()); - - // build leaving vectors - aVecA = pA->getNext()->getPosition() - pA->getPosition(); - aVecB = pB->getNext()->getPosition() - pA->getPosition(); - aVecA.normalize(); - aVecB.normalize(); - double fDegreeA1 = atan2(aVecA.getY(), aVecA.getX()); - double fDegreeB1 = atan2(aVecB.getY(), aVecB.getX()); - - // compare - if(fDegreeA1 > fDegreeA2) - { - double fTemp = fDegreeA2; - fDegreeA2 = fDegreeA1; - fDegreeA1 = fTemp; - } + double fTemp = fDegreeA2; + fDegreeA2 = fDegreeA1; + fDegreeA1 = fTemp; + } - sal_Bool bB1Inside(::basegfx::numeric::fTools::more(fDegreeB1, fDegreeA1) - && ::basegfx::numeric::fTools::more(fDegreeA2, fDegreeB1)); - sal_Bool bB2Inside(::basegfx::numeric::fTools::more(fDegreeB2, fDegreeA1) - && ::basegfx::numeric::fTools::more(fDegreeA2, fDegreeB2)); + sal_Bool bB1Inside(::basegfx::fTools::more(fDegreeB1, fDegreeA1) + && ::basegfx::fTools::more(fDegreeA2, fDegreeB1)); + sal_Bool bB2Inside(::basegfx::fTools::more(fDegreeB2, fDegreeA1) + && ::basegfx::fTools::more(fDegreeA2, fDegreeB2)); - if(bB1Inside && bB2Inside) - { - return sal_False; - } + if(bB1Inside && bB2Inside) + { + return sal_False; + } + + sal_Bool bB1Outside(::basegfx::fTools::more(fDegreeA1, fDegreeB1) + || ::basegfx::fTools::more(fDegreeB1, fDegreeA2)); + sal_Bool bB2Outside(::basegfx::fTools::more(fDegreeA1, fDegreeB2) + || ::basegfx::fTools::more(fDegreeB2, fDegreeA2)); - sal_Bool bB1Outside(::basegfx::numeric::fTools::more(fDegreeA1, fDegreeB1) - || ::basegfx::numeric::fTools::more(fDegreeB1, fDegreeA2)); - sal_Bool bB2Outside(::basegfx::numeric::fTools::more(fDegreeA1, fDegreeB2) - || ::basegfx::numeric::fTools::more(fDegreeB2, fDegreeA2)); + return !(bB1Outside && bB2Outside); + } - return !(bB1Outside && bB2Outside); + sal_Bool B2DPolyPolygonCutter::isCrossover(B2DSimpleCut* pEnter, B2DSimpleCut* pLeave) + { + // build entering vectors + ::basegfx::B2DVector aVecJ(pEnter->getLeft()->getNext()->getPosition() - pEnter->getLeft()->getPosition()); + ::basegfx::B2DVector aVecA(pEnter->getLeft()->getPrevious()->getPosition() - pEnter->getLeft()->getPosition()); + ::basegfx::B2DVector aVecB(pEnter->getRight()->getPrevious()->getPosition() - pEnter->getLeft()->getPosition()); + aVecJ.normalize(); + aVecA.normalize(); + aVecB.normalize(); + double fDegreeJo = atan2(aVecJ.getY(), aVecJ.getX()); + double fDegreeA2 = atan2(aVecA.getY(), aVecA.getX()) - fDegreeJo; + double fDegreeB2 = atan2(aVecB.getY(), aVecB.getX()) - fDegreeJo; + + // move to range [0..2PI[ + while(fDegreeA2 < 0.0) + { + fDegreeA2 += (2.0 * F_PI); } - sal_Bool B2DPolyPolygonCutter::isCrossover(B2DSimpleCut* pEnter, B2DSimpleCut* pLeave) + while(fDegreeA2 >= (2.0 * F_PI)) { - // build entering vectors - ::basegfx::vector::B2DVector aVecJ(pEnter->getLeft()->getNext()->getPosition() - pEnter->getLeft()->getPosition()); - ::basegfx::vector::B2DVector aVecA(pEnter->getLeft()->getPrevious()->getPosition() - pEnter->getLeft()->getPosition()); - ::basegfx::vector::B2DVector aVecB(pEnter->getRight()->getPrevious()->getPosition() - pEnter->getLeft()->getPosition()); - aVecJ.normalize(); - aVecA.normalize(); - aVecB.normalize(); - double fDegreeJo = atan2(aVecJ.getY(), aVecJ.getX()); - double fDegreeA2 = atan2(aVecA.getY(), aVecA.getX()) - fDegreeJo; - double fDegreeB2 = atan2(aVecB.getY(), aVecB.getX()) - fDegreeJo; - - // move to range [0..2PI[ - while(fDegreeA2 < 0.0) - { - fDegreeA2 += (2.0 * F_PI); - } + fDegreeA2 -= (2.0 * F_PI); + } - while(fDegreeA2 >= (2.0 * F_PI)) - { - fDegreeA2 -= (2.0 * F_PI); - } + // move to range [0..2PI[ + while(fDegreeB2 < 0.0) + { + fDegreeB2 += (2.0 * F_PI); + } - // move to range [0..2PI[ - while(fDegreeB2 < 0.0) - { - fDegreeB2 += (2.0 * F_PI); - } + while(fDegreeB2 >= (2.0 * F_PI)) + { + fDegreeB2 -= (2.0 * F_PI); + } - while(fDegreeB2 >= (2.0 * F_PI)) - { - fDegreeB2 -= (2.0 * F_PI); - } + sal_Bool bA2BiggerB2(::basegfx::fTools::more(fDegreeA2, fDegreeB2)); + + // build leaving vectors + aVecJ = pLeave->getLeft()->getPrevious()->getPosition() - pLeave->getLeft()->getPosition(); + aVecA = pLeave->getLeft()->getNext()->getPosition() - pLeave->getLeft()->getPosition(); + aVecB = pLeave->getRight()->getNext()->getPosition() - pLeave->getLeft()->getPosition(); + aVecJ.normalize(); + aVecA.normalize(); + aVecB.normalize(); + fDegreeJo = atan2(aVecJ.getY(), aVecJ.getX()); + double fDegreeA1 = atan2(aVecA.getY(), aVecA.getX()) - fDegreeJo; + double fDegreeB1 = atan2(aVecB.getY(), aVecB.getX()) - fDegreeJo; + + // move to range [0..2PI[ + while(fDegreeA1 < 0.0) + { + fDegreeA1 += (2.0 * F_PI); + } - sal_Bool bA2BiggerB2(::basegfx::numeric::fTools::more(fDegreeA2, fDegreeB2)); - - // build leaving vectors - aVecJ = pLeave->getLeft()->getPrevious()->getPosition() - pLeave->getLeft()->getPosition(); - aVecA = pLeave->getLeft()->getNext()->getPosition() - pLeave->getLeft()->getPosition(); - aVecB = pLeave->getRight()->getNext()->getPosition() - pLeave->getLeft()->getPosition(); - aVecJ.normalize(); - aVecA.normalize(); - aVecB.normalize(); - fDegreeJo = atan2(aVecJ.getY(), aVecJ.getX()); - double fDegreeA1 = atan2(aVecA.getY(), aVecA.getX()) - fDegreeJo; - double fDegreeB1 = atan2(aVecB.getY(), aVecB.getX()) - fDegreeJo; - - // move to range [0..2PI[ - while(fDegreeA1 < 0.0) - { - fDegreeA1 += (2.0 * F_PI); - } + while(fDegreeA1 >= (2.0 * F_PI)) + { + fDegreeA1 -= (2.0 * F_PI); + } - while(fDegreeA1 >= (2.0 * F_PI)) - { - fDegreeA1 -= (2.0 * F_PI); - } + // move to range [0..2PI[ + while(fDegreeB1 < 0) + { + fDegreeB1 += (2.0 * F_PI); + } - // move to range [0..2PI[ - while(fDegreeB1 < 0) - { - fDegreeB1 += (2.0 * F_PI); - } + while(fDegreeB1 >= (2.0 * F_PI)) + { + fDegreeB1 -= (2.0 * F_PI); + } - while(fDegreeB1 >= (2.0 * F_PI)) - { - fDegreeB1 -= (2.0 * F_PI); - } + sal_Bool bA1BiggerB1(::basegfx::fTools::more(fDegreeA1, fDegreeB1)); - sal_Bool bA1BiggerB1(::basegfx::numeric::fTools::more(fDegreeA1, fDegreeB1)); + // compare + return (bA1BiggerB1 == bA2BiggerB2); + } - // compare - return (bA1BiggerB1 == bA2BiggerB2); + void B2DPolyPolygonCutter::removeDoubleIntersections() + { + double fMaxAX, fMinAX, fMaxAY, fMinAY; + double fMaxBX, fMinBX, fMaxBY, fMinBY; + double fCut; + B2DSimpleCutVector aCuts; + B2DSimpleCutVector aTmpCuts; + B2DSimpleCutVector aNewCuts; + B2DPolygonNode* pCandA; + B2DPolygonNode* pCandB; + B2DPolygonNode* pA; + B2DPolygonNode* pB; + sal_uInt32 a; + + // create volume list for all polys for faster compares + ::basegfx::B2DRange* pVolumes = new ::basegfx::B2DRange[maPolygonList.size()]; + + for(a = 0L; a < maPolygonList.size(); a++) + { + pVolumes[a] = maPolygonList[a]->getRange(); } - void B2DPolyPolygonCutter::removeDoubleIntersections() + // register cuts (and add points for them) between pCandA and pCandB + for(a = 0L; a + 1L < maPolygonList.size(); a++) { - double fMaxAX, fMinAX, fMaxAY, fMinAY; - double fMaxBX, fMinBX, fMaxBY, fMinBY; - double fCut; - B2DSimpleCutVector aCuts; - B2DSimpleCutVector aTmpCuts; - B2DSimpleCutVector aNewCuts; - B2DPolygonNode* pCandA; - B2DPolygonNode* pCandB; - B2DPolygonNode* pA; - B2DPolygonNode* pB; - sal_uInt32 a; - - // create volume list for all polys for faster compares - ::basegfx::range::B2DRange* pVolumes = new ::basegfx::range::B2DRange[maPolygonList.size()]; - - for(a = 0L; a < maPolygonList.size(); a++) - { - pVolumes[a] = maPolygonList[a]->getRange(); - } + pCandA = maPolygonList[a]; - // register cuts (and add points for them) between pCandA and pCandB - for(a = 0L; a + 1L < maPolygonList.size(); a++) + for(sal_uInt32 b = a + 1L; b < maPolygonList.size(); b++) { - pCandA = maPolygonList[a]; - - for(sal_uInt32 b = a + 1L; b < maPolygonList.size(); b++) + if(doRangesIntersect(pVolumes[a], pVolumes[b])) { - if(doRangesIntersect(pVolumes[a], pVolumes[b])) - { - pCandB = maPolygonList[b]; - pA = pCandA; + pCandB = maPolygonList[b]; + pA = pCandA; + + // one run to find same start positions (so there is no need to + // search for existing cuts in main loop) + do { + pB = pCandB; - // one run to find same start positions (so there is no need to - // search for existing cuts in main loop) do { - pB = pCandB; + if(isSamePos(pA->getPosition(), pB->getPosition())) + { + aTmpCuts.push_back(new B2DSimpleCut(pA, pB)); + } - do { - if(isSamePos(pA->getPosition(), pB->getPosition())) - { - aTmpCuts.push_back(new B2DSimpleCut(pA, pB)); - } + // next B + pB = pB->getNext(); + } while(pB != pCandB); - // next B - pB = pB->getNext(); - } while(pB != pCandB); + // next A + pA = pA->getNext(); + } while(pA != pCandA); - // next A - pA = pA->getNext(); - } while(pA != pCandA); + // second run to find real cuts + pA = pCandA; - // second run to find real cuts - pA = pCandA; + do { + // get bounds for this edge in poly + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); + pB = pCandB; do { - // get bounds for this edge in poly - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); - pB = pCandB; + pB->calcMinMaxX(fMaxBX, fMinBX); - do { - pB->calcMinMaxX(fMaxBX, fMinBX); + if(::basegfx::fTools::more(fMaxBX, fMinAX) + && ::basegfx::fTools::more(fMaxAX, fMinBX)) + { + pB->calcMinMaxY(fMaxBY, fMinBY); - if(::basegfx::numeric::fTools::more(fMaxBX, fMinAX) - && ::basegfx::numeric::fTools::more(fMaxAX, fMinBX)) + if(::basegfx::fTools::more(fMaxBY, fMinAY) + && ::basegfx::fTools::more(fMaxAY, fMinBY)) { - pB->calcMinMaxY(fMaxBY, fMinBY); - - if(::basegfx::numeric::fTools::more(fMaxBY, fMinAY) - && ::basegfx::numeric::fTools::more(fMaxAY, fMinBY)) + if(!isSamePos(pA->getPosition(), pB->getPosition())) { - if(!isSamePos(pA->getPosition(), pB->getPosition())) - { - const ::basegfx::vector::B2DVector aVectorA(pA->getNext()->getPosition() - pA->getPosition()); - const ::basegfx::vector::B2DVector aVectorB(pB->getNext()->getPosition() - pB->getPosition()); + const ::basegfx::B2DVector aVectorA(pA->getNext()->getPosition() - pA->getPosition()); + const ::basegfx::B2DVector aVectorB(pB->getNext()->getPosition() - pB->getPosition()); - if(::basegfx::polygon::tools::findCut(pA->getPosition(), aVectorA, pB->getPosition(), aVectorB, CUTFLAG_LINE, &fCut)) + if(::basegfx::tools::findCut(pA->getPosition(), aVectorA, pB->getPosition(), aVectorB, CUTFLAG_LINE, &fCut)) + { + // crossover, two new points, use as cutpoint + ::basegfx::B2DPoint aNewPos(::basegfx::interpolate(pA->getPosition(), pA->getNext()->getPosition(), fCut)); + B2DPolygonNode* pCutLo = new B2DPolygonNode(aNewPos, pA); + B2DPolygonNode* pCutHi = new B2DPolygonNode(aNewPos, pB); + aNewCuts.push_back(new B2DSimpleCut(pCutLo, pCutHi)); + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); + } + else + { + if(::basegfx::tools::isPointOnEdge(pA->getPosition(), pB->getPosition(), aVectorB, &fCut)) { - // crossover, two new points, use as cutpoint - ::basegfx::point::B2DPoint aNewPos(::basegfx::tuple::interpolate(pA->getPosition(), pA->getNext()->getPosition(), fCut)); - B2DPolygonNode* pCutLo = new B2DPolygonNode(aNewPos, pA); - B2DPolygonNode* pCutHi = new B2DPolygonNode(aNewPos, pB); - aNewCuts.push_back(new B2DSimpleCut(pCutLo, pCutHi)); - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); + // startpoint A at edge B, one new point + // leaves or enters common section + B2DPolygonNode* pCutHi = new B2DPolygonNode(pA->getPosition(), pB); + aTmpCuts.push_back(new B2DSimpleCut(pA, pCutHi)); } - else + else if(::basegfx::tools::isPointOnEdge(pB->getPosition(), pA->getPosition(), aVectorA, &fCut)) { - if(::basegfx::polygon::tools::isPointOnEdge(pA->getPosition(), pB->getPosition(), aVectorB, &fCut)) - { - // startpoint A at edge B, one new point - // leaves or enters common section - B2DPolygonNode* pCutHi = new B2DPolygonNode(pA->getPosition(), pB); - aTmpCuts.push_back(new B2DSimpleCut(pA, pCutHi)); - } - else if(::basegfx::polygon::tools::isPointOnEdge(pB->getPosition(), pA->getPosition(), aVectorA, &fCut)) - { - // startpoint B at edge A, one new point - // leaves or enters common section - B2DPolygonNode* pCutLo = new B2DPolygonNode(pB->getPosition(), pA); - aTmpCuts.push_back(new B2DSimpleCut(pCutLo, pB)); - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); - } + // startpoint B at edge A, one new point + // leaves or enters common section + B2DPolygonNode* pCutLo = new B2DPolygonNode(pB->getPosition(), pA); + aTmpCuts.push_back(new B2DSimpleCut(pCutLo, pB)); + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); } } } } + } - // next B - pB = pB->getNext(); - } while(pB != pCandB); - - // next A - pA = pA->getNext(); - } while(pA != pCandA); + // next B + pB = pB->getNext(); + } while(pB != pCandB); - // test all temporary cuts for simple criteria - for(sal_uInt32 c(0L); c < aTmpCuts.size();) - { - B2DSimpleCut* pCand = aTmpCuts[c]; - sal_Bool bPrevSamePos(isPrevSamePos(pCand->getLeft(), pCand->getRight())); - sal_Bool bNextSamePos(isNextSamePos(pCand->getLeft(), pCand->getRight())); - sal_Bool bDelete(sal_False); - sal_Bool bIncC(sal_True); + // next A + pA = pA->getNext(); + } while(pA != pCandA); - if(bPrevSamePos && bNextSamePos) - { - // single point inside continued same direction section - bDelete = sal_True; - } - else if(!bPrevSamePos && !bNextSamePos) - { - // this is no same direction section, test for real cut - if(isCrossover(pCand->getLeft(), pCand->getRight())) - { - // real cut, move to real cutlist - aNewCuts.push_back(pCand); - aTmpCuts.erase(aTmpCuts.begin() + c); - bIncC = sal_False; - } - else - { - // no cut, just a touch in one point - bDelete = sal_True; - } - } + // test all temporary cuts for simple criteria + for(sal_uInt32 c(0L); c < aTmpCuts.size();) + { + B2DSimpleCut* pCand = aTmpCuts[c]; + sal_Bool bPrevSamePos(isPrevSamePos(pCand->getLeft(), pCand->getRight())); + sal_Bool bNextSamePos(isNextSamePos(pCand->getLeft(), pCand->getRight())); + sal_Bool bDelete(sal_False); + sal_Bool bIncC(sal_True); - // delete if wanted - if(bDelete) + if(bPrevSamePos && bNextSamePos) + { + // single point inside continued same direction section + bDelete = sal_True; + } + else if(!bPrevSamePos && !bNextSamePos) + { + // this is no same direction section, test for real cut + if(isCrossover(pCand->getLeft(), pCand->getRight())) { - delete pCand; + // real cut, move to real cutlist + aNewCuts.push_back(pCand); aTmpCuts.erase(aTmpCuts.begin() + c); bIncC = sal_False; } + else + { + // no cut, just a touch in one point + bDelete = sal_True; + } + } - // next candidate - if(bIncC) - c++; + // delete if wanted + if(bDelete) + { + delete pCand; + aTmpCuts.erase(aTmpCuts.begin() + c); + bIncC = sal_False; } - // are there entering/leaving same direction sections? - while(aTmpCuts.size()) + // next candidate + if(bIncC) + c++; + } + + // are there entering/leaving same direction sections? + while(aTmpCuts.size()) + { + // this cuts enter/leave a common same-direction section between + // polygons pCandA, pCandB. If it is a real crossover, a cutpoint + // for it is needed, else it can be ignored. + B2DSimpleCut* pCutA = aTmpCuts[0L]; + aTmpCuts.erase(aTmpCuts.begin()); + B2DPolygonNode* pActA = pCutA->getLeft(); + B2DPolygonNode* pActB = pCutA->getRight(); + sal_Bool bPrevSamePos(isPrevSamePos(pActA, pActB)); + sal_Bool bNextSamePos(isNextSamePos(pActA, pActB)); + + if(aTmpCuts.size()) { - // this cuts enter/leave a common same-direction section between - // polygons pCandA, pCandB. If it is a real crossover, a cutpoint - // for it is needed, else it can be ignored. - B2DSimpleCut* pCutA = aTmpCuts[0L]; - aTmpCuts.erase(aTmpCuts.begin()); - B2DPolygonNode* pActA = pCutA->getLeft(); - B2DPolygonNode* pActB = pCutA->getRight(); - sal_Bool bPrevSamePos(isPrevSamePos(pActA, pActB)); - sal_Bool bNextSamePos(isNextSamePos(pActA, pActB)); - - if(aTmpCuts.size()) + B2DSimpleCut* pCutB = 0L; + + if(isNextSamePos(pCutA->getLeft(), pCutA->getRight())) { - B2DSimpleCut* pCutB = 0L; + // this is a start node + B2DPolygonNode* pActA = pCutA->getLeft()->getNext(); + B2DPolygonNode* pActB = pCutA->getRight()->getNext(); - if(isNextSamePos(pCutA->getLeft(), pCutA->getRight())) + while(!pCutB && pActA != pCutA->getLeft()) { - // this is a start node - B2DPolygonNode* pActA = pCutA->getLeft()->getNext(); - B2DPolygonNode* pActB = pCutA->getRight()->getNext(); - - while(!pCutB && pActA != pCutA->getLeft()) + if(!isNextSamePos(pActA, pActB)) { - if(!isNextSamePos(pActA, pActB)) - { - pCutB = getExistingCut(aTmpCuts, pActA, pActB); - } - - pActA = pActA->getNext(); - pActB = pActB->getNext(); + pCutB = getExistingCut(aTmpCuts, pActA, pActB); } - if(pCutB) + pActA = pActA->getNext(); + pActB = pActB->getNext(); + } + + if(pCutB) + { + const B2DSimpleCutVector::iterator aFindResult = ::std::find(aTmpCuts.begin(), aTmpCuts.end(), pCutB); + aTmpCuts.erase(aFindResult); + + if(isCrossover(pCutA, pCutB)) + { + aNewCuts.push_back(pCutB); + } + else { - const B2DSimpleCutVector::iterator aFindResult = ::std::find(aTmpCuts.begin(), aTmpCuts.end(), pCutB); - aTmpCuts.erase(aFindResult); + delete pCutB; + } + } + } + else + { + // this is a end node + B2DPolygonNode* pActA = pCutA->getLeft()->getPrevious(); + B2DPolygonNode* pActB = pCutA->getRight()->getPrevious(); - if(isCrossover(pCutA, pCutB)) - { - aNewCuts.push_back(pCutB); - } - else - { - delete pCutB; - } + while(!pCutB && pActA != pCutA->getLeft()) + { + if(!isPrevSamePos(pActA, pActB)) + { + pCutB = getExistingCut(aTmpCuts, pActA, pActB); } + + pActA = pActA->getPrevious(); + pActB = pActB->getPrevious(); } - else + + if(pCutB) { - // this is a end node - B2DPolygonNode* pActA = pCutA->getLeft()->getPrevious(); - B2DPolygonNode* pActB = pCutA->getRight()->getPrevious(); + const B2DSimpleCutVector::iterator aFindResult = ::std::find(aTmpCuts.begin(), aTmpCuts.end(), pCutB); + aTmpCuts.erase(aFindResult); - while(!pCutB && pActA != pCutA->getLeft()) + if(isCrossover(pCutB, pCutA)) { - if(!isPrevSamePos(pActA, pActB)) - { - pCutB = getExistingCut(aTmpCuts, pActA, pActB); - } - - pActA = pActA->getPrevious(); - pActB = pActB->getPrevious(); + aNewCuts.push_back(pCutB); } - - if(pCutB) + else { - const B2DSimpleCutVector::iterator aFindResult = ::std::find(aTmpCuts.begin(), aTmpCuts.end(), pCutB); - aTmpCuts.erase(aFindResult); - - if(isCrossover(pCutB, pCutA)) - { - aNewCuts.push_back(pCutB); - } - else - { - delete pCutB; - } + delete pCutB; } } } - - // delete cut in EVERY case - delete pCutA; } - // copy new cuts to all cuts - aCuts.insert(aCuts.begin(), aNewCuts.begin(), aNewCuts.end()); - aNewCuts.clear(); + // delete cut in EVERY case + delete pCutA; } + + // copy new cuts to all cuts + aCuts.insert(aCuts.begin(), aNewCuts.begin(), aNewCuts.end()); + aNewCuts.clear(); } } + } - // delete volume list again - delete[] pVolumes; + // delete volume list again + delete[] pVolumes; - // are there cuts to solve? Solve them all in one run - if(aCuts.size()) - { - solveAllCuts(aCuts); - } + // are there cuts to solve? Solve them all in one run + if(aCuts.size()) + { + solveAllCuts(aCuts); } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b2dpolypolygontools.cxx b/basegfx/source/polygon/b2dpolypolygontools.cxx index 3ddb6f11a0a3..60f61b347135 100644 --- a/basegfx/source/polygon/b2dpolypolygontools.cxx +++ b/basegfx/source/polygon/b2dpolypolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygontools.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:12 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,153 +87,164 @@ namespace basegfx { - namespace polygon + namespace tools { - namespace tools + // B2DPolyPolygon tools + + void correctOrientations(::basegfx::B2DPolyPolygon& rCandidate) { - // B2DPolyPolygon tools + const sal_uInt32 nPolygonCount(rCandidate.count()); + sal_uInt32 nIndexOfOutmostPolygon(0L); + sal_Bool bIndexOfOutmostPolygonSet(sal_False); - void correctOrientations(::basegfx::polygon::B2DPolyPolygon& rCandidate) + for(sal_uInt32 a(0L); a < nPolygonCount; a++) { - const sal_uInt32 nPolygonCount(rCandidate.count()); - sal_uInt32 nIndexOfOutmostPolygon(0L); - sal_Bool bIndexOfOutmostPolygonSet(sal_False); + ::basegfx::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); - for(sal_uInt32 a(0L); a < nPolygonCount; a++) + if(aCandidate.count() > 2L) { - ::basegfx::polygon::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); - - if(aCandidate.count() > 2L) + ::basegfx::B2DVectorOrientation aOrientation = + ::basegfx::tools::getOrientation(aCandidate); + sal_Bool bDoFlip(::basegfx::ORIENTATION_POSITIVE != aOrientation); + + // init values for depth and compare point for + // inside test. Since the ordering makes only sense when assuming + // that there are no intersections, the inside test is done with + // any point of the candidate, so teke the first one. + sal_uInt32 nDepth(0L); + const ::basegfx::B2DPoint aTestPoint(aCandidate.getB2DPoint(0L)); + + // loop over other polygons and calculate depth + for(sal_uInt32 b(0L); b < nPolygonCount; b++) { - ::basegfx::vector::B2DVectorOrientation aOrientation = - ::basegfx::polygon::tools::getOrientation(aCandidate); - sal_Bool bDoFlip(::basegfx::vector::ORIENTATION_POSITIVE != aOrientation); - - // init values for depth and compare point for - // inside test. Since the ordering makes only sense when assuming - // that there are no intersections, the inside test is done with - // any point of the candidate, so teke the first one. - sal_uInt32 nDepth(0L); - const ::basegfx::point::B2DPoint aTestPoint(aCandidate.getB2DPoint(0L)); - - // loop over other polygons and calculate depth - for(sal_uInt32 b(0L); b < nPolygonCount; b++) + if(b != a) { - if(b != a) - { - ::basegfx::polygon::B2DPolygon aComparePolygon = rCandidate.getB2DPolygon(b); + ::basegfx::B2DPolygon aComparePolygon = rCandidate.getB2DPolygon(b); - if(::basegfx::polygon::tools::isInside(aComparePolygon, aTestPoint)) - { - nDepth++; - } + if(::basegfx::tools::isInside(aComparePolygon, aTestPoint)) + { + nDepth++; } } + } - // if nDepth is odd it is a hole - sal_Bool bIsHole(1L == (nDepth & 0x00000001)); + // if nDepth is odd it is a hole + sal_Bool bIsHole(1L == (nDepth & 0x00000001)); - // does polygon need to be flipped? - if((bDoFlip && !bIsHole) || (!bDoFlip && bIsHole)) - { - aCandidate.flip(); - - // write back changed polygon - rCandidate.setB2DPolygon(a, aCandidate); - } + // does polygon need to be flipped? + if((bDoFlip && !bIsHole) || (!bDoFlip && bIsHole)) + { + aCandidate.flip(); - // remember the index if it's the outmost polygon - if(!bIndexOfOutmostPolygonSet && 0L == nDepth) - { - bIndexOfOutmostPolygonSet = sal_True; - nIndexOfOutmostPolygon = a; - } + // write back changed polygon + rCandidate.setB2DPolygon(a, aCandidate); } - } - // if the outmost polygon is not the first, move it in front - if(bIndexOfOutmostPolygonSet && nIndexOfOutmostPolygon > 0L) - { - ::basegfx::polygon::B2DPolygon aOutmostPolygon = rCandidate.getB2DPolygon(nIndexOfOutmostPolygon); - rCandidate.remove(nIndexOfOutmostPolygon); - rCandidate.insert(0L, aOutmostPolygon); + // remember the index if it's the outmost polygon + if(!bIndexOfOutmostPolygonSet && 0L == nDepth) + { + bIndexOfOutmostPolygonSet = sal_True; + nIndexOfOutmostPolygon = a; + } } } - void removeIntersections(::basegfx::polygon::B2DPolyPolygon& rCandidate, - sal_Bool bForceOrientation, sal_Bool bInvertRemove) + // if the outmost polygon is not the first, move it in front + if(bIndexOfOutmostPolygonSet && nIndexOfOutmostPolygon > 0L) { - ::basegfx::polygon::B2DPolyPolygonCutter aCutter; - - aCutter.addPolyPolygon(rCandidate, bForceOrientation); - aCutter.removeSelfIntersections(); - aCutter.removeDoubleIntersections(); - aCutter.removeIncludedPolygons(!bInvertRemove); - rCandidate.clear(); - aCutter.getPolyPolygon(rCandidate); + ::basegfx::B2DPolygon aOutmostPolygon = rCandidate.getB2DPolygon(nIndexOfOutmostPolygon); + rCandidate.remove(nIndexOfOutmostPolygon); + rCandidate.insert(0L, aOutmostPolygon); } + } + + void removeIntersections(::basegfx::B2DPolyPolygon& rCandidate, + sal_Bool bForceOrientation, sal_Bool bInvertRemove) + { + ::basegfx::B2DPolyPolygonCutter aCutter; + + aCutter.addPolyPolygon(rCandidate, bForceOrientation); + aCutter.removeSelfIntersections(); + aCutter.removeDoubleIntersections(); + aCutter.removeIncludedPolygons(!bInvertRemove); + rCandidate.clear(); + aCutter.getPolyPolygon(rCandidate); + } - ::basegfx::polygon::B2DPolyPolygon adaptiveSubdivideByDistance(const ::basegfx::polygon::B2DPolyPolygon& rCandidate, double fDistanceBound) + ::basegfx::B2DPolyPolygon adaptiveSubdivideByDistance(const ::basegfx::B2DPolyPolygon& rCandidate, double fDistanceBound) + { + ::basegfx::B2DPolyPolygon aRetval(rCandidate); + + if(aRetval.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolyPolygon aRetval(rCandidate); + const sal_uInt32 nPolygonCount(aRetval.count()); - if(aRetval.areControlPointsUsed()) + for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++) { - const sal_uInt32 nPolygonCount(aRetval.count()); + ::basegfx::B2DPolygon aCandidate = aRetval.getB2DPolygon(a); - for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++) + if(aCandidate.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolygon aCandidate = aRetval.getB2DPolygon(a); - - if(aCandidate.areControlPointsUsed()) - { - aCandidate = ::basegfx::polygon::tools::adaptiveSubdivideByDistance(aCandidate, fDistanceBound); - aRetval.setB2DPolygon(a, aCandidate); - } + aCandidate = ::basegfx::tools::adaptiveSubdivideByDistance(aCandidate, fDistanceBound); + aRetval.setB2DPolygon(a, aCandidate); } } - - return aRetval; } - ::basegfx::polygon::B2DPolyPolygon adaptiveSubdivideByAngle(const ::basegfx::polygon::B2DPolyPolygon& rCandidate, double fAngleBound) + return aRetval; + } + + ::basegfx::B2DPolyPolygon adaptiveSubdivideByAngle(const ::basegfx::B2DPolyPolygon& rCandidate, double fAngleBound) + { + ::basegfx::B2DPolyPolygon aRetval(rCandidate); + + if(aRetval.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolyPolygon aRetval(rCandidate); + const sal_uInt32 nPolygonCount(aRetval.count()); - if(aRetval.areControlPointsUsed()) + for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++) { - const sal_uInt32 nPolygonCount(aRetval.count()); + ::basegfx::B2DPolygon aCandidate = aRetval.getB2DPolygon(a); - for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++) + if(aCandidate.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolygon aCandidate = aRetval.getB2DPolygon(a); - - if(aCandidate.areControlPointsUsed()) - { - aCandidate = ::basegfx::polygon::tools::adaptiveSubdivideByAngle(aCandidate, fAngleBound); - aRetval.setB2DPolygon(a, aCandidate); - } + aCandidate = ::basegfx::tools::adaptiveSubdivideByAngle(aCandidate, fAngleBound); + aRetval.setB2DPolygon(a, aCandidate); } } - - return aRetval; } - ::basegfx::range::B2DRange getRange(const ::basegfx::polygon::B2DPolyPolygon& rCandidate) + return aRetval; + } + + ::basegfx::B2DRange getRange(const ::basegfx::B2DPolyPolygon& rCandidate) + { + ::basegfx::B2DRange aRetval; + const sal_uInt32 nPolygonCount(rCandidate.count()); + + for(sal_uInt32 a(0L); a < nPolygonCount; a++) { - ::basegfx::range::B2DRange aRetval; - const sal_uInt32 nPolygonCount(rCandidate.count()); + ::basegfx::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); + aRetval.expand(::basegfx::tools::getRange(aCandidate)); + } - for(sal_uInt32 a(0L); a < nPolygonCount; a++) - { - ::basegfx::polygon::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); - aRetval.expand(::basegfx::polygon::tools::getRange(aCandidate)); - } + return aRetval; + } + + ::basegfx::B2DPolyPolygon applyLineDashing(const ::basegfx::B2DPolyPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen) + { + ::basegfx::B2DPolyPolygon aRetval; + const sal_uInt32 nPolygonCount(rCandidate.count()); - return aRetval; + for(sal_uInt32 a(0L); a < nPolygonCount; a++) + { + ::basegfx::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); + aRetval.append(applyLineDashing(aCandidate, raDashDotArray, fFullDashDotLen)); } - } // end of namespace tools - } // end of namespace polygon + + return aRetval; + } + } // end of namespace tools } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b3dpolygon.cxx b/basegfx/source/polygon/b3dpolygon.cxx index df2672d6bbf4..0d488c04bf2c 100644 --- a/basegfx/source/polygon/b3dpolygon.cxx +++ b/basegfx/source/polygon/b3dpolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolygon.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:31:36 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -82,17 +82,17 @@ class CoordinateData3D { - ::basegfx::point::B3DPoint maPoint; + ::basegfx::B3DPoint maPoint; public: CoordinateData3D() {} - CoordinateData3D(const ::basegfx::point::B3DPoint& rData) : maPoint(rData) {} + CoordinateData3D(const ::basegfx::B3DPoint& rData) : maPoint(rData) {} ~CoordinateData3D() {} - const ::basegfx::point::B3DPoint& getCoordinate() const { return maPoint; } - void setCoordinate(const ::basegfx::point::B3DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } + const ::basegfx::B3DPoint& getCoordinate() const { return maPoint; } + void setCoordinate(const ::basegfx::B3DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } sal_Bool operator==(const CoordinateData3D& rData ) const { return (maPoint == rData.getCoordinate()); } - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) { maPoint *= rMatrix; } + void transform(const ::basegfx::B3DHomMatrix& rMatrix) { maPoint *= rMatrix; } }; ////////////////////////////////////////////////////////////////////////////// @@ -133,12 +133,12 @@ public: return (maVector == rCandidate.maVector); } - const ::basegfx::point::B3DPoint& getCoordinate(sal_uInt32 nIndex) const + const ::basegfx::B3DPoint& getCoordinate(sal_uInt32 nIndex) const { return maVector[nIndex].getCoordinate(); } - void setCoordinate(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rValue) + void setCoordinate(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rValue) { maVector[nIndex].setCoordinate(rValue); } @@ -229,7 +229,7 @@ public: } } - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + void transform(const ::basegfx::B3DHomMatrix& rMatrix) { CoordinateData3DVector::iterator aStart(maVector.begin()); CoordinateData3DVector::iterator aEnd(maVector.end()); @@ -333,17 +333,17 @@ public: return sal_False; } - const ::basegfx::point::B3DPoint& getPoint(sal_uInt32 nIndex) const + const ::basegfx::B3DPoint& getPoint(sal_uInt32 nIndex) const { return maPoints.getCoordinate(nIndex); } - void setPoint(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rValue) + void setPoint(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rValue) { maPoints.setCoordinate(nIndex, rValue); } - void insert(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rPoint, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount) { if(nCount) { @@ -417,7 +417,7 @@ public: maPoints.removeDoublePointsWholeTrack(); } - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + void transform(const ::basegfx::B3DHomMatrix& rMatrix) { maPoints.transform(rMatrix); } @@ -427,253 +427,250 @@ public: namespace basegfx { - namespace polygon - { - // init static default Polygon - static ImplB3DPolygon maStaticDefaultPolygon; + // init static default Polygon + static ImplB3DPolygon maStaticDefaultPolygon; - void B3DPolygon::implForceUniqueCopy() + void B3DPolygon::implForceUniqueCopy() + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - mpPolygon = new ImplB3DPolygon(*mpPolygon); - } + mpPolygon->decRefCount(); + mpPolygon = new ImplB3DPolygon(*mpPolygon); } + } + + B3DPolygon::B3DPolygon() + : mpPolygon(&maStaticDefaultPolygon) + { + mpPolygon->incRefCount(); + } - B3DPolygon::B3DPolygon() - : mpPolygon(&maStaticDefaultPolygon) + B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon) + : mpPolygon(rPolygon.mpPolygon) + { + mpPolygon->incRefCount(); + } + + B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) + : mpPolygon(new ImplB3DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + { + OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B3DPolygon constructor outside range (!)"); + } + + B3DPolygon::~B3DPolygon() + { + if(mpPolygon->getRefCount()) { - mpPolygon->incRefCount(); + mpPolygon->decRefCount(); } - - B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon) - : mpPolygon(rPolygon.mpPolygon) + else { - mpPolygon->incRefCount(); + delete mpPolygon; } + } - B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) - : mpPolygon(new ImplB3DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + B3DPolygon& B3DPolygon::operator=(const B3DPolygon& rPolygon) + { + if(mpPolygon->getRefCount()) { - OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B3DPolygon constructor outside range (!)"); + mpPolygon->decRefCount(); } - - B3DPolygon::~B3DPolygon() + else { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - } - else - { - delete mpPolygon; - } + delete mpPolygon; } - B3DPolygon& B3DPolygon::operator=(const B3DPolygon& rPolygon) - { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - } - else - { - delete mpPolygon; - } + mpPolygon = rPolygon.mpPolygon; + mpPolygon->incRefCount(); - mpPolygon = rPolygon.mpPolygon; - mpPolygon->incRefCount(); + return *this; + } - return *this; + sal_Bool B3DPolygon::operator==(const B3DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) + { + return sal_True; } - sal_Bool B3DPolygon::operator==(const B3DPolygon& rPolygon) const - { - if(mpPolygon == rPolygon.mpPolygon) - { - return sal_True; - } + return mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } - return mpPolygon->isEqual(*(rPolygon.mpPolygon)); + sal_Bool B3DPolygon::operator!=(const B3DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) + { + return sal_False; } - sal_Bool B3DPolygon::operator!=(const B3DPolygon& rPolygon) const - { - if(mpPolygon == rPolygon.mpPolygon) - { - return sal_False; - } + return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } - return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); - } + sal_uInt32 B3DPolygon::count() const + { + return mpPolygon->count(); + } - sal_uInt32 B3DPolygon::count() const - { - return mpPolygon->count(); - } + ::basegfx::B3DPoint B3DPolygon::getB3DPoint(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)"); - ::basegfx::point::B3DPoint B3DPolygon::getB3DPoint(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)"); + return mpPolygon->getPoint(nIndex); + } - return mpPolygon->getPoint(nIndex); - } + void B3DPolygon::setB3DPoint(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)"); - void B3DPolygon::setB3DPoint(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rValue) + if(mpPolygon->getPoint(nIndex) != rValue) { - OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)"); - - if(mpPolygon->getPoint(nIndex) != rValue) - { - implForceUniqueCopy(); - mpPolygon->setPoint(nIndex, rValue); - } + implForceUniqueCopy(); + mpPolygon->setPoint(nIndex, rValue); } + } - void B3DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rPoint, sal_uInt32 nCount) - { - OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)"); + void B3DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)"); - if(nCount) - { - implForceUniqueCopy(); - mpPolygon->insert(nIndex, rPoint, nCount); - } + if(nCount) + { + implForceUniqueCopy(); + mpPolygon->insert(nIndex, rPoint, nCount); } + } - void B3DPolygon::append(const ::basegfx::point::B3DPoint& rPoint, sal_uInt32 nCount) + void B3DPolygon::append(const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount) + { + if(nCount) { - if(nCount) - { - implForceUniqueCopy(); - mpPolygon->insert(mpPolygon->count(), rPoint, nCount); - } + implForceUniqueCopy(); + mpPolygon->insert(mpPolygon->count(), rPoint, nCount); } + } + + void B3DPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)"); - void B3DPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) + if(rPoly.count()) { - OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)"); + implForceUniqueCopy(); - if(rPoly.count()) + if(!nCount) { - implForceUniqueCopy(); - - if(!nCount) - { - nCount = rPoly.count(); - } - - if(0L == nIndex2 && nCount == rPoly.count()) - { - mpPolygon->insert(nIndex, *rPoly.mpPolygon); - } - else - { - OSL_ENSURE(nIndex2 + nCount > rPoly.mpPolygon->count(), "B3DPolygon Insert outside range (!)"); - ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); - mpPolygon->insert(nIndex, aTempPoly); - } + nCount = rPoly.count(); } - } - void B3DPolygon::append(const B3DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) - { - if(rPoly.count()) + if(0L == nIndex2 && nCount == rPoly.count()) { - implForceUniqueCopy(); - - if(!nCount) - { - nCount = rPoly.count(); - } - - if(0L == nIndex && nCount == rPoly.count()) - { - mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); - } - else - { - OSL_ENSURE(nIndex + nCount > rPoly.mpPolygon->count(), "B3DPolygon Append outside range (!)"); - ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); - mpPolygon->insert(mpPolygon->count(), aTempPoly); - } + mpPolygon->insert(nIndex, *rPoly.mpPolygon); + } + else + { + OSL_ENSURE(nIndex2 + nCount > rPoly.mpPolygon->count(), "B3DPolygon Insert outside range (!)"); + ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); + mpPolygon->insert(nIndex, aTempPoly); } } + } - void B3DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + void B3DPolygon::append(const B3DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(rPoly.count()) { - OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B3DPolygon Remove outside range (!)"); + implForceUniqueCopy(); - if(nCount) + if(!nCount) { - implForceUniqueCopy(); - mpPolygon->remove(nIndex, nCount); + nCount = rPoly.count(); } - } - void B3DPolygon::clear() - { - if(mpPolygon->getRefCount()) + if(0L == nIndex && nCount == rPoly.count()) { - mpPolygon->decRefCount(); + mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); } else { - delete mpPolygon; + OSL_ENSURE(nIndex + nCount > rPoly.mpPolygon->count(), "B3DPolygon Append outside range (!)"); + ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); + mpPolygon->insert(mpPolygon->count(), aTempPoly); } - - mpPolygon = &maStaticDefaultPolygon; - mpPolygon->incRefCount(); } + } - sal_Bool B3DPolygon::isClosed() const + void B3DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B3DPolygon Remove outside range (!)"); + + if(nCount) { - return mpPolygon->isClosed(); + implForceUniqueCopy(); + mpPolygon->remove(nIndex, nCount); } + } - void B3DPolygon::setClosed(sal_Bool bNew) + void B3DPolygon::clear() + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->isClosed() != bNew) - { - implForceUniqueCopy(); - mpPolygon->setClosed(bNew); - } + mpPolygon->decRefCount(); } + else + { + delete mpPolygon; + } + + mpPolygon = &maStaticDefaultPolygon; + mpPolygon->incRefCount(); + } + + sal_Bool B3DPolygon::isClosed() const + { + return mpPolygon->isClosed(); + } - void B3DPolygon::flip() + void B3DPolygon::setClosed(sal_Bool bNew) + { + if(mpPolygon->isClosed() != bNew) { - if(mpPolygon->count() > 1) - { - implForceUniqueCopy(); - mpPolygon->flip(); - } + implForceUniqueCopy(); + mpPolygon->setClosed(bNew); } + } - sal_Bool B3DPolygon::hasDoublePoints() const + void B3DPolygon::flip() + { + if(mpPolygon->count() > 1) { - return mpPolygon->hasDoublePoints(); + implForceUniqueCopy(); + mpPolygon->flip(); } + } - void B3DPolygon::removeDoublePoints() + sal_Bool B3DPolygon::hasDoublePoints() const + { + return mpPolygon->hasDoublePoints(); + } + + void B3DPolygon::removeDoublePoints() + { + if(mpPolygon->count() > 1) { - if(mpPolygon->count() > 1) - { - implForceUniqueCopy(); - mpPolygon->removeDoublePointsAtBeginEnd(); - mpPolygon->removeDoublePointsWholeTrack(); - } + implForceUniqueCopy(); + mpPolygon->removeDoublePointsAtBeginEnd(); + mpPolygon->removeDoublePointsWholeTrack(); } + } - void B3DPolygon::transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + void B3DPolygon::transform(const ::basegfx::B3DHomMatrix& rMatrix) + { + if(mpPolygon->count()) { - if(mpPolygon->count()) - { - implForceUniqueCopy(); - mpPolygon->transform(rMatrix); - } + implForceUniqueCopy(); + mpPolygon->transform(rMatrix); } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b3dpolygontools.cxx b/basegfx/source/polygon/b3dpolygontools.cxx index 473aa6baef45..9784ae5930a9 100644 --- a/basegfx/source/polygon/b3dpolygontools.cxx +++ b/basegfx/source/polygon/b3dpolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolygontools.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:31:39 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -83,275 +83,344 @@ namespace basegfx { - namespace polygon + namespace tools { - namespace tools + // B3DPolygon tools + void checkClosed(B3DPolygon& rCandidate) { - // B3DPolygon tools - void checkClosed(polygon::B3DPolygon& rCandidate) + while(rCandidate.count() > 1L + && rCandidate.getB3DPoint(0L).equal(rCandidate.getB3DPoint(rCandidate.count() - 1L))) { - while(rCandidate.count() > 1L - && rCandidate.getB3DPoint(0L).equal(rCandidate.getB3DPoint(rCandidate.count() - 1L))) - { - rCandidate.setClosed(sal_True); - rCandidate.remove(rCandidate.count() - 1L); - } + rCandidate.setClosed(sal_True); + rCandidate.remove(rCandidate.count() - 1L); } + } + + // Get successor and predecessor indices. Returning the same index means there + // is none. Same for successor. + sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - // Get successor and predecessor indices. Returning the same index means there - // is none. Same for successor. - sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate) + if(nIndex) + { + return nIndex - 1L; + } + else if(rCandidate.count()) + { + return rCandidate.count() - 1L; + } + else { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + return nIndex; + } + } - if(nIndex) - { - return nIndex - 1L; - } - else if(rCandidate.count()) - { - return rCandidate.count() - 1L; - } - else - { - return nIndex; - } + sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + + if(nIndex + 1L < rCandidate.count()) + { + return nIndex + 1L; } + else + { + return 0L; + } + } + + sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate) + { + sal_uInt32 nNewIndex(nIndex); + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate) + if(rCandidate.count() > 1) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + nNewIndex = getIndexOfPredecessor(nIndex, rCandidate); + ::basegfx::B3DPoint aPoint(rCandidate.getB3DPoint(nIndex)); - if(nIndex + 1L < rCandidate.count()) - { - return nIndex + 1L; - } - else + while(nNewIndex != nIndex + && aPoint.equal(rCandidate.getB3DPoint(nNewIndex))) { - return 0L; + nNewIndex = getIndexOfPredecessor(nNewIndex, rCandidate); } } - sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate) + return nNewIndex; + } + + sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate) + { + sal_uInt32 nNewIndex(nIndex); + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + + if(rCandidate.count() > 1) { - sal_uInt32 nNewIndex(nIndex); - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + nNewIndex = getIndexOfSuccessor(nIndex, rCandidate); + ::basegfx::B3DPoint aPoint(rCandidate.getB3DPoint(nIndex)); - if(rCandidate.count() > 1) + while(nNewIndex != nIndex + && aPoint.equal(rCandidate.getB3DPoint(nNewIndex))) { - nNewIndex = getIndexOfPredecessor(nIndex, rCandidate); - ::basegfx::point::B3DPoint aPoint(rCandidate.getB3DPoint(nIndex)); - - while(nNewIndex != nIndex - && aPoint.equal(rCandidate.getB3DPoint(nNewIndex))) - { - nNewIndex = getIndexOfPredecessor(nNewIndex, rCandidate); - } + nNewIndex = getIndexOfSuccessor(nNewIndex, rCandidate); } - - return nNewIndex; } - sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate) - { - sal_uInt32 nNewIndex(nIndex); - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + return nNewIndex; + } - if(rCandidate.count() > 1) - { - nNewIndex = getIndexOfSuccessor(nIndex, rCandidate); - ::basegfx::point::B3DPoint aPoint(rCandidate.getB3DPoint(nIndex)); - - while(nNewIndex != nIndex - && aPoint.equal(rCandidate.getB3DPoint(nNewIndex))) - { - nNewIndex = getIndexOfSuccessor(nNewIndex, rCandidate); - } - } + ::basegfx::B3DRange getRange(const ::basegfx::B3DPolygon& rCandidate) + { + ::basegfx::B3DRange aRetval; + const sal_uInt32 nPointCount(rCandidate.count()); - return nNewIndex; + for(sal_uInt32 a(0L); a < nPointCount; a++) + { + const ::basegfx::B3DPoint aTestPoint(rCandidate.getB3DPoint(a)); + aRetval.expand(aTestPoint); } - ::basegfx::range::B3DRange getRange(const ::basegfx::polygon::B3DPolygon& rCandidate) - { - ::basegfx::range::B3DRange aRetval; - const sal_uInt32 nPointCount(rCandidate.count()); + return aRetval; + } + + double getEdgeLength(const ::basegfx::B3DPolygon& rCandidate, sal_uInt32 nIndex) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(nIndex < nPointCount) + { + if(rCandidate.isClosed() || nIndex + 1 != nPointCount) { - const ::basegfx::point::B3DPoint aTestPoint(rCandidate.getB3DPoint(a)); - aRetval.expand(aTestPoint); + const sal_uInt32 nNextIndex(nIndex + 1 == nPointCount ? 0L : nIndex + 1L); + const ::basegfx::B3DPoint aCurrentPoint(rCandidate.getB3DPoint(nIndex)); + const ::basegfx::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); + const ::basegfx::B3DVector aVector(aNextPoint - aCurrentPoint); + fRetval = aVector.getLength(); } + } - return aRetval; + return fRetval; + } + + double getLength(const ::basegfx::B3DPolygon& rCandidate) + { + // This method may also be implemented using a loop over getEdgeLength, but + // since this would cause a lot of sqare roots to be solved it is much better + // to sum up the quadrats first and then use a singe suare root (if necessary) + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); + const sal_uInt32 nLoopCount(rCandidate.isClosed() ? nPointCount : nPointCount - 1L); + + for(sal_uInt32 a(0L); a < nLoopCount; a++) + { + const sal_uInt32 nNextIndex(a + 1 == nPointCount ? 0L : a + 1L); + const ::basegfx::B3DPoint aCurrentPoint(rCandidate.getB3DPoint(a)); + const ::basegfx::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); + const ::basegfx::B3DVector aVector(aNextPoint - aCurrentPoint); + fRetval += aVector.scalar(aVector); } - double getEdgeLength(const ::basegfx::polygon::B3DPolygon& rCandidate, sal_uInt32 nIndex) + if(!::basegfx::fTools::equalZero(fRetval)) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); + const double fOne(1.0); - if(nIndex < nPointCount) + if(!::basegfx::fTools::equal(fOne, fRetval)) { - if(rCandidate.isClosed() || nIndex + 1 != nPointCount) - { - const sal_uInt32 nNextIndex(nIndex + 1 == nPointCount ? 0L : nIndex + 1L); - const ::basegfx::point::B3DPoint aCurrentPoint(rCandidate.getB3DPoint(nIndex)); - const ::basegfx::point::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); - const ::basegfx::vector::B3DVector aVector(aNextPoint - aCurrentPoint); - fRetval = aVector.getLength(); - } + fRetval = sqrt(fRetval); } - - return fRetval; } - double getLength(const ::basegfx::polygon::B3DPolygon& rCandidate) + return fRetval; + } + + ::basegfx::B3DPoint getPositionAbsolute(const ::basegfx::B3DPolygon& rCandidate, double fDistance, double fLength) + { + ::basegfx::B3DPoint aRetval; + const sal_uInt32 nPointCount(rCandidate.count()); + + if(nPointCount > 1L) { - // This method may also be implemented using a loop over getEdgeLength, but - // since this would cause a lot of sqare roots to be solved it is much better - // to sum up the quadrats first and then use a singe suare root (if necessary) - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); - const sal_uInt32 nLoopCount(rCandidate.isClosed() ? nPointCount : nPointCount - 1L); - - for(sal_uInt32 a(0L); a < nLoopCount; a++) + sal_uInt32 nIndex(0L); + sal_Bool bIndexDone(sal_False); + const double fZero(0.0); + double fEdgeLength(fZero); + + // get length if not given + if(::basegfx::fTools::equalZero(fLength)) { - const sal_uInt32 nNextIndex(a + 1 == nPointCount ? 0L : a + 1L); - const ::basegfx::point::B3DPoint aCurrentPoint(rCandidate.getB3DPoint(a)); - const ::basegfx::point::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); - const ::basegfx::vector::B3DVector aVector(aNextPoint - aCurrentPoint); - fRetval += aVector.scalar(aVector); + fLength = getLength(rCandidate); } - if(!::basegfx::numeric::fTools::equalZero(fRetval)) + // handle fDistance < 0.0 + if(::basegfx::fTools::less(fDistance, fZero)) { - const double fOne(1.0); - - if(!::basegfx::numeric::fTools::equal(fOne, fRetval)) + if(rCandidate.isClosed()) + { + // if fDistance < 0.0 increment with multiple of fLength + sal_uInt32 nCount(sal_uInt32(-fDistance / fLength)); + fDistance += double(nCount + 1L) * fLength; + } + else { - fRetval = sqrt(fRetval); + // crop to polygon start + fDistance = fZero; + bIndexDone = sal_True; } } - return fRetval; - } - - ::basegfx::point::B3DPoint getPositionAbsolute(const ::basegfx::polygon::B3DPolygon& rCandidate, double fDistance, double fLength) - { - ::basegfx::point::B3DPoint aRetval; - const sal_uInt32 nPointCount(rCandidate.count()); - - if(nPointCount > 1L) + // handle fDistance >= fLength + if(::basegfx::fTools::moreOrEqual(fDistance, fLength)) { - sal_uInt32 nIndex(0L); - sal_Bool bIndexDone(sal_False); - const double fZero(0.0); - double fEdgeLength(fZero); - - // get length if not given - if(::basegfx::numeric::fTools::equalZero(fLength)) + if(rCandidate.isClosed()) { - fLength = getLength(rCandidate); + // if fDistance >= fLength decrement with multiple of fLength + sal_uInt32 nCount(sal_uInt32(fDistance / fLength)); + fDistance -= (double)(nCount) * fLength; } - - // handle fDistance < 0.0 - if(::basegfx::numeric::fTools::less(fDistance, fZero)) + else { - if(rCandidate.isClosed()) - { - // if fDistance < 0.0 increment with multiple of fLength - sal_uInt32 nCount(sal_uInt32(-fDistance / fLength)); - fDistance += double(nCount + 1L) * fLength; - } - else - { - // crop to polygon start - fDistance = fZero; - bIndexDone = sal_True; - } + // crop to polygon end + fDistance = fZero; + nIndex = nPointCount - 1L; + bIndexDone = sal_True; } + } - // handle fDistance >= fLength - if(::basegfx::numeric::fTools::moreOrEqual(fDistance, fLength)) + // look for correct index. fDistance is now [0.0 .. fLength[ + if(!bIndexDone) + { + do { - if(rCandidate.isClosed()) + // get length of next edge + fEdgeLength = getEdgeLength(rCandidate, nIndex); + + if(::basegfx::fTools::moreOrEqual(fDistance, fEdgeLength)) { - // if fDistance >= fLength decrement with multiple of fLength - sal_uInt32 nCount(sal_uInt32(fDistance / fLength)); - fDistance -= (double)(nCount) * fLength; + // go to next edge + fDistance -= fEdgeLength; + nIndex++; } else { - // crop to polygon end - fDistance = fZero; - nIndex = nPointCount - 1L; + // it's on this edge, stop bIndexDone = sal_True; } + } while (!bIndexDone); + } + + // get the point using nIndex + aRetval = rCandidate.getB3DPoint(nIndex); + + // if fDistance != 0.0, move that length on the edge. The edge + // length is in fEdgeLength. + if(!::basegfx::fTools::equalZero(fDistance)) + { + sal_uInt32 nNextIndex(getIndexOfSuccessor(nIndex, rCandidate)); + const ::basegfx::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); + double fRelative(fZero); + + if(!::basegfx::fTools::equalZero(fEdgeLength)) + { + fRelative = fDistance / fEdgeLength; } - // look for correct index. fDistance is now [0.0 .. fLength[ - if(!bIndexDone) + // add calculated average value to the return value + aRetval += ::basegfx::average(aRetval, aNextPoint, fRelative); + } + } + + return aRetval; + } + + ::basegfx::B3DPoint getPositionRelative(const ::basegfx::B3DPolygon& rCandidate, double fDistance, double fLength) + { + // get length if not given + if(::basegfx::fTools::equalZero(fLength)) + { + fLength = getLength(rCandidate); + } + + // multiply fDistance with real length to get absolute position and + // use getPositionAbsolute + return getPositionAbsolute(rCandidate, fDistance * fLength, fLength); + } + + ::basegfx::B3DPolyPolygon applyLineDashing(const ::basegfx::B3DPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen) + { + ::basegfx::B3DPolyPolygon aRetval; + + if(rCandidate.count() && fFullDashDotLen > 0.0) + { + const sal_uInt32 nCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); + sal_uInt32 nDashDotIndex(0L); + double fDashDotLength(raDashDotArray[nDashDotIndex]); + + for(sal_uInt32 a(0L); a < nCount; a++) + { + const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); + const ::basegfx::B3DPoint aStart(rCandidate.getB3DPoint(a)); + const ::basegfx::B3DPoint aEnd(rCandidate.getB3DPoint(nNextIndex)); + ::basegfx::B3DVector aVector(aEnd - aStart); + double fLength(aVector.getLength()); + double fPosOnVector(0.0); + aVector.normalize(); + + while(fLength >= fDashDotLength) { - do + // handle [fPosOnVector .. fPosOnVector+fDashDotLength] + if(nDashDotIndex % 2) { - // get length of next edge - fEdgeLength = getEdgeLength(rCandidate, nIndex); + ::basegfx::B3DPolygon aResult; - if(::basegfx::numeric::fTools::moreOrEqual(fDistance, fEdgeLength)) + // add start point + if(fPosOnVector == 0.0) { - // go to next edge - fDistance -= fEdgeLength; - nIndex++; + aResult.append(aStart); } else { - // it's on this edge, stop - bIndexDone = sal_True; + aResult.append(aStart + (aVector * fPosOnVector)); } - } while (!bIndexDone); - } - // get the point using nIndex - aRetval = rCandidate.getB3DPoint(nIndex); + // add end point + aResult.append(aStart + (aVector * (fPosOnVector + fDashDotLength))); - // if fDistance != 0.0, move that length on the edge. The edge - // length is in fEdgeLength. - if(!::basegfx::numeric::fTools::equalZero(fDistance)) - { - sal_uInt32 nNextIndex(getIndexOfSuccessor(nIndex, rCandidate)); - const ::basegfx::point::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); - double fRelative(fZero); - - if(!::basegfx::numeric::fTools::equalZero(fEdgeLength)) - { - fRelative = fDistance / fEdgeLength; + // add line to PolyPolygon + aRetval.append(aResult); } - // add calculated average value to the return value - aRetval += ::basegfx::tuple::average(aRetval, aNextPoint, fRelative); + // consume from fDashDotLength + fPosOnVector += fDashDotLength; + fLength -= fDashDotLength; + nDashDotIndex = (nDashDotIndex + 1L) % raDashDotArray.size(); + fDashDotLength = raDashDotArray[nDashDotIndex]; } - } - return aRetval; - } + // handle [fPosOnVector .. fPosOnVector+fLength (bzw. end)] + if((fLength > 0.0) && (nDashDotIndex % 2)) + { + ::basegfx::B3DPolygon aResult; - ::basegfx::point::B3DPoint getPositionRelative(const ::basegfx::polygon::B3DPolygon& rCandidate, double fDistance, double fLength) - { - // get length if not given - if(::basegfx::numeric::fTools::equalZero(fLength)) - { - fLength = getLength(rCandidate); - } + // add start and end point + const ::basegfx::B3DPoint aPosA(aStart + (aVector * fPosOnVector)); + aResult.append(aPosA); + aResult.append(aEnd); - // multiply fDistance with real length to get absolute position and - // use getPositionAbsolute - return getPositionAbsolute(rCandidate, fDistance * fLength, fLength); + // add line to PolyPolygon + aRetval.append(aResult); + } + + // consume from fDashDotLength + fDashDotLength -= fLength; + } } - } // end of namespace tools - } // end of namespace polygon + return aRetval; + } + } // end of namespace tools } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b3dpolypolygon.cxx b/basegfx/source/polygon/b3dpolypolygon.cxx index 28e43316f369..bb78552b24e5 100644 --- a/basegfx/source/polygon/b3dpolypolygon.cxx +++ b/basegfx/source/polygon/b3dpolypolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolypolygon.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:31:37 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -77,7 +77,7 @@ class ImplB3DPolyPolygon { - typedef ::std::vector< ::basegfx::polygon::B3DPolygon > PolygonVector; + typedef ::std::vector< ::basegfx::B3DPolygon > PolygonVector; PolygonVector maPolygons; sal_uInt32 mnRefCount; @@ -123,17 +123,17 @@ public: return sal_True; } - const ::basegfx::polygon::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const + const ::basegfx::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const { return maPolygons[nIndex]; } - void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rPolygon) + void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon) { maPolygons[nIndex] = rPolygon; } - void insert(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rPolygon, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon, sal_uInt32 nCount) { if(nCount) { @@ -144,7 +144,7 @@ public: } } - void insert(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolyPolygon& rPolyPolygon) + void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon) { const sal_uInt32 nCount = rPolyPolygon.count(); @@ -205,7 +205,7 @@ public: } } - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + void transform(const ::basegfx::B3DHomMatrix& rMatrix) { for(sal_uInt32 a(0L); a < maPolygons.size(); a++) { @@ -218,232 +218,229 @@ public: namespace basegfx { - namespace polygon - { - // init static default Polygon - static ImplB3DPolyPolygon maStaticDefaultPolyPolygon; + // init static default Polygon + static ImplB3DPolyPolygon maStaticDefaultPolyPolygon; - void B3DPolyPolygon::implForceUniqueCopy() + void B3DPolyPolygon::implForceUniqueCopy() + { + if(mpPolyPolygon->getRefCount()) { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - mpPolyPolygon = new ImplB3DPolyPolygon(*mpPolyPolygon); - } + mpPolyPolygon->decRefCount(); + mpPolyPolygon = new ImplB3DPolyPolygon(*mpPolyPolygon); } + } + + B3DPolyPolygon::B3DPolyPolygon() + : mpPolyPolygon(&maStaticDefaultPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } - B3DPolyPolygon::B3DPolyPolygon() - : mpPolyPolygon(&maStaticDefaultPolyPolygon) + B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon) + : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } + + B3DPolyPolygon::~B3DPolyPolygon() + { + if(mpPolyPolygon->getRefCount()) { - mpPolyPolygon->incRefCount(); + mpPolyPolygon->decRefCount(); } - - B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon) - : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + else { - mpPolyPolygon->incRefCount(); + delete mpPolyPolygon; } + } - B3DPolyPolygon::~B3DPolyPolygon() + B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon& rPolyPolygon) + { + if(mpPolyPolygon->getRefCount()) { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } + mpPolyPolygon->decRefCount(); } - - B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon& rPolyPolygon) + else { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } - - mpPolyPolygon = rPolyPolygon.mpPolyPolygon; - mpPolyPolygon->incRefCount(); - - return *this; + delete mpPolyPolygon; } - sal_Bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const - { - if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) - { - return sal_True; - } + mpPolyPolygon = rPolyPolygon.mpPolyPolygon; + mpPolyPolygon->incRefCount(); - return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); - } + return *this; + } - sal_Bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const + sal_Bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) { - if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) - { - return sal_False; - } - - return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + return sal_True; } - sal_uInt32 B3DPolyPolygon::count() const + return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } + + sal_Bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) { - return mpPolyPolygon->count(); + return sal_False; } - B3DPolygon B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)"); + return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } - return mpPolyPolygon->getB3DPolygon(nIndex); - } + sal_uInt32 B3DPolyPolygon::count() const + { + return mpPolyPolygon->count(); + } - void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon) - { - OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)"); + B3DPolygon B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)"); - if(mpPolyPolygon->getB3DPolygon(nIndex) != rPolygon) - { - implForceUniqueCopy(); - mpPolyPolygon->setB3DPolygon(nIndex, rPolygon); - } - } + return mpPolyPolygon->getB3DPolygon(nIndex); + } - void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPolygon, sal_uInt32 nCount) - { - OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)"); + void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon) + { + OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)"); - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(nIndex, rPolygon, nCount); - } + if(mpPolyPolygon->getB3DPolygon(nIndex) != rPolygon) + { + implForceUniqueCopy(); + mpPolyPolygon->setB3DPolygon(nIndex, rPolygon); } + } - void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount) + void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPolygon, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)"); + + if(nCount) { - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolygon, nCount); } + } - void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolyPolygon& rPolyPolygon) + void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount) + { + if(nCount) { - OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)"); - - if(rPolyPolygon.count()) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(nIndex, rPolyPolygon); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); } + } + + void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolyPolygon& rPolyPolygon) + { + OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)"); - void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon) + if(rPolyPolygon.count()) { - if(rPolyPolygon.count()) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolyPolygon); } + } - void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon) + { + if(rPolyPolygon.count()) { - OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)"); - - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->remove(nIndex, nCount); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); } + } - void B3DPolyPolygon::clear() - { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } + void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)"); - mpPolyPolygon = &maStaticDefaultPolyPolygon; - mpPolyPolygon->incRefCount(); + if(nCount) + { + implForceUniqueCopy(); + mpPolyPolygon->remove(nIndex, nCount); } + } - sal_Bool B3DPolyPolygon::isClosed() const + void B3DPolyPolygon::clear() + { + if(mpPolyPolygon->getRefCount()) + { + mpPolyPolygon->decRefCount(); + } + else { - sal_Bool bRetval(sal_True); + delete mpPolyPolygon; + } - // PolyPOlygon is closed when all contained Polygons are closed or - // no Polygon exists. - for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++) - { - if(!(mpPolyPolygon->getB3DPolygon(a)).isClosed()) - { - bRetval = sal_False; - } - } + mpPolyPolygon = &maStaticDefaultPolyPolygon; + mpPolyPolygon->incRefCount(); + } - return bRetval; - } + sal_Bool B3DPolyPolygon::isClosed() const + { + sal_Bool bRetval(sal_True); - void B3DPolyPolygon::setClosed(sal_Bool bNew) + // PolyPOlygon is closed when all contained Polygons are closed or + // no Polygon exists. + for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++) { - if(bNew != isClosed()) + if(!(mpPolyPolygon->getB3DPolygon(a)).isClosed()) { - implForceUniqueCopy(); - mpPolyPolygon->setClosed(bNew); + bRetval = sal_False; } } - void B3DPolyPolygon::flip() + return bRetval; + } + + void B3DPolyPolygon::setClosed(sal_Bool bNew) + { + if(bNew != isClosed()) { implForceUniqueCopy(); - mpPolyPolygon->flip(); + mpPolyPolygon->setClosed(bNew); } + } - sal_Bool B3DPolyPolygon::hasDoublePoints() const - { - sal_Bool bRetval(sal_False); - - for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++) - { - if((mpPolyPolygon->getB3DPolygon(a)).hasDoublePoints()) - { - bRetval = sal_True; - } - } + void B3DPolyPolygon::flip() + { + implForceUniqueCopy(); + mpPolyPolygon->flip(); + } - return bRetval; - } + sal_Bool B3DPolyPolygon::hasDoublePoints() const + { + sal_Bool bRetval(sal_False); - void B3DPolyPolygon::removeDoublePoints() + for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++) { - if(hasDoublePoints()) + if((mpPolyPolygon->getB3DPolygon(a)).hasDoublePoints()) { - implForceUniqueCopy(); - mpPolyPolygon->removeDoublePoints(); + bRetval = sal_True; } } - void B3DPolyPolygon::transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + return bRetval; + } + + void B3DPolyPolygon::removeDoublePoints() + { + if(hasDoublePoints()) { implForceUniqueCopy(); - mpPolyPolygon->transform(rMatrix); + mpPolyPolygon->removeDoublePoints(); } - } // end of namespace polygon + } + + void B3DPolyPolygon::transform(const ::basegfx::B3DHomMatrix& rMatrix) + { + implForceUniqueCopy(); + mpPolyPolygon->transform(rMatrix); + } } // end of namespace basegfx // eof diff --git a/basegfx/source/polygon/b3dpolypolygontools.cxx b/basegfx/source/polygon/b3dpolypolygontools.cxx index 3b540b258653..4a4e5a3eab2e 100644 --- a/basegfx/source/polygon/b3dpolypolygontools.cxx +++ b/basegfx/source/polygon/b3dpolypolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolypolygontools.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:31:41 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,26 +87,37 @@ namespace basegfx { - namespace polygon + namespace tools { - namespace tools + // B3DPolyPolygon tools + ::basegfx::B3DRange getRange(const ::basegfx::B3DPolyPolygon& rCandidate) { - // B3DPolyPolygon tools - ::basegfx::range::B3DRange getRange(const ::basegfx::polygon::B3DPolyPolygon& rCandidate) + ::basegfx::B3DRange aRetval; + const sal_uInt32 nPolygonCount(rCandidate.count()); + + for(sal_uInt32 a(0L); a < nPolygonCount; a++) { - ::basegfx::range::B3DRange aRetval; - const sal_uInt32 nPolygonCount(rCandidate.count()); + ::basegfx::B3DPolygon aCandidate = rCandidate.getB3DPolygon(a); + aRetval.expand(::basegfx::tools::getRange(aCandidate)); + } + + return aRetval; + } - for(sal_uInt32 a(0L); a < nPolygonCount; a++) - { - ::basegfx::polygon::B3DPolygon aCandidate = rCandidate.getB3DPolygon(a); - aRetval.expand(::basegfx::polygon::tools::getRange(aCandidate)); - } + ::basegfx::B3DPolyPolygon applyLineDashing(const ::basegfx::B3DPolyPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen) + { + ::basegfx::B3DPolyPolygon aRetval; + const sal_uInt32 nPolygonCount(rCandidate.count()); - return aRetval; + for(sal_uInt32 a(0L); a < nPolygonCount; a++) + { + ::basegfx::B3DPolygon aCandidate = rCandidate.getB3DPolygon(a); + aRetval.append(applyLineDashing(aCandidate, raDashDotArray, fFullDashDotLen)); } - } // end of namespace tools - } // end of namespace polygon + + return aRetval; + } + } // end of namespace tools } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/range/b1drange.cxx b/basegfx/source/range/b1drange.cxx index 48271c90e1ac..faf5c89b7a66 100644 --- a/basegfx/source/range/b1drange.cxx +++ b/basegfx/source/range/b1drange.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b1drange.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aw $ $Date: 2003-10-31 10:13:59 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,9 +65,6 @@ namespace basegfx { - namespace range - { - } // end of namespace range } // end of namespace basegfx // eof diff --git a/basegfx/source/range/b2drange.cxx b/basegfx/source/range/b2drange.cxx index f4e7ec28973e..a5c6122c460e 100644 --- a/basegfx/source/range/b2drange.cxx +++ b/basegfx/source/range/b2drange.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2drange.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aw $ $Date: 2003-10-31 10:13:59 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,9 +65,6 @@ namespace basegfx { - namespace range - { - } // end of namespace range } // end of namespace basegfx // eof diff --git a/basegfx/source/range/b3drange.cxx b/basegfx/source/range/b3drange.cxx index c67b87994fcb..714efb85a562 100644 --- a/basegfx/source/range/b3drange.cxx +++ b/basegfx/source/range/b3drange.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3drange.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aw $ $Date: 2003-10-31 10:13:59 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,9 +65,6 @@ namespace basegfx { - namespace range - { - } // end of namespace range } // end of namespace basegfx // eof diff --git a/basegfx/source/tuple/b2dtuple.cxx b/basegfx/source/tuple/b2dtuple.cxx index a8cdfa54d663..1565fe3ea0d2 100644 --- a/basegfx/source/tuple/b2dtuple.cxx +++ b/basegfx/source/tuple/b2dtuple.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dtuple.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-10 11:45:51 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:13 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,65 +69,62 @@ namespace basegfx { - namespace tuple - { - // initialize static member - ::basegfx::tuple::B2DTuple B2DTuple::maEmptyTuple(0.0, 0.0); + // initialize static member + ::basegfx::B2DTuple B2DTuple::maEmptyTuple(0.0, 0.0); - sal_Bool B2DTuple::equalZero() const - { - return (this == &maEmptyTuple || - (::basegfx::numeric::fTools::equalZero(mfX) && ::basegfx::numeric::fTools::equalZero(mfY))); - } + sal_Bool B2DTuple::equalZero() const + { + return (this == &maEmptyTuple || + (::basegfx::fTools::equalZero(mfX) && ::basegfx::fTools::equalZero(mfY))); + } - sal_Bool B2DTuple::equalZero(const double& rfSmallValue) const - { - return (this == &maEmptyTuple || - (::basegfx::numeric::fTools::equalZero(mfX, rfSmallValue) && ::basegfx::numeric::fTools::equalZero(mfY, rfSmallValue))); - } + sal_Bool B2DTuple::equalZero(const double& rfSmallValue) const + { + return (this == &maEmptyTuple || + (::basegfx::fTools::equalZero(mfX, rfSmallValue) && ::basegfx::fTools::equalZero(mfY, rfSmallValue))); + } - sal_Bool B2DTuple::equal(const B2DTuple& rTup) const - { - return ( - ::basegfx::numeric::fTools::equal(mfX, rTup.mfX) && - ::basegfx::numeric::fTools::equal(mfY, rTup.mfY)); - } + sal_Bool B2DTuple::equal(const B2DTuple& rTup) const + { + return ( + ::basegfx::fTools::equal(mfX, rTup.mfX) && + ::basegfx::fTools::equal(mfY, rTup.mfY)); + } - sal_Bool B2DTuple::equal(const B2DTuple& rTup, const double& rfSmallValue) const - { - return ( - ::basegfx::numeric::fTools::equal(mfX, rTup.mfX, rfSmallValue) && - ::basegfx::numeric::fTools::equal(mfY, rTup.mfY, rfSmallValue)); - } + sal_Bool B2DTuple::equal(const B2DTuple& rTup, const double& rfSmallValue) const + { + return ( + ::basegfx::fTools::equal(mfX, rTup.mfX, rfSmallValue) && + ::basegfx::fTools::equal(mfY, rTup.mfY, rfSmallValue)); + } - void B2DTuple::correctValues(const double fCompareValue) + void B2DTuple::correctValues(const double fCompareValue) + { + if(0.0 == fCompareValue) { - if(0.0 == fCompareValue) + if(::basegfx::fTools::equalZero(mfX)) { - if(::basegfx::numeric::fTools::equalZero(mfX)) - { - mfX = 0.0; - } + mfX = 0.0; + } - if(::basegfx::numeric::fTools::equalZero(mfY)) - { - mfY = 0.0; - } + if(::basegfx::fTools::equalZero(mfY)) + { + mfY = 0.0; } - else + } + else + { + if(::basegfx::fTools::equal(mfX, fCompareValue)) { - if(::basegfx::numeric::fTools::equal(mfX, fCompareValue)) - { - mfX = fCompareValue; - } + mfX = fCompareValue; + } - if(::basegfx::numeric::fTools::equal(mfY, fCompareValue)) - { - mfY = fCompareValue; - } + if(::basegfx::fTools::equal(mfY, fCompareValue)) + { + mfY = fCompareValue; } } - } // end of namespace tuple + } } // end of namespace basegfx // eof diff --git a/basegfx/source/tuple/b3dtuple.cxx b/basegfx/source/tuple/b3dtuple.cxx index f1e7691adfb3..718903f0864f 100644 --- a/basegfx/source/tuple/b3dtuple.cxx +++ b/basegfx/source/tuple/b3dtuple.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dtuple.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-10 11:45:51 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:14 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,11 +65,8 @@ namespace basegfx { - namespace tuple - { - // initialize static member - ::basegfx::tuple::B3DTuple B3DTuple::maEmptyTuple(0.0, 0.0, 0.0); - } // end of namespace tuple + // initialize static member + ::basegfx::B3DTuple B3DTuple::maEmptyTuple(0.0, 0.0, 0.0); } // end of namespace basegfx // eof diff --git a/basegfx/source/vector/b2dvector.cxx b/basegfx/source/vector/b2dvector.cxx index ed0325b446a5..d9c46044211c 100644 --- a/basegfx/source/vector/b2dvector.cxx +++ b/basegfx/source/vector/b2dvector.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dvector.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: thb $ $Date: 2003-11-12 12:11:24 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:15 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -73,163 +73,160 @@ namespace basegfx { - namespace vector + B2DVector& B2DVector::normalize() { - B2DVector& B2DVector::normalize() + double fLen(scalar(*this)); + + if(!::basegfx::fTools::equalZero(fLen)) { - double fLen(scalar(*this)); + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equalZero(fLen)) + if(!::basegfx::fTools::equal(fOne, fLen)) { - const double fOne(1.0); + fLen = sqrt(fLen); - if(!::basegfx::numeric::fTools::equal(fOne, fLen)) + if(!::basegfx::fTools::equalZero(fLen)) { - fLen = sqrt(fLen); - - if(!::basegfx::numeric::fTools::equalZero(fLen)) - { - mfX /= fLen; - mfY /= fLen; - } + mfX /= fLen; + mfY /= fLen; } } - - return *this; - } - - B2DVector& B2DVector::operator=( const ::basegfx::tuple::B2DTuple& rVec ) - { - mfX = rVec.getX(); - mfY = rVec.getY(); - return *this; } + return *this; + } - double B2DVector::getLength() const - { - return hypot( mfX, mfY ); - } - - double B2DVector::scalar( const B2DVector& rVec ) const - { - return((mfX * rVec.mfX) + (mfY * rVec.mfY)); - } + B2DVector& B2DVector::operator=( const ::basegfx::B2DTuple& rVec ) + { + mfX = rVec.getX(); + mfY = rVec.getY(); + return *this; + } - double B2DVector::cross( const B2DVector& rVec ) const - { - return(mfX * rVec.getY() - mfY * rVec.getX()); - } - double B2DVector::angle( const B2DVector& rVec ) const - { - return atan2(mfX * rVec.getY() - mfY * rVec.getX(), - mfX * rVec.getX() + mfY * rVec.getY()); - } + double B2DVector::getLength() const + { + return hypot( mfX, mfY ); + } - const B2DVector& B2DVector::getEmptyVector() - { - return (const B2DVector&) ::basegfx::tuple::B2DTuple::getEmptyTuple(); - } + double B2DVector::scalar( const B2DVector& rVec ) const + { + return((mfX * rVec.mfX) + (mfY * rVec.mfY)); + } - B2DVector& B2DVector::operator*=( const matrix::B2DHomMatrix& rMat ) - { - const double fTempX( rMat.get(0,0)*mfX + - rMat.get(0,1)*mfY ); - const double fTempY( rMat.get(1,0)*mfX + - rMat.get(1,1)*mfY ); - mfX = fTempX; - mfY = fTempY; - - return *this; - } + double B2DVector::cross( const B2DVector& rVec ) const + { + return(mfX * rVec.getY() - mfY * rVec.getX()); + } - B2DVector& B2DVector::setLength(double fLen) - { - double fLenNow(scalar(*this)); + double B2DVector::angle( const B2DVector& rVec ) const + { + return atan2(mfX * rVec.getY() - mfY * rVec.getX(), + mfX * rVec.getX() + mfY * rVec.getY()); + } - if(!::basegfx::numeric::fTools::equalZero(fLenNow)) - { - const double fOne(10.0); + const B2DVector& B2DVector::getEmptyVector() + { + return (const B2DVector&) ::basegfx::B2DTuple::getEmptyTuple(); + } - if(!::basegfx::numeric::fTools::equal(fOne, fLenNow)) - { - fLen /= sqrt(fLenNow); - } + B2DVector& B2DVector::operator*=( const B2DHomMatrix& rMat ) + { + const double fTempX( rMat.get(0,0)*mfX + + rMat.get(0,1)*mfY ); + const double fTempY( rMat.get(1,0)*mfX + + rMat.get(1,1)*mfY ); + mfX = fTempX; + mfY = fTempY; - mfX *= fLen; - mfY *= fLen; - } + return *this; + } - return *this; - } + B2DVector& B2DVector::setLength(double fLen) + { + double fLenNow(scalar(*this)); - sal_Bool B2DVector::isNormalized() const + if(!::basegfx::fTools::equalZero(fLenNow)) { - const double fOne(1.0); - const double fScalar(scalar(*this)); + const double fOne(10.0); - return (::basegfx::numeric::fTools::equal(fOne, fScalar)); - } + if(!::basegfx::fTools::equal(fOne, fLenNow)) + { + fLen /= sqrt(fLenNow); + } - sal_Bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB ) - { - double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX()); - return ::basegfx::numeric::fTools::equalZero(fVal); + mfX *= fLen; + mfY *= fLen; } - B2DVectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB ) - { - double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX()); + return *this; + } - if(fVal > 0.0) - { - return ORIENTATION_POSITIVE; - } + sal_Bool B2DVector::isNormalized() const + { + const double fOne(1.0); + const double fScalar(scalar(*this)); - if(fVal < 0.0) - { - return ORIENTATION_NEGATIVE; - } + return (::basegfx::fTools::equal(fOne, fScalar)); + } - return ORIENTATION_NEUTRAL; - } + sal_Bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB ) + { + double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX()); + return ::basegfx::fTools::equalZero(fVal); + } + + B2DVectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB ) + { + double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX()); - B2DVector getPerpendicular( const B2DVector& rNormalizedVec ) + if(fVal > 0.0) { - B2DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX()); - return aPerpendicular; + return ORIENTATION_POSITIVE; } - B2DVector operator*( const matrix::B2DHomMatrix& rMat, const B2DVector& rVec ) + if(fVal < 0.0) { - B2DVector aRes( rVec ); - return aRes*=rMat; + return ORIENTATION_NEGATIVE; } - ::basegfx::vector::B2DVectorContinuity getContinuity(const B2DVector& rBackVector, const B2DVector& rForwardVector ) + return ORIENTATION_NEUTRAL; + } + + B2DVector getPerpendicular( const B2DVector& rNormalizedVec ) + { + B2DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX()); + return aPerpendicular; + } + + B2DVector operator*( const B2DHomMatrix& rMat, const B2DVector& rVec ) + { + B2DVector aRes( rVec ); + return aRes*=rMat; + } + + ::basegfx::B2DVectorContinuity getContinuity(const B2DVector& rBackVector, const B2DVector& rForwardVector ) + { + ::basegfx::B2DVectorContinuity eRetval(::basegfx::CONTINUITY_NONE); + + if(!rBackVector.equalZero() && !rForwardVector.equalZero()) { - ::basegfx::vector::B2DVectorContinuity eRetval(::basegfx::vector::CONTINUITY_NONE); + const B2DVector aInverseForwardVector(-rForwardVector.getX(), -rForwardVector.getY()); - if(!rBackVector.equalZero() && !rForwardVector.equalZero()) + if(rBackVector.equal(aInverseForwardVector)) { - const B2DVector aInverseForwardVector(-rForwardVector.getX(), -rForwardVector.getY()); - - if(rBackVector.equal(aInverseForwardVector)) - { - // same direction and same length -> C2 - eRetval = ::basegfx::vector::CONTINUITY_C2; - } - else if(areParallel(rBackVector, aInverseForwardVector)) - { - // same direction -> C1 - eRetval = ::basegfx::vector::CONTINUITY_C1; - } + // same direction and same length -> C2 + eRetval = ::basegfx::CONTINUITY_C2; + } + else if(areParallel(rBackVector, aInverseForwardVector)) + { + // same direction -> C1 + eRetval = ::basegfx::CONTINUITY_C1; } - - return eRetval; } - } // end of namespace vector + + return eRetval; + } } // end of namespace basegfx // eof diff --git a/basegfx/source/vector/b3dvector.cxx b/basegfx/source/vector/b3dvector.cxx index 45c8b3d58fa8..6e08ea0fffa7 100644 --- a/basegfx/source/vector/b3dvector.cxx +++ b/basegfx/source/vector/b3dvector.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dvector.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:16 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:16 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,71 +69,68 @@ namespace basegfx { - namespace vector + B3DVector& B3DVector::normalize() { - B3DVector& B3DVector::normalize() + double fLen(scalar(*this)); + + if(!::basegfx::fTools::equalZero(fLen)) { - double fLen(scalar(*this)); + const double fOne(1.0); - if(!::basegfx::numeric::fTools::equalZero(fLen)) + if(!::basegfx::fTools::equal(fOne, fLen)) { - const double fOne(1.0); + fLen = sqrt(fLen); - if(!::basegfx::numeric::fTools::equal(fOne, fLen)) + if(!::basegfx::fTools::equalZero(fLen)) { - fLen = sqrt(fLen); - - if(!::basegfx::numeric::fTools::equalZero(fLen)) - { - mfX /= fLen; - mfY /= fLen; - mfZ /= fLen; - } + mfX /= fLen; + mfY /= fLen; + mfZ /= fLen; } } - - return *this; } - B3DVector B3DVector::getPerpendicular(const B3DVector& rNormalizedVec) const - { - B3DVector aNew(*this); - aNew = cross(aNew, rNormalizedVec); - aNew.normalize(); - return aNew; - } + return *this; + } - B3DVector B3DVector::getProjectionOnPlane(const B3DVector& rNormalizedPlane) const - { - B3DVector aNew(*this); - aNew = cross(aNew, rNormalizedPlane); - aNew = cross(aNew, rNormalizedPlane); + B3DVector B3DVector::getPerpendicular(const B3DVector& rNormalizedVec) const + { + B3DVector aNew(*this); + aNew = cross(aNew, rNormalizedVec); + aNew.normalize(); + return aNew; + } + + B3DVector B3DVector::getProjectionOnPlane(const B3DVector& rNormalizedPlane) const + { + B3DVector aNew(*this); + aNew = cross(aNew, rNormalizedPlane); + aNew = cross(aNew, rNormalizedPlane); - aNew.mfX = mfX - aNew.mfX; - aNew.mfY = mfY - aNew.mfY; - aNew.mfZ = mfZ - aNew.mfZ; + aNew.mfX = mfX - aNew.mfX; + aNew.mfY = mfY - aNew.mfY; + aNew.mfZ = mfZ - aNew.mfZ; - return aNew; - } + return aNew; + } - B3DVector& B3DVector::operator*=( const matrix::B3DHomMatrix& rMat ) - { - const double fTempX( rMat.get(0,0)*mfX + rMat.get(0,1)*mfY + rMat.get(0,2)*mfZ ); - const double fTempY( rMat.get(1,0)*mfX + rMat.get(1,1)*mfY + rMat.get(1,2)*mfZ ); - const double fTempZ( rMat.get(2,0)*mfX + rMat.get(2,1)*mfY + rMat.get(2,2)*mfZ ); - mfX = fTempX; - mfY = fTempY; - mfZ = fTempZ; + B3DVector& B3DVector::operator*=( const B3DHomMatrix& rMat ) + { + const double fTempX( rMat.get(0,0)*mfX + rMat.get(0,1)*mfY + rMat.get(0,2)*mfZ ); + const double fTempY( rMat.get(1,0)*mfX + rMat.get(1,1)*mfY + rMat.get(1,2)*mfZ ); + const double fTempZ( rMat.get(2,0)*mfX + rMat.get(2,1)*mfY + rMat.get(2,2)*mfZ ); + mfX = fTempX; + mfY = fTempY; + mfZ = fTempZ; - return *this; - } + return *this; + } - B3DVector operator*( const matrix::B3DHomMatrix& rMat, const B3DVector& rVec ) - { - B3DVector aRes( rVec ); - return aRes*=rMat; - } - } // end of namespace vector + B3DVector operator*( const B3DHomMatrix& rMat, const B3DVector& rVec ) + { + B3DVector aRes( rVec ); + return aRes*=rMat; + } } // end of namespace basegfx // eof |