Mapper  0.9.0
API documentation
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
OpenOrienteering::MapCoord Class Reference

Coordinates of a point in a map, with optional flags. More...

#include <map_coord.h>

Classes

struct  BoundsOffset
 Offset and flag for importing and moving out-of-bounds MapCoords. More...
 

Public Types

enum  Flag {
  CurveStart = 1 << 0, ClosePoint = 1 << 1, GapPoint = 1 << 2, HolePoint = 1 << 4,
  DashPoint = 1 << 5, MaskCopiedFlagsAtStart = GapPoint | DashPoint, MaskCopiedFlagsAtEnd = GapPoint | DashPoint | HolePoint | ClosePoint
}
 These flags provide extra information on each coordinate in a path. More...
 
template<class c >
using StringBuffer = std::array< c, 28 >
 A buffer that can hold a compact MapCoord string representation. More...
 

Public Member Functions

constexpr MapCoord () noexcept
 Creates a MapCoord with position at the origin and without any flags set. More...
 
constexpr MapCoord (const MapCoord &) noexcept=default
 Copy constructor. More...
 
constexpr MapCoord (int x, int y) noexcept
 Creates a MapCoord from a position given in millimeters on the map. More...
 
constexpr MapCoord (qreal x, qreal y) noexcept
 Creates a MapCoord from a position given in millimeters on the map. More...
 
constexpr MapCoord (qreal x, qreal y, Flags flags) noexcept
 Creates a MapCoord with the given flags from a position given in millimeters on the map. More...
 
constexpr MapCoord (qreal x, qreal y, Flag flag) noexcept
 Creates a MapCoord with the given flags from a position given in millimeters on the map. More...
 
 MapCoord (qreal x, qreal y, int flags)=delete
 
constexpr MapCoord (const QPointF &point) noexcept
 Creates a MapCoord with the position taken from a QPointF. More...
 
constexpr MapCoord (const QPointF &point, Flags flags) noexcept
 Creates a MapCoord with the given flags and with the position taken from a QPointF. More...
 
constexpr MapCoord (const QPointF &point, Flag flag) noexcept
 Creates a MapCoord with the given flags and with the position taken from a QPointF. More...
 
 MapCoord (QPointF point, int flags)=delete
 
MapCoordoperator= (const MapCoord &other)=default
 Assignment operator. More...
 
constexpr qreal x () const
 Returns the coord's x position in millimeters on the map. More...
 
constexpr qreal y () const
 Returns the coord's y position in millimeters on the map. More...
 
void setX (qreal x)
 Sets the coord's x position to a value in millimeters on the map. More...
 
void setY (qreal y)
 Sets the coord's y position to a value in millimeters on the map. More...
 
constexpr qint32 nativeX () const
 Returns the coord's x position in native map coords. More...
 
constexpr qint32 nativeY () const
 Returns the coord's y position in native map coords. More...
 
void setNativeX (qint32 new_x)
 Sets the coord's x position to a value in native map coords. More...
 
void setNativeY (qint32 new_y)
 Sets the coord's y position to a value in native map coords. More...
 
constexpr Flags::Int flags () const noexcept
 Returns the coord's flags separately, merged into the lowest 8 bits of an int. More...
 
void setFlags (Flags::Int flags) noexcept
 Sets the flags as retrieved by flags(). More...
 
bool isRegular () const
 Returns true iff the coordinates are within "regular" bounds. More...
 
qreal length () const
 Returns the length of this coord, seen as a vector from the origin to the given coordinate, in millimeters on the map. More...
 
constexpr qreal lengthSquared () const
 Returns the squared length of this coord, seen as a vector from the origin to the given coordinate, in millimeters on the map. More...
 
qreal distanceTo (const MapCoord &other) const
 Returns the distance from this coord to the other in millimeters on the map. More...
 
constexpr qreal distanceSquaredTo (const MapCoord &other) const
 Returns the squared distance from this coord to the other in millimeters on the map. More...
 
