namespace chart
{ usingnamespace ::com::sun::star; using ::basegfx::B2DRectangle; using ::basegfx::B2DTuple;
namespace{ /** @descr This is a supporting function for lcl_clip2d. It computes a new parametric valueforanentering(dTE)orleaving(dTL)intersectionpointwithone oftheedgesboundingtheclippingarea. Forexplanationoftheparameterspleasereferto:
if (fDenom > 0) // Intersection enters: PE
{
fT = fNum / fDenom; // Parametric value at the intersection. if (fT > fTL) // fTE and fTL crossover returnfalse; // therefore reject the line. elseif (fT > fTE) // A new fTE has been found.
fTE = fT;
} elseif (fDenom < 0) // Intersection leaves: PL
{
fT = fNum / fDenom; // Parametric Value at the intersection. if (fT < fTE) // fTE and fTL crossover returnfalse; // therefore reject the line. elseif (fT < fTL) // A new fTL has been found.
fTL = fT;
} elseif (fNum > 0) returnfalse; // Line lies on the outside of the edge.
returntrue;
}
/** @descr The line given by its two endpoints rP0 and rP1 is clipped at the rectangle rRectangle.Ifthereisatleastapartofitvisiblethensal_Trueisreturnedand theendpointsofthatpartarestoredinrP0andrP1.ThepointsrP0andrP1 mayhavethesamecoordinates. @paramrP0Startpointofthelinetoclip.Modifiedtocontainastartpointinside theclippingareaifpossible. @paramrP1Endpointofthelinetoclip.Modifiedtocontainanendpointinside theclippingareaifpossible. @paramrRectangleClippingarea. @returnIfthelineliescompletelyorpartlyinsidetheclippingareathenTRUE isreturned.Ifthelineliescompletelyoutsidethensal_FalseisreturnedandrP0and rP1areleftunmodified.
*/ bool lcl_clip2d(B2DTuple& rPoint0, B2DTuple& rPoint1, const B2DRectangle& rRectangle)
{ //Direction vector of the line.
B2DTuple aDirection = rPoint1 - rPoint0;
if( aDirection.getX()==0 && aDirection.getY()==0 && rRectangle.isInside(rPoint0) )
{ // Degenerate case of a zero length line. returntrue;
} else
{ // Values of the line parameter where the line enters resp. leaves the rectangle. double fTE = 0,
fTL = 1;
// Test whether at least a part lies in the four half-planes with respect to // the rectangles four edges. if( lcl_CLIPt(aDirection.getX(), rRectangle.getMinX() - rPoint0.getX(), fTE, fTL) ) if( lcl_CLIPt(-aDirection.getX(), rPoint0.getX() - rRectangle.getMaxX(), fTE, fTL) ) if( lcl_CLIPt(aDirection.getY(), rRectangle.getMinY() - rPoint0.getY(), fTE, fTL) ) if( lcl_CLIPt(-aDirection.getY(), rPoint0.getY() - rRectangle.getMaxY(), fTE, fTL) )
{ // At least a part is visible. if (fTL < 1)
{ // Compute the new end point.
rPoint1.setX( rPoint0.getX() + fTL * aDirection.getX() );
rPoint1.setY( rPoint0.getY() + fTL * aDirection.getY() );
} if (fTE > 0)
{ // Compute the new starting point.
rPoint0.setX( rPoint0.getX() + fTE * aDirection.getX() );
rPoint0.setY( rPoint0.getY() + fTE * aDirection.getY() );
} returntrue;
}
unsignedint round_up_nearest_pow2(unsignedint v)
{ // compute the next highest power of 2 of 32-bit v
--v;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
++v; return v;
}
void lcl_addPointToPoly( drawing::PolyPolygonShape3D& rPoly
, const drawing::Position3D& rPos
, sal_Int32 nPolygonIndex
, std::vector< sal_Int32 >& rResultPointCount
, sal_Int32 nReservePointCount )
{ if(nPolygonIndex<0)
{
OSL_FAIL( "The polygon index needs to be > 0");
nPolygonIndex=0;
}
//make sure that we have enough polygons if(nPolygonIndex >= rPoly.SequenceX.getLength() )
{
rPoly.SequenceX.realloc(nPolygonIndex+1);
rPoly.SequenceY.realloc(nPolygonIndex+1);
rPoly.SequenceZ.realloc(nPolygonIndex+1);
rResultPointCount.resize(nPolygonIndex+1,0);
}
void lcl_addPointToPoly( std::vector<std::vector<css::drawing::Position3D>>& rPoly
, const drawing::Position3D& rPos
, sal_Int32 nPolygonIndex
, std::vector< sal_Int32 >& rResultPointCount
, sal_Int32 nReservePointCount )
{ if(nPolygonIndex<0)
{
OSL_FAIL( "The polygon index needs to be > 0");
nPolygonIndex=0;
}
//make sure that we have enough polygons if(o3tl::make_unsigned(nPolygonIndex) >= rPoly.size() )
{
rPoly.resize(nPolygonIndex+1);
rResultPointCount.resize(nPolygonIndex+1,0);
}
// set last point to a position outside the rectangle, such that the first // time lcl_clip2d returns true, the comparison to last will always yield false
drawing::Position3D aLast(rRectangle.getMinX()-1.0,rRectangle.getMinY()-1.0, 0.0 );
// set last point to a position outside the rectangle, such that the first // time lcl_clip2d returns true, the comparison to last will always yield false
drawing::Position3D aLast(rRectangle.getMinX()-1.0,rRectangle.getMinY()-1.0, 0.0 );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.