CartoType C++ API 7.8.2, 2022-03-25
for Windows, Linux, Qt and other platforms supporting C++ development
|
#include <cartotype_path.h>
Classes | |
class | ConstIter |
Public Member Functions | |
virtual | ~MPath () |
virtual size_t | Contours () const =0 |
virtual TContour | Contour (size_t aIndex) const =0 |
virtual bool | MayHaveCurves () const =0 |
template<class MPathTraverser > | |
void | Traverse (MPathTraverser &aTraverser, const TRect &aClip) const |
template<class MPathTraverser > | |
void | Traverse (MPathTraverser &aTraverser, const TRect *aClip=nullptr) const |
bool | operator== (const MPath &aOther) const |
TRect | CBox () const |
bool | CBoxBiggerThan (int32_t aSize) const |
bool | IsContainedIn (const TRect &aRect) const |
bool | Contains (double aX, double aY) const |
bool | Contains (const TPoint &aPoint) const |
bool | Contains (const TPointFP &aPoint) const |
bool | MayIntersect (const TRect &aRect) const |
bool | MayIntersect (const TRect &aRect, int32_t aBorder) const |
bool | Intersects (const TRect &aRect) const |
bool | Intersects (const MPath &aPath, const TRect *aBounds=nullptr) const |
int32_t | MaxDistanceFromOrigin () const |
TPathIntersectionType | IntersectionType (const MPath &aOther, double *aDistance=nullptr, TPointFP *aNearest1=nullptr, TPointFP *aNearest2=nullptr) const |
TPathIntersectionInfo | IntersectionInfo (const MPath &aOther) const |
double | DistanceFrom (const MPath &aOther, TPointFP *aNearest1=nullptr, TPointFP *aNearest2=nullptr, TPathIntersectionType *aType=nullptr) const |
double | DistanceFromPoint (const TPointFP &aPoint, TPointFP *aNearest=nullptr, size_t *aContourIndex=nullptr, size_t *aLineIndex=nullptr, double *aFractionaLineIndex=nullptr, bool aTreatAsOpen=false) const |
bool | IsClippingNeeded (const TRect &aClip) const |
COutline | Copy () const |
COutline | ClippedPath (const TRect &aClip) const |
COutline | ClippedPath (const MPath &aClip) const |
COutline | ClippedPath (const TClipRegion &aClip) const |
COutline | Clip (TClipOperation aClipOperation, const MPath &aClip) const |
COutline | Envelope (double aOffset) const |
bool | IsSmoothingNeeded () const |
COutline | SmoothPath () const |
COutline | FlatPath (double aMaxDistance) const |
COutline | TruncatedPath (double aStart, double aEnd) const |
COutline | OffsetPath (double aOffset) const |
COutline | TransformedPath (const TTransform &aTransform) const |
COutline | TransformedPath (TDrawResult &aError, MPointTransformer &aTransformer, int32_t aFractionalBits) const |
std::array< TLine, 3 > | GetHorizontalPaths (int32_t aPathLength, int32_t aLabelHeight, const TPointFP &aUpVector, const TRect *aBounds, const TRect *aClip) const |
TPointFP | CenterOfGravity () const |
void | GetCenterOfGravity (TPoint &aCenter) const |
double | Length () const |
double | Area () const |
TPointFP | PointAtLength (double aPos) const |
std::pair< TPoint, bool > | End () const |
void | Write (TDataOutputStream &aOutput) const |
bool | IsEmpty () const |
bool | IsPoint () const |
bool | IsGridOrientedRectangle (TRect *aRect=nullptr) const |
void | GetSphericalAreaAndLength (const CProjection &aProjection, double *aArea, double *aLength) const |
TClipType | ClipType (const TRect &aRect) const |
bool | HasCurves () const |
ConstIter | begin () const |
ConstIter | end () const |
Path objects, which are sequences of contours, must implement the MPath interface class.
|
inlinevirtual |
A virtual destructor: needed in case paths returned by ClippedPath are not the same as the path passed in and must therefore be deleted by the caller.
double CartoType::MPath::Area | ( | ) | const |
Returns the area of the path, ignoring curves (i.e., treating off-curve points as on-curve).
|
inline |
Returns a constant iterator positioned at the start of the contours.
TRect CartoType::MPath::CBox | ( | ) | const |
Returns the minimal bounding box that contains all the control points of a path. This is not as small as the bounding box of the path itself but is guaranteed to contain it and can be calculated more quickly.
bool CartoType::MPath::CBoxBiggerThan | ( | int32_t | aSize | ) | const |
Returns true if the bounding box of the control points of the path is bigger than aSize in either width or height.
TPointFP CartoType::MPath::CenterOfGravity | ( | ) | const |
Return the center of gravity of a path. Algorithm from comp.graphics.algorithms FAQ 2.02, based on weighted average of points of gravity of triangulation. The weight is based on the signed area of the triangle.
The first point is used as the origin to avoid loss of accuracy when multiplying large numbers.
COutline CartoType::MPath::Clip | ( | TClipOperation | aClipOperation, |
const MPath & | aClip | ||
) | const |
Performs a general clip operation, which is one of clip, union, difference and exclusive or, on this path using aClip as the clip path, and returns the resulting path. The clipping path (aClip) must be made from closed contours only.
Returns a copy of this path, clipped to aClip. The subject path (*this) may contain open contours. The clipping path (aClip) must be made from closed contours only.
COutline CartoType::MPath::ClippedPath | ( | const TClipRegion & | aClip | ) | const |
Returns a version of the path clipped to the clip region aClip.
Returns a version of the path clipped to the axis-aligned rectangle aClip.
Returns the clip type of this path. The clip type labels different relationships a clip rectangle has with a path, to decide what sort of clipping is needed.
|
inline |
Returns true if this path contains aPoint.
|
inline |
Returns true if this path contains aPoint.
bool CartoType::MPath::Contains | ( | double | aX, |
double | aY | ||
) | const |
Returns true if this path contains the point (aX,aY).
|
pure virtual |
Returns the contour indexed by aIndex.
Implemented in CartoType::COutline, CartoType::TContour, CartoType::TSimpleContourData, CartoType::CContourBase< T >, CartoType::CContourBase< TOutlinePoint >, CartoType::CContourBase< TPoint >, CartoType::TWritableContour, and CartoType::TFixedSizeContour< aPointCount, aClosed >.
|
pure virtual |
Returns the number of contours.
Implemented in CartoType::MContour, CartoType::CContourBase< T >, CartoType::CContourBase< TOutlinePoint >, CartoType::CContourBase< TPoint >, and CartoType::COutline.
double CartoType::MPath::DistanceFrom | ( | const MPath & | aOther, |
TPointFP * | aNearest1 = nullptr , |
||
TPointFP * | aNearest2 = nullptr , |
||
TPathIntersectionType * | aType = nullptr |
||
) | const |
Finds the distance between two paths. aNearest1 and aNearest2, if non-null, are used to return the nearest points on this path and the other path respectively. If one of the paths contains or intersects the other, the distance returned is zero, and aNearest1 and aNearest2 are both set to the first intersection if there is one, or to the first point of the contained path if not.
If either path is empty, this function returns CT_DBL_MAX (the largest possible number).
double CartoType::MPath::DistanceFromPoint | ( | const TPointFP & | aPoint, |
TPointFP * | aNearest = nullptr , |
||
size_t * | aContourIndex = nullptr , |
||
size_t * | aLineIndex = nullptr , |
||
double * | aFractionaLineIndex = nullptr , |
||
bool | aTreatAsOpen = false |
||
) | const |
Find the distance from a point to a path. It is the shortest distance from the point to any contour.
If aNearest is non-null use it to return the coordinates of the nearest point in any contour, or the original point if the nearest contour is closed and the point is inside it.
If aContourIndex is non-null use it to return the index of the contour containing the nearest point. If aLineIndex is non-null use it to return the index of the line within the contour containing the nearest point. If aFractionalLineIndex is non-null return the fractional line index (e.g., 4.5 if the point is half way between points 4 and 5) of the nearest point, or 0 if there are fewer than 2 points or the contour is closed and the point is inside.
If aTreatAsOpen is true, treat any contour as open even if it is closed, and therefore return a non-zero distance even if the point is inside the contour.
If the path is empty return DBL_MAX.
std::pair< TPoint, bool > CartoType::MPath::End | ( | ) | const |
Returns the point at the end of the path and a boolean value. If the path is empty the second element of the pair is false.
|
inline |
Returns a constant iterator positioned at the end of the contours.
COutline CartoType::MPath::Envelope | ( | double | aOffset | ) | const |
Returns a path that is the envelope of the current path created by offsetting the path by aOffset. The offset may be negative if the subject path is made of polygons only.
This function runs quite slowly; it is intended for situations where there are overlapping subject paths and a single simplified result is needed, without overlaps. Use COutline::AppendCircularPenEnvelope by preference.
COutline CartoType::MPath::FlatPath | ( | double | aMaxDistance | ) | const |
Returns a flattened version of a path.
void CartoType::MPath::GetCenterOfGravity | ( | TPoint & | aCenter | ) | const |
Return the center of gravity of a path, rounding to integer coordinates.
std::array< TLine, 3 > CartoType::MPath::GetHorizontalPaths | ( | int32_t | aDesiredLength, |
int32_t | aLabelHeight, | ||
const TPointFP & | aUpVector, | ||
const TRect * | aBounds, | ||
const TRect * | aClip | ||
) | const |
Returns up to three horizontal lines inside an outline, suitable for drawing a label.
aFontSize is size in pixels of the main label font. aUpVector is a vector defining the up direction for labels. aBounds is the bounds of the path, if known. aClip is the clip rectangle if any.
The path must be in 64ths of pixels.
void CartoType::MPath::GetSphericalAreaAndLength | ( | const CProjection & | aProjection, |
double * | aArea, | ||
double * | aLength | ||
) | const |
Gets the spherical area and/or length of a path in meters, given the projection used to project the path. The path must be in map coordinates.
bool CartoType::MPath::HasCurves | ( | ) | const |
Returns true if this path has any off-curve points.
TPathIntersectionInfo CartoType::MPath::IntersectionInfo | ( | const MPath & | aOther | ) | const |
Returns information about the intersection of this path with another one.
TPathIntersectionType CartoType::MPath::IntersectionType | ( | const MPath & | aOther, |
double * | aDistance = nullptr , |
||
TPointFP * | aNearest1 = nullptr , |
||
TPointFP * | aNearest2 = nullptr |
||
) | const |
Returns the relationship between two paths as a path intersection type.
Other information can optionally be obtained.
If aDistance is non-null it is used to return the distance between the two path, or zero if they intersect.
aNearest1 and aNearest2, if non-null, are used to return the nearest points on this path and the other path respectively.
This function ignores curves, and does not handle self-intersecting paths.
If one of the paths contains or intersects the other, the distance returned is zero, and aNearest1 and aNearest2 are both set to the first intersection if there is one, or to the first point of the contained path if not.
Containment is defined to mean that each contour of one path is wholly contained by a single contour of the other.
If either path is empty, this function returns TPathIntersectionType::Separate, and sets the other return values to CT_DBL_MAX (the largest possible number).
Returns true if this path intersects the other path. If aBounds is supplied, it is assumed to be the bounding box of this path, and is used instead of calculating the bounding box.
bool CartoType::MPath::Intersects | ( | const TRect & | aRect | ) | const |
Returns true if the path intersects a specified rectangle. For single points, this is true if the point is inside the rectangle. For open paths, this is true if at least one line intersects the rectangle. For closed paths, the polygon defined by the control points must intersect the rectangle.
bool CartoType::MPath::IsClippingNeeded | ( | const TRect & | aClip | ) | const |
Returns true if ClippedPath(aClip) would change the path.
bool CartoType::MPath::IsContainedIn | ( | const TRect & | aRect | ) | const |
Returns true if this path is contained by the rectangle aRect.
bool CartoType::MPath::IsEmpty | ( | ) | const |
Returns true if the path is empty, which means it has no points. A path with a single point, or a path of zero length, is not empty.
bool CartoType::MPath::IsGridOrientedRectangle | ( | TRect * | aRect = nullptr | ) | const |
Determines whether a path is a grid-oriented rectangle and return the rectangle if so, and if aRect is non-null.
bool CartoType::MPath::IsPoint | ( | ) | const |
Returns true if the path is a single point, defined as a path of one contour with one point.
bool CartoType::MPath::IsSmoothingNeeded | ( | ) | const |
Returns true if SmoothPath would change the path.
double CartoType::MPath::Length | ( | ) | const |
Returns the length of the path. This is the sum of the length of the line segments, ignoring curves (i.e., treating off-curve points as on-curve).
int32_t CartoType::MPath::MaxDistanceFromOrigin | ( | ) | const |
Returns a distance guaranteed to be greater than the maximum distance of the path from the origin. This is used in ensuring that a margin is drawn round a map so that parts of objects just off it appear, thus enabling tiles to be drawn that match along their edges.
For speed the number returned is simply the ceiling of root-2 times the greatest x or y distance from the origin.
|
pure virtual |
Returns true if the path may have off-curve points.
Implemented in CartoType::TContour, CartoType::TSimpleContourData, CartoType::CContour, CartoType::COnCurveContour, CartoType::TWritableContour, CartoType::COutline, and CartoType::TFixedSizeContour< aPointCount, aClosed >.
bool CartoType::MPath::MayIntersect | ( | const TRect & | aRect | ) | const |
Returns true if this path contains aPath.
Returns true if the path may possibly intersect the specified rectangle. Returns false if there is definitely no intersection. The return value actually indicates whether the bounding box of the path's control points intersects the rectangle.
bool CartoType::MPath::MayIntersect | ( | const TRect & | aRect, |
int32_t | aBorder | ||
) | const |
Returns true if the path may possibly intersect the specified rectangle, expanded on all sides by aBorder. Returns false if there is definitely no intersection. The return value actually indicates whether the bounding box of the path's control points intersects the rectangle.
COutline CartoType::MPath::OffsetPath | ( | double | aOffset | ) | const |
Offsets a path by a distance. The distance is negative for a left offset, positive for a right offset.
bool CartoType::MPath::operator== | ( | const MPath & | aOther | ) | const |
The equality operator.
TPointFP CartoType::MPath::PointAtLength | ( | double | aPos | ) | const |
Return a point at a certain distance along a path. If aPos is less than or equal to zero return the start of the path. If aPos is greater than the length of the path return the end of the path.
COutline CartoType::MPath::SmoothPath | ( | ) | const |
Returns a version of the path with sequences of obtuse angles converted to curves. Any sequence of two or more segments of length aMinSegmentLength or more is made into a curve.
COutline CartoType::MPath::TransformedPath | ( | const TTransform & | aTransform | ) | const |
Creates a transformed path using the supplied transform.
COutline CartoType::MPath::TransformedPath | ( | TDrawResult & | aError, |
MPointTransformer & | aTransformer, | ||
int32_t | aFractionalBits | ||
) | const |
Creates a transformed path by providing a point transformer and number of fractional bits.
|
inline |
Traverses this path, calling the functions defined by aTraverser to handle moves, lines, and curves. Clips the output to aClip.
|
inline |
Traverses this path, calling the functions defined by aTraverser to handle moves, lines, and curves. Clips the output to aClip if aClip is non-null.
COutline CartoType::MPath::TruncatedPath | ( | double | aStart, |
double | aEnd | ||
) | const |
Returns a version of the path truncated by removing a length equal to aStart at the start of each contour, and a length equal to aEnd at the end.
void CartoType::MPath::Write | ( | TDataOutputStream & | aOutput | ) | const |
Write a path to a stream in serialized form.