CartoType C++ API 8.8-7-gb35e4dc71
for Windows, Linux, Qt and other platforms supporting C++ development
Classes | Public Member Functions | List of all members
CartoTypeCore::MPath Class Referenceabstract

#include <cartotype_path.h>

Inheritance diagram for CartoTypeCore::MPath:
CartoTypeCore::MContour CartoTypeCore::MapObject CartoTypeCore::Outline CartoTypeCore::ContourView CartoTypeCore::FixedSizeContour< aPointCount, aClosed > CartoTypeCore::MWritableContour CartoTypeCore::ContourBase< OutlinePoint > CartoTypeCore::ContourBase< Point > CartoTypeCore::ContourBase< T > CartoTypeCore::SimpleContourData CartoTypeCore::WritableContourView CartoTypeCore::Contour CartoTypeCore::OnCurveContour

Classes

class  ConstIter
 

Public Member Functions

virtual ~MPath ()
 
virtual size_t Contours () const =0
 
virtual ContourView ContourByIndex (size_t aIndex) const =0
 
virtual bool MayHaveCurves () const =0
 
template<class MPathTraverser >
void Traverse (MPathTraverser &aTraverser, const Rect &aClip) const
 
template<class MPathTraverser >
void Traverse (MPathTraverser &aTraverser, const Rect *aClip=nullptr) const
 
bool operator== (const MPath &aOther) const
 
Rect CBox () const
 
bool CBoxBiggerThan (int32_t aSize) const
 
bool IsContainedIn (const Rect &aRect) const
 
bool Contains (double aX, double aY) const
 
bool Contains (const Point &aPoint) const
 
bool Contains (const PointFP &aPoint) const
 
bool MayIntersect (const Rect &aRect) const
 
bool MayIntersect (const Rect &aRect, int32_t aBorder) const
 
bool Intersects (const Rect &aRect) const
 
bool Intersects (const MPath &aPath, const Rect *aBounds=nullptr) const
 
int32_t MaxDistanceFromOrigin () const
 
PathIntersectionType IntersectionType (const MPath &aOther, double *aDistance=nullptr, PointFP *aNearest1=nullptr, PointFP *aNearest2=nullptr) const
 
PathIntersectionInfo IntersectionInfo (const MPath &aOther) const
 
double DistanceFrom (const MPath &aOther, PointFP *aNearest1=nullptr, PointFP *aNearest2=nullptr, PathIntersectionType *aType=nullptr) const
 
double DistanceFromPoint (const PointFP &aPoint, PointFP *aNearest=nullptr, size_t *aContourIndex=nullptr, size_t *aLineIndex=nullptr, double *aFractionaLineIndex=nullptr, bool aTreatAsOpen=false) const
 
bool IsClippingNeeded (const Rect &aClip) const
 
Outline Copy () const
 
Outline ClippedPath (const Rect &aClip) const
 
Outline ClippedPath (const MPath &aClip) const
 
Outline ClippedPath (const ClipRegion &aClip) const
 
Outline Clip (ClipOperation aClipOperation, const MPath &aClip) const
 
Outline Envelope (double aOffset) const
 
Outline ConcaveHull (double aMaxEdgeLength, PolygonOrientation aAssumedOrientation=PolygonOrientation::None) const
 
bool IsSmoothingNeeded () const
 
Outline SmoothPath () const
 
Outline FlatPath (double aMaxDistance) const
 
Outline TruncatedPath (double aStart, double aEnd) const
 
Outline OffsetPath (double aOffset) const
 
Outline TransformedPath (const AffineTransform &aTransform) const
 
Outline TransformedPath (DrawResult &aError, MPointTransformer &aTransformer, int32_t aFractionalBits) const
 
Outline Interpolate (int32_t aGranularity) const
 
std::array< Line, 3 > HorizontalPaths (GraphicsContext *aGc, int32_t aPathLength, int32_t aLabelAscent, int32_t aLabelDescent, const PointFP &aUpVector, const Rect *aBounds, const Rect *aClip) const
 
PointFP CenterOfGravity () const
 
double Length () const
 
double Area () const
 
PointFP PointAtLength (double aPos) const
 
std::pair< Point, bool > End () const
 
void Write (OutputStream &aOutput) const
 
void WriteAsXml (OutputStream &aOutput) const
 
bool IsEmpty () const
 
bool IsPoint () const
 
bool IsGridOrientedRectangle (Rect *aRect=nullptr) const
 
void GetSphericalAreaAndLength (const Projection &aProjection, double *aArea, double *aLength) const
 
CartoTypeCore::ClipType ClipType (const Rect &aRect) const
 
bool HasCurves () const
 
size_t PointCount () 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 CartoTypeCore::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 CartoTypeCore::MPath::Area ( ) const

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

◆ begin()

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

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

◆ CBox()

Rect CartoTypeCore::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 CartoTypeCore::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()

PointFP CartoTypeCore::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()

Outline CartoTypeCore::MPath::Clip ( ClipOperation  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]

Outline CartoTypeCore::MPath::ClippedPath ( const ClipRegion aClip) const

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

◆ ClippedPath() [2/3]

Outline CartoTypeCore::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() [3/3]

Outline CartoTypeCore::MPath::ClippedPath ( const Rect aClip) const

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

◆ ClipType()