constexpr bool isPositionEqualTo (const MapCoord &other) const
 Returns if this coord's position is equal to that of the other one. More...
 
constexpr bool isCurveStart () const
 Is this point the first point of a cubic bezier curve segment? More...
 
void setCurveStart (bool value)
 Sets the curve start flag. More...
 
constexpr bool isClosePoint () const
 Is this the last point of a closed path, which is at the same position as the first point? This is set in addition to isHolePoint(). More...
 
void setClosePoint (bool value)
 Sets the close point flag. More...
 
constexpr bool isHolePoint () const
 Is this the start of a hole for a line? More...
 
void setHolePoint (bool value)
 Sets the hole point flag. More...
 
constexpr bool isDashPoint () const
 Is this coordinate a special dash point? More...
 
void setDashPoint (bool value)
 Sets the dash point flag. More...
 
constexpr bool isGapPoint () const
 Is this coordinate a gap point? More...
 
void setGapPoint (bool value)
 Sets the gap point flag. More...
 
constexpr MapCoord operator- () const
 Additive inverse. More...
 
MapCoordoperator+= (const MapCoord &rhs_vector)
 Component-wise addition. More...
 
MapCoordoperator+= (const QPointF &rhs_vector)
 Component-wise addition of this and a MapCoordF/QPointF. More...
 
MapCoordoperator-= (const MapCoord &rhs_vector)
 Component-wise subtraction. More...
 
MapCoordoperator-= (const QPointF &rhs_vector)
 Component-wise subtraction of this and a MapCoordF/QPointF. More...
 
MapCoordoperator*= (qreal factor)
 Multiply with scalar factor. More...
 
MapCoordoperator/= (qreal scalar)
 Divide by scalar factor. More...
 
constexpr operator QPointF () const
 Converts the coord's position to a QPointF. More...
 
QString toString () const
 Writes raw coordinates and flags to a string. More...
 
QString toString (StringBuffer< QChar > &buffer) const
 Returns a string for the raw coordinates and flags, using the given buffer. More...
 
QByteArray toUtf8 (StringBuffer< char > &buffer) const
 Returns an UTF-8 string for the raw coordinates and flags, using the given buffer. More...
 
 MapCoord (QStringRef &text)
 Constructs the MapCoord from the beginning of text, and moves the reference to behind the this coordinates data. More...
 
void save (QXmlStreamWriter &xml) const
 Saves the MapCoord in xml format to the stream. More...
 

Static Public Member Functions

static BoundsOffsetboundsOffset ()
 Returns the global bounds offset. More...
 
static constexpr MapCoord fromNative (qint32 x, qint32 y) noexcept
 Creates a MapCoord from native map coordinates. More...
 
static constexpr MapCoord fromNative (qint32 x, qint32 y, Flags flags) noexcept
 Creates a MapCoord from native map coordinates. More...
 
static constexpr MapCoord fromNative (qint32 x, qint32 y, Flag flag) noexcept
 Creates a MapCoord from native map coordinates. More...
 
static MapCoord fromNative (qint32 x, qint32 y, int flags)=delete
 
static MapCoord fromNative (qint64 x, qint64 y)=delete
 It is illegal to call MapCoord::fromNative with qint64 arguments. More...
 
static MapCoord fromNative64 (qint64 x, qint64 y)
 Creates a MapCoord from native map coordinates. More...
 
static MapCoord fromNative64withOffset (qint64 x, qint64 y)
 Creates a MapCoord from native map coordinates. More...
 
static MapCoord load (QXmlStreamReader &xml)
 Loads the MapCoord in xml format from the stream. More...
 
static MapCoord load (qreal x, qreal y, MapCoord::Flags flags)
 Creates a MapCoord from map coordinates in millimeters, with offset handling. More...
 
static MapCoord load (qreal x, qreal y, int flags)=delete
 
static MapCoord load (const QPointF &p, MapCoord::Flags flags)
 Creates a MapCoord from map coordinates in millimeters, with offset handling. More...
 
static MapCoord load (const QPointF &p, int flags)=delete
 

Friends

class CoordXmlTest
 Benchmark. More...
 
constexpr bool operator== (const MapCoord &lhs, const MapCoord &rhs)
 Compare MapCoord for equality. More...
 
constexpr MapCoord operator+ (const MapCoord &lhs, const MapCoord &rhs)
 Component-wise addition of MapCoord. More...
 
constexpr MapCoord operator+ (const MapCoord &lhs, const QPointF &rhs)
 Component-wise addition of MapCoord and MapCoordF/QPointF. More...
 
constexpr MapCoord operator- (const MapCoord &lhs, const MapCoord &rhs)
 Component-wise subtraction of MapCoord. More...
 
constexpr MapCoord operator- (const MapCoord &lhs, const QPointF &rhs)
 Component-wise subtraction of MapCoord and MapCoordF/QPointF. More...
 
constexpr MapCoord operator* (const MapCoord &lhs, qreal factor)
 Multiply MapCoord with scalar factor. More...
 
constexpr MapCoord operator* (qreal factor, const MapCoord &rhs)
 Multiply MapCoord with scalar factor. More...
 
constexpr MapCoord operator/ (const MapCoord &lhs, qreal divisor)
 Divide MapCoord by scalar factor. More...
 

Detailed Description

Coordinates of a point in a map, with optional flags.

This coordinate uses what we call native map coordinates. One unit in native map coordinates is 1/1000th of a millimeter on the map paper.

The possible flags are:

These coordinates are implemented as 32 bit integers, the flags are store separately.

Member Typedef Documentation

◆ StringBuffer

template<class c >
using OpenOrienteering::MapCoord::StringBuffer = std::array<c, 28>

A buffer that can hold a compact MapCoord string representation.

The buffer size must allow for 1x ';': 1 2x '-': 2 2x ' ': 2 2x the decimal digits for values up to 0..2^31: 20 1x the decimal digits for 0..2^8-1: 3 Total: 28

Member Enumeration Documentation

◆ Flag

These flags provide extra information on each coordinate in a path.

Don't change the values, they are used in import/export.

Enumerator
CurveStart 
ClosePoint 
GapPoint 
HolePoint 
DashPoint 
MaskCopiedFlagsAtStart 
MaskCopiedFlagsAtEnd 

Constructor & Destructor Documentation

◆ MapCoord() [1/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( )
noexcept

Creates a MapCoord with position at the origin and without any flags set.

◆ MapCoord() [2/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( const MapCoord )
defaultnoexcept

Copy constructor.

◆ MapCoord() [3/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( int  x,
int  y 
)
noexcept

Creates a MapCoord from a position given in millimeters on the map.

This is a convenience constructor for efficient construction of a point at the origin i.e. MapCoord(0, 0), or for simple vectors i.e. MapCoord(1, 0). Intentionally, there is no public version with flags - you need to use other argument types than int if the compiler complains about ambiguity.

◆ MapCoord() [4/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( qreal  x,
qreal  y 
)
noexcept

Creates a MapCoord from a position given in millimeters on the map.

◆ MapCoord() [5/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( qreal  x,
qreal  y,
Flags  flags 
)
noexcept

Creates a MapCoord with the given flags from a position given in millimeters on the map.

◆ MapCoord() [6/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( qreal  x,
qreal  y,
Flag  flag 
)
noexcept

Creates a MapCoord with the given flags from a position given in millimeters on the map.

◆ MapCoord() [7/12]

OpenOrienteering::MapCoord::MapCoord ( qreal  x,
qreal  y,
int  flags 
)
delete

◆ MapCoord() [8/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( const QPointF point)
explicitnoexcept

Creates a MapCoord with the position taken from a QPointF.

◆ MapCoord() [9/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( const QPointF point,
Flags  flags 
)
noexcept

Creates a MapCoord with the given flags and with the position taken from a QPointF.

◆ MapCoord() [10/12]

constexpr OpenOrienteering::MapCoord::MapCoord ( const QPointF point,
Flag  flag 
)
noexcept

Creates a MapCoord with the given flags and with the position taken from a QPointF.

◆ MapCoord() [11/12]

OpenOrienteering::MapCoord::MapCoord ( QPointF  point,
int  flags 
)
delete

◆ MapCoord() [12/12]

OpenOrienteering::MapCoord::MapCoord ( QStringRef text)

Constructs the MapCoord from the beginning of text, and moves the reference to behind the this coordinates data.

This is the counterpiece to toString(). It will throw a std::invalid_argument if the (beginning of) text does not contain valid data.

This constructor will initialize the boundsOffset() if necessary. Otherwise it will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32.

Member Function Documentation

◆ boundsOffset()

MapCoord::BoundsOffset & OpenOrienteering::MapCoord::boundsOffset ( )
static

Returns the global bounds offset.

It is returned as a non-const reference, so that it can be used in QScopedValueRollack.

◆ distanceSquaredTo()

constexpr qreal OpenOrienteering::MapCoord::distanceSquaredTo ( const MapCoord other) const

Returns the squared distance from this coord to the other in millimeters on the map.

Faster than lengthTo().

◆ distanceTo()

qreal OpenOrienteering::MapCoord::distanceTo ( const MapCoord other) const
inline

Returns the distance from this coord to the other in millimeters on the map.

◆ flags()

constexpr MapCoord::Flags::Int OpenOrienteering::MapCoord::flags ( ) const
noexcept

Returns the coord's flags separately, merged into the lowest 8 bits of an int.

◆ fromNative() [1/5]

constexpr MapCoord OpenOrienteering::MapCoord::fromNative ( qint32  x,
qint32  y 
)
staticnoexcept

Creates a MapCoord from native map coordinates.

◆ fromNative() [2/5]

constexpr MapCoord OpenOrienteering::MapCoord::fromNative ( qint32  x,
qint32  y,
Flags  flags 
)
staticnoexcept

Creates a MapCoord from native map coordinates.

◆ fromNative() [3/5]

constexpr MapCoord OpenOrienteering::MapCoord::fromNative ( qint32  x,
qint32  y,
Flag  flag 
)
staticnoexcept

Creates a MapCoord from native map coordinates.

◆ fromNative() [4/5]

static MapCoord OpenOrienteering::MapCoord::fromNative ( qint32  x,
qint32  y,
int  flags 
)
staticdelete

◆ fromNative() [5/5]

static MapCoord OpenOrienteering::MapCoord::fromNative ( qint64  x,
qint64  y 
)
staticdelete

It is illegal to call MapCoord::fromNative with qint64 arguments.

Use fromNative64 instead. That method tests the values against the bounds of qint32.

◆ fromNative64()

MapCoord OpenOrienteering::MapCoord::fromNative64 ( qint64  x,
qint64  y 
)
static

Creates a MapCoord from native map coordinates.

The coordinates are expected to be in the bounds of qint32.

Todo:
Raise (and handle exceptions) when out of bounds.

◆ fromNative64withOffset()

MapCoord OpenOrienteering::MapCoord::fromNative64withOffset ( qint64  x,
qint64  y 
)
static

Creates a MapCoord from native map coordinates.

This will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32. It does not modify BoundsOffset()!

◆ isClosePoint()

constexpr bool OpenOrienteering::MapCoord::isClosePoint ( ) const

Is this the last point of a closed path, which is at the same position as the first point? This is set in addition to isHolePoint().

◆ isCurveStart()

constexpr bool OpenOrienteering::MapCoord::isCurveStart ( ) const

Is this point the first point of a cubic bezier curve segment?

◆ isDashPoint()

constexpr bool OpenOrienteering::MapCoord::isDashPoint ( ) const

Is this coordinate a special dash point?

◆ isGapPoint()

constexpr bool OpenOrienteering::MapCoord::isGapPoint ( ) const

Is this coordinate a gap point?

◆ isHolePoint()

constexpr bool OpenOrienteering::MapCoord::isHolePoint ( ) const

Is this the start of a hole for a line?

◆ isPositionEqualTo()

constexpr bool OpenOrienteering::MapCoord::isPositionEqualTo ( const MapCoord other) const

Returns if this coord's position is equal to that of the other one.

◆ isRegular()

bool OpenOrienteering::MapCoord::isRegular ( ) const

Returns true iff the coordinates are within "regular" bounds.

◆ length()

qreal OpenOrienteering::MapCoord::length ( ) const
inline

Returns the length of this coord, seen as a vector from the origin to the given coordinate, in millimeters on the map.

◆ lengthSquared()

constexpr qreal OpenOrienteering::MapCoord::lengthSquared ( ) const

Returns the squared length of this coord, seen as a vector from the origin to the given coordinate, in millimeters on the map.

Faster than length().

◆ load() [1/5]

MapCoord OpenOrienteering::MapCoord::load ( QXmlStreamReader xml)
static

Loads the MapCoord in xml format from the stream.

This will initialize the boundsOffset() if necessary. Otherwise it will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32.

◆ load() [2/5]

static MapCoord OpenOrienteering::MapCoord::load ( qreal  x,
qreal  y,
MapCoord::Flags  flags 
)
static

Creates a MapCoord from map coordinates in millimeters, with offset handling.

This will initialize the boundsOffset() if necessary. Otherwise it will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32.

◆ load() [3/5]

static MapCoord OpenOrienteering::MapCoord::load ( qreal  x,
qreal  y,
int  flags 
)
staticdelete

◆ load() [4/5]

MapCoord OpenOrienteering::MapCoord::load ( const QPointF p,
MapCoord::Flags  flags 
)
static

Creates a MapCoord from map coordinates in millimeters, with offset handling.

This will initialize the boundsOffset() if necessary. Otherwise it will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32.

◆ load() [5/5]

static MapCoord OpenOrienteering::MapCoord::load ( const QPointF p,
int  flags 
)
staticdelete

◆ nativeX()

constexpr qint32 OpenOrienteering::MapCoord::nativeX ( ) const

Returns the coord's x position in native map coords.

◆ nativeY()

constexpr qint32 OpenOrienteering::MapCoord::nativeY ( ) const

Returns the coord's y position in native map coords.

◆ operator QPointF()

constexpr OpenOrienteering::MapCoord::operator QPointF ( ) const
explicit

Converts the coord's position to a QPointF.

◆ operator*=()

MapCoord & OpenOrienteering::MapCoord::operator*= ( qreal  factor)
inline

Multiply with scalar factor.

◆ operator+=() [1/2]

MapCoord & OpenOrienteering::MapCoord::operator+= ( const MapCoord rhs_vector)
inline

Component-wise addition.

◆ operator+=() [2/2]

MapCoord & OpenOrienteering::MapCoord::operator+= ( const QPointF rhs_vector)
inline

Component-wise addition of this and a MapCoordF/QPointF.

◆ operator-()

constexpr MapCoord OpenOrienteering::MapCoord::operator- ( ) const

Additive inverse.

◆ operator-=() [1/2]

MapCoord & OpenOrienteering::MapCoord::operator-= ( const MapCoord rhs_vector)
inline

Component-wise subtraction.

◆ operator-=() [2/2]

MapCoord & OpenOrienteering::MapCoord::operator-= ( const QPointF rhs_vector)
inline

Component-wise subtraction of this and a MapCoordF/QPointF.

◆ operator/=()

MapCoord & OpenOrienteering::MapCoord::operator/= ( qreal  scalar)
inline

Divide by scalar factor.

◆ operator=()

MapCoord& OpenOrienteering::MapCoord::operator= ( const MapCoord other)
default

Assignment operator.

◆ save()

void OpenOrienteering::MapCoord::save ( QXmlStreamWriter xml) const

Saves the MapCoord in xml format to the stream.

◆ setClosePoint()

void OpenOrienteering::MapCoord::setClosePoint ( bool  value)
inline

Sets the close point flag.

◆ setCurveStart()

void OpenOrienteering::MapCoord::setCurveStart ( bool  value)
inline

Sets the curve start flag.

◆ setDashPoint()

void OpenOrienteering::MapCoord::setDashPoint ( bool  value)
inline

Sets the dash point flag.

◆ setFlags()

void OpenOrienteering::MapCoord::setFlags ( Flags::Int  flags)
inlinenoexcept

Sets the flags as retrieved by flags().

◆ setGapPoint()

void OpenOrienteering::MapCoord::setGapPoint ( bool  value)
inline

Sets the gap point flag.

◆ setHolePoint()

void OpenOrienteering::MapCoord::setHolePoint ( bool  value)
inline

Sets the hole point flag.

◆ setNativeX()

void OpenOrienteering::MapCoord::setNativeX ( qint32  new_x)
inline

Sets the coord's x position to a value in native map coords.

◆ setNativeY()

void OpenOrienteering::MapCoord::setNativeY ( qint32  new_y)
inline

Sets the coord's y position to a value in native map coords.

◆ setX()

void OpenOrienteering::MapCoord::setX ( qreal  x)
inline

Sets the coord's x position to a value in millimeters on the map.

◆ setY()

void OpenOrienteering::MapCoord::setY ( qreal  y)
inline

Sets the coord's y position to a value in millimeters on the map.

◆ toString() [1/2]

QString OpenOrienteering::MapCoord::toString ( ) const

Writes raw coordinates and flags to a string.

◆ toString() [2/2]

QString OpenOrienteering::MapCoord::toString ( MapCoord::StringBuffer< QChar > &  buffer) const

Returns a string for the raw coordinates and flags, using the given buffer.

The string is created using QString::fromRawData(), so it is valid for the lifetime of the buffer only.

◆ toUtf8()

QByteArray OpenOrienteering::MapCoord::toUtf8 ( MapCoord::StringBuffer< char > &  buffer) const

Returns an UTF-8 string for the raw coordinates and flags, using the given buffer.

The string is created using QByteArray::fromRawData(), so it is valid for the lifetime of the buffer only.

◆ x()

constexpr qreal OpenOrienteering::MapCoord::x ( ) const

Returns the coord's x position in millimeters on the map.

◆ y()

constexpr qreal OpenOrienteering::MapCoord::y ( ) const

Returns the coord's y position in millimeters on the map.

Friends And Related Function Documentation

◆ CoordXmlTest

friend class CoordXmlTest
friend

Benchmark.

◆ operator* [1/2]

constexpr MapCoord operator* ( const MapCoord lhs,
qreal  factor 
)
friend

Multiply MapCoord with scalar factor.

◆ operator* [2/2]

constexpr MapCoord operator* ( qreal  factor,
const MapCoord rhs 
)
friend

Multiply MapCoord with scalar factor.

◆ operator+ [1/2]

constexpr MapCoord operator+ ( const MapCoord lhs,
const MapCoord rhs 
)
friend

Component-wise addition of MapCoord.

◆ operator+ [2/2]

constexpr MapCoord operator+ ( const MapCoord lhs,
const QPointF rhs 
)
friend

Component-wise addition of MapCoord and MapCoordF/QPointF.

◆ operator- [1/2]

constexpr MapCoord operator- ( const MapCoord lhs,
const MapCoord rhs 
)
friend

Component-wise subtraction of MapCoord.

◆ operator- [2/2]

constexpr MapCoord operator- ( const MapCoord lhs,
const QPointF rhs 
)
friend

Component-wise subtraction of MapCoord and MapCoordF/QPointF.

◆ operator/

constexpr MapCoord operator/ ( const MapCoord lhs,
qreal  divisor 
)
friend

Divide MapCoord by scalar factor.

◆ operator==

constexpr bool operator== ( const MapCoord lhs,
const MapCoord rhs 
)
friend

Compare MapCoord for equality.


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