diff options
Diffstat (limited to 'basegfx/inc/basegfx/polygon/b2dpolygontools.hxx')
-rw-r--r-- | basegfx/inc/basegfx/polygon/b2dpolygontools.hxx | 263 |
1 files changed, 126 insertions, 137 deletions
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 |