ClipType CartoTypeCore::MPath::ClipType ( const Rect 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.

◆ ConcaveHull()

Outline CartoTypeCore::MPath::ConcaveHull ( double  aMinEdgeLength,
PolygonOrientation  aAssumedOrientation = PolygonOrientation::None 
) const

Creates a concave hull for a closed path, with a maximum desired inserted edge length of aMaxEdgeLength. For any unclosed contour, returns the original path.

The assumed orientation can be set so that outer and inner paths are treated correctly. If, for example, it is set to anticlockwise, outer hulls are created for outer paths, and inner hulls for inner paths (holes).

◆ Contains() [1/3]

bool CartoTypeCore::MPath::Contains ( const Point aPoint) const
inline

Returns true if this path contains aPoint.

◆ Contains() [2/3]

bool CartoTypeCore::MPath::Contains ( const PointFP aPoint) const
inline

Returns true if this path contains aPoint.

◆ Contains() [3/3]

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

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

◆ ContourByIndex()

virtual ContourView CartoTypeCore::MPath::ContourByIndex ( size_t  aIndex) const
pure virtual

◆ Contours()

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

◆ Copy()

Outline CartoTypeCore::MPath::Copy ( ) const

Returns a copy of this path as an Outline object.

◆ DistanceFrom()

double CartoTypeCore::MPath::DistanceFrom ( const MPath aOther,
PointFP aNearest1 = nullptr,
PointFP aNearest2 = nullptr,
PathIntersectionType 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 CartoTypeCore::MPath::DistanceFromPoint ( const PointFP aPoint,
PointFP 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< Point, bool > CartoTypeCore::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 CartoTypeCore::MPath::end ( ) const
inline

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

◆ Envelope()

Outline CartoTypeCore::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 Outline::AppendCircularPenEnvelope by preference.

◆ FlatPath()

Outline CartoTypeCore::MPath::FlatPath ( double  aMaxDistance) const

Returns a flattened version of a path.

◆ GetSphericalAreaAndLength()

void CartoTypeCore::MPath::GetSphericalAreaAndLength ( const Projection &  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 CartoTypeCore::MPath::HasCurves ( ) const

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

◆ HorizontalPaths()

std::array< Line, 3 > CartoTypeCore::MPath::HorizontalPaths ( GraphicsContext aGc,
int32_t  aDesiredLength,
int32_t  aLabelAscent,
int32_t  aLabelDescent,
const PointFP aUpVector,
const Rect aBounds,
const Rect aClip 
) const

Returns up to three horizontal lines inside an outline, suitable for drawing a label.

aGc is the graphics context for the main map. aDesiredLength is the minimum required path length in 64ths of pixels. aLabelAscent and aLabelDescent are the ascent and descent of the label in pixels 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.

◆ Interpolate()

Outline CartoTypeCore::MPath::Interpolate ( int32_t  aGranularity) const

Creates a path, interpolating extra points so that the maximum difference between coordinates doesn't exceed aGranularity. Chooses the points to be interpolated using the coordinate modulo aGranularity, so that adjacent polygons have the same interpolated points and thus meet without gaps.

◆ IntersectionInfo()

PathIntersectionInfo CartoTypeCore::MPath::IntersectionInfo ( const MPath aOther) const

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

◆ IntersectionType()

PathIntersectionType CartoTypeCore::MPath::IntersectionType ( const MPath aOther,
double *  aDistance = nullptr,
PointFP aNearest1 = nullptr,
PointFP 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 PathIntersectionType::Separate, and sets the other return values to CT_DBL_MAX (the largest possible number).

◆ Intersects() [1/2]

bool CartoTypeCore::MPath::Intersects ( const MPath aPath,
const Rect 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 CartoTypeCore::MPath::Intersects ( const Rect 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 CartoTypeCore::MPath::IsClippingNeeded ( const Rect aClip) const

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

◆ IsContainedIn()

bool CartoTypeCore::MPath::IsContainedIn ( const Rect aRect) const

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

◆ IsEmpty()

bool CartoTypeCore::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 CartoTypeCore::MPath::IsGridOrientedRectangle ( Rect 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 CartoTypeCore::MPath::IsPoint ( ) const

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

◆ IsSmoothingNeeded()

bool CartoTypeCore::MPath::IsSmoothingNeeded ( ) const

Returns true if SmoothPath would change the path.

◆ Length()

double CartoTypeCore::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 CartoTypeCore::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 CartoTypeCore::MPath::MayHaveCurves ( ) const
pure virtual

◆ MayIntersect() [1/2]

bool CartoTypeCore::MPath::MayIntersect ( const Rect 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 CartoTypeCore::MPath::MayIntersect ( const Rect 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()

Outline CartoTypeCore::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 CartoTypeCore::MPath::operator== ( const MPath aOther) const

The equality operator.

◆ PointAtLength()

PointFP CartoTypeCore::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.

◆ PointCount()

size_t CartoTypeCore::MPath::PointCount ( ) const

Returns the total number of points in the path.

◆ SmoothPath()

Outline CartoTypeCore::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]

Outline CartoTypeCore::MPath::TransformedPath ( const AffineTransform aTransform) const

Creates a transformed path using the supplied transform.

◆ TransformedPath() [2/2]

Outline CartoTypeCore::MPath::TransformedPath ( DrawResult 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 CartoTypeCore::MPath::Traverse ( MPathTraverser &  aTraverser,
const Rect 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 CartoTypeCore::MPath::Traverse ( MPathTraverser &  aTraverser,
const Rect 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()

Outline CartoTypeCore::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 CartoTypeCore::MPath::Write ( OutputStream aOutput) const

Writes a path to a stream in serialized form.

◆ WriteAsXml()

void CartoTypeCore::MPath::WriteAsXml ( OutputStream aOutput) const

Writes this path to a stream as XML.

There is a single CartoTypePath element containing zero or more contour elements, each of which has a 'closed' attribute with the value 'yes' or 'no'. Each contour element has text made up from zero or more whitespace-separated points. A point is of the form X,Y{,T}: it must have X and Y parts and can have a T (point type) part. Point types are used if the point is off-curve.

All point coordinates apart from the first are stored as differences from the previous point.


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