diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2004-11-26 17:38:29 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2004-11-26 17:38:29 +0000 |
commit | 776a6bf0916414713d73a0b6c365b0881834739a (patch) | |
tree | 8f854392db5bd74173229119ccdeabb136a080a3 /basegfx/source | |
parent | 72f3dfe2bd78948b526c51bd5016d8f5dda9d5ab (diff) |
INTEGRATION: CWS presentationengine01 (1.12.2); FILE MERGED
2004/11/21 22:03:48 thb 1.12.2.11: #110496# After merge, polygon clipper now uses correct orientation, reverted back to original version for rect and circle generation
2004/11/17 18:55:09 thb 1.12.2.10: RESYNC: (1.13-1.14); FILE MERGED
2004/08/29 00:55:53 thb 1.12.2.9: #110496# Fixed circle approximation (had wrong control vectors
2004/08/23 14:12:27 thb 1.12.2.8: RESYNC: (1.12-1.13); FILE MERGED
2004/08/19 00:10:02 thb 1.12.2.7: #110496# Added B2DMultiRange implementation
2004/08/11 13:23:17 thb 1.12.2.6: #110496# Now using M_SQRT2 instead of direct sqrt(2) calculations
2004/08/11 13:22:07 thb 1.12.2.5: #110496# Now using M_SQRT2 instead of direct sqrt(2) calculations
2004/08/11 13:06:20 thb 1.12.2.4: #110496# Added circle factory method for B2DPolygon
2004/07/14 10:39:01 thb 1.12.2.3: #110496# Correctly handling boundary cases in getPositionAbsolute()
2004/07/01 17:00:33 thb 1.12.2.2: #110496# Added SVG import to B2DPolygon
2004/04/21 18:46:03 thb 1.12.2.1: #110496# Added B2DPolygon contructor to B2DPolyPolygon, added rect2poly convenience method to polygontools
Diffstat (limited to 'basegfx/source')
-rw-r--r-- | basegfx/source/polygon/b2dpolygontools.cxx | 89 |
1 files changed, 79 insertions, 10 deletions
diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx index 2cb5b38eb9d4..ef92305a1ed0 100644 --- a/basegfx/source/polygon/b2dpolygontools.cxx +++ b/basegfx/source/polygon/b2dpolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygontools.cxx,v $ * - * $Revision: 1.14 $ + * $Revision: 1.15 $ * - * last change: $Author: pjunck $ $Date: 2004-11-03 08:37:46 $ + * last change: $Author: rt $ $Date: 2004-11-26 18:38:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,6 +59,10 @@ * ************************************************************************/ +#ifndef _BGFX_NUMERIC_FTOOLS_HXX +#include <basegfx/numeric/ftools.hxx> +#endif + #ifndef _BGFX_POLYGON_B2DPOLYGONTOOLS_HXX #include <basegfx/polygon/b2dpolygontools.hxx> #endif @@ -75,10 +79,6 @@ #include <basegfx/polygon/b2dpolypolygon.hxx> #endif -#ifndef _BGFX_NUMERIC_FTOOLS_HXX -#include <basegfx/numeric/ftools.hxx> -#endif - #ifndef _BGFX_RANGE_B2DRANGE_HXX #include <basegfx/range/b2drange.hxx> #endif @@ -569,8 +569,14 @@ namespace basegfx { B2DPoint aRetval; const sal_uInt32 nPointCount(rCandidate.count()); + const sal_uInt32 nPointCountMinusOne(nPointCount - 1L); - if(nPointCount > 1L) + if( 1L == nPointCount ) + { + // only one point (i.e. no edge) - simply take that point + aRetval = rCandidate.getB2DPoint(0); + } + else if(nPointCount > 1L) { sal_uInt32 nIndex(0L); bool bIndexDone(false); @@ -613,7 +619,7 @@ namespace basegfx { // crop to polygon end fDistance = fZero; - nIndex = nPointCount - 1L; + nIndex = nPointCountMinusOne; bIndexDone = true; } } @@ -626,7 +632,15 @@ namespace basegfx // get length of next edge fEdgeLength = getEdgeLength(rCandidate, nIndex); - if(fTools::moreOrEqual(fDistance, fEdgeLength)) + // edge found must be on the half-open range + // [0,fEdgeLength). + // Note that in theory, we cannot move beyond + // the last polygon point, since fDistance>=fLength + // is checked above. Unfortunately, with floating- + // point calculations, this case might happen. + // Handled by nIndex check below + if( nIndex < nPointCountMinusOne && + fDistance >= fEdgeLength ) { // go to next edge fDistance -= fEdgeLength; @@ -653,7 +667,11 @@ namespace basegfx if(!fTools::equalZero(fEdgeLength)) { - fRelative = fDistance / fEdgeLength; + // clamp fRelative to [0,1] range. Borderline cases + // can happen, since this is floating point arithmetic. + fRelative = ::std::max(0.0, + ::std::min(1.0, + fDistance / fEdgeLength) ); } // add calculated average value to the return value @@ -1321,6 +1339,57 @@ namespace basegfx return false; } + + B2DPolygon createPolygonFromRect( const B2DRectangle& rRect ) + { + B2DPolygon aRet; + + const double aX1( rRect.getMinX() ); + const double aX2( rRect.getMaxX() ); + const double aY1( rRect.getMinY() ); + const double aY2( rRect.getMaxY() ); + + aRet.append( B2DPoint( aX1, aY1 ) ); + aRet.append( B2DPoint( aX2, aY1 ) ); + aRet.append( B2DPoint( aX2, aY2 ) ); + aRet.append( B2DPoint( aX1, aY2 ) ); + aRet.setClosed( true ); + + return aRet; + } + + B2DPolygon createPolygonFromCircle( const B2DPoint& rCenter, double nRadius ) + { + B2DPolygon aRet; + + const double aX( rCenter.getX() ); + const double aY( rCenter.getY() ); + + const double nKappa( (M_SQRT2-1.0)*4.0/3.0 ); + const double l( nRadius * nKappa ); + + aRet.append( B2DPoint( aX, aY-nRadius ) ); + aRet.append( B2DPoint( aX+nRadius, aY ) ); + aRet.append( B2DPoint( aX, aY+nRadius ) ); + aRet.append( B2DPoint( aX-nRadius, aY ) ); + + aRet.setControlPointA( 0, B2DPoint( aX+l, aY-nRadius ) ); + aRet.setControlPointB( 0, B2DPoint( aX+nRadius, aY-l ) ); + + aRet.setControlPointA( 1, B2DPoint( aX+nRadius, aY+l ) ); + aRet.setControlPointB( 1, B2DPoint( aX+l, aY+nRadius ) ); + + aRet.setControlPointA( 2, B2DPoint( aX-l, aY+nRadius ) ); + aRet.setControlPointB( 2, B2DPoint( aX-nRadius, aY+l ) ); + + aRet.setControlPointA( 3, B2DPoint( aX-nRadius, aY-l ) ); + aRet.setControlPointB( 3, B2DPoint( aX-l, aY-nRadius ) ); + + aRet.setClosed( true ); + + return aRet; + } + } // end of namespace tools } // end of namespace basegfx |