CartoType C++ API 7.8.2, 2022-03-25
for Windows, Linux, Qt and other platforms supporting C++ development
Classes | Public Member Functions | List of all members
CartoType::MPath Class Referenceabstract

#include <cartotype_path.h>

Inheritance diagram for CartoType::MPath:
CartoType::CMapObject CartoType::COutline CartoType::MContour CartoType::MWritableContour CartoType::TContour CartoType::TFixedSizeContour< aPointCount, aClosed > CartoType::CContourBase< TOutlinePoint > CartoType::CContourBase< TPoint > CartoType::CContourBase< T > CartoType::TSimpleContourData CartoType::TWritableContour CartoType::CContour CartoType::COnCurveContour

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
 

Detailed Description

Path objects, which are sequences of contours, must implement the MPath interface class.

Constructor & Destructor Documentation

◆ ~MPath()

virtual CartoType::MPath::~MPath ( )
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.

Member Function Documentation

◆ Area()

double CartoType::MPath::Area ( ) const

Returns the area of the path, ignoring curves (i.e., treating off-curve points as on-curve).

◆ begin()

ConstIter CartoType::MPath::begin ( ) const
inline

Returns a constant iterator positioned at the start of the contours.

◆ CBox()

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.

◆ CBoxBiggerThan()

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.

◆ CenterOfGravity()

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.

◆ Clip()

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.

◆ ClippedPath() [1/3]

COutline CartoType::MPath::ClippedPath ( const MPath aClip) const

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.

◆ ClippedPath() [2/3]

COutline CartoType::MPath::ClippedPath ( const TClipRegion aClip) const

Returns a version of the path clipped to the clip region aClip.

◆ ClippedPath() [3/3]

COutline CartoType::MPath::ClippedPath ( const TRect aClip) const

Returns a version of the path clipped to the axis-aligned rectangle aClip.

◆ ClipType()

TClipType CartoType::MPath::ClipType ( const TRect aRect) const

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.

◆ Contains() [1/3]

bool CartoType::MPath::Contains ( const TPoint aPoint) const
inline

Returns true if this path contains aPoint.

◆ Contains() [2/3]

bool CartoType::MPath::Contains ( const TPointFP aPoint) const
inline

Returns true if this path contains aPoint.

◆ Contains() [3/3]

bool CartoType::MPath::Contains ( double  aX,
double  aY 
) const

Returns true if this path contains the point (aX,aY).

◆ Contour()

virtual TContour CartoType::MPath::Contour ( size_t  aIndex) const
pure virtual

◆ Contours()

virtual size_t CartoType::MPath::Contours ( ) const
pure virtual

◆ Copy()

COutline CartoType::MPath::Copy ( ) const

Returns a copy of this path as a COutline object.

◆ DistanceFrom()

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).

◆ DistanceFromPoint()

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.

◆ End()

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.

◆ end()

ConstIter CartoType::MPath::end ( ) const
inline

Returns a constant iterator positioned at the end of the contours.

◆ Envelope()

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.

◆ FlatPath()

COutline CartoType::MPath::FlatPath ( double  aMaxDistance) const

Returns a flattened version of a path.

◆ GetCenterOfGravity()

void CartoType::MPath::GetCenterOfGravity ( TPoint aCenter) const

Return the center of gravity of a path, rounding to integer coordinates.

◆ GetHorizontalPaths()

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.

◆ GetSphericalAreaAndLength()

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.

◆ HasCurves()

bool CartoType::MPath::HasCurves ( ) const

Returns true if this path has any off-curve points.

◆ IntersectionInfo()

TPathIntersectionInfo CartoType::MPath::IntersectionInfo ( const MPath aOther) const

Returns information about the intersection of this path with another one.

◆ IntersectionType()

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).

◆ Intersects() [1/2]

bool CartoType::MPath::Intersects ( const MPath aPath,
const TRect aBounds = nullptr 
) const

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.

◆ Intersects() [2/2]

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.

◆ IsClippingNeeded()

bool CartoType::MPath::IsClippingNeeded ( const TRect aClip) const

Returns true if ClippedPath(aClip) would change the path.

◆ IsContainedIn()

bool CartoType::MPath::IsContainedIn ( const TRect aRect) const

Returns true if this path is contained by the rectangle aRect.

◆ IsEmpty()

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.

◆ IsGridOrientedRectangle()

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.

◆ IsPoint()

bool CartoType::MPath::IsPoint ( ) const

Returns true if the path is a single point, defined as a path of one contour with one point.

◆ IsSmoothingNeeded()

bool CartoType::MPath::IsSmoothingNeeded ( ) const

Returns true if SmoothPath would change the path.

◆ Length()

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).

◆ MaxDistanceFromOrigin()

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.

◆ MayHaveCurves()

virtual bool CartoType::MPath::MayHaveCurves ( ) const
pure virtual

◆ MayIntersect() [1/2]

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.

◆ MayIntersect() [2/2]

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.

◆ OffsetPath()

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.

◆ operator==()

bool CartoType::MPath::operator== ( const MPath aOther) const

The equality operator.

◆ PointAtLength()

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.

◆ SmoothPath()

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.

◆ TransformedPath() [1/2]

COutline CartoType::MPath::TransformedPath ( const TTransform aTransform) const

Creates a transformed path using the supplied transform.

◆ TransformedPath() [2/2]

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.

◆ Traverse() [1/2]

template<class MPathTraverser >
void CartoType::MPath::Traverse ( MPathTraverser &  aTraverser,
const TRect aClip 
) const
inline

Traverses this path, calling the functions defined by aTraverser to handle moves, lines, and curves. Clips the output to aClip.

◆ Traverse() [2/2]

template<class MPathTraverser >
void CartoType::MPath::Traverse ( MPathTraverser &  aTraverser,
const TRect aClip = nullptr 
) const
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.

◆ TruncatedPath()

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.

◆ Write()

void CartoType::MPath::Write ( TDataOutputStream aOutput) const

Write a path to a stream in serialized form.


The documentation for this class was generated from the following files: