Horizon
Macros | Functions
geometry_utils.h File Reference

a few functions useful in geometry calculations. More...

#include <math/vector2d.h>
#include <cmath>

Go to the source code of this file.

Macros

#define DOT_WIDTH_MILS   0.0254
 Dashed and dotted line patterns. More...
 
#define DOT_MARK_LEN(aLineWidth)    ( std::max( 1.0, IU_PER_MILS * DOT_WIDTH_MILS - aLineWidth ) )
 
#define DASH_GAP_LEN(aLineWidth)    ( 3.0 * DOT_MARK_LEN( aLineWidth ) + ( 2.0 * aLineWidth ) )
 
#define DASH_MARK_LEN(aLineWidth)    ( std::max( DASH_GAP_LEN( aLineWidth ), 5.0 * DOT_MARK_LEN( aLineWidth ) ) )
 

Functions

int GetArcToSegmentCount (int aRadius, int aErrorMax, double aArcAngleDegree)
 
double GetCircletoPolyCorrectionFactor (int aSegCountforCircle)
 
template<typename T >
VECTOR2< T > GetVectorSnapped45 (const VECTOR2< T > &aVec)
 Snap a vector onto the nearest 0, 45 or 90 degree line. More...
 

Detailed Description

a few functions useful in geometry calculations.

Macro Definition Documentation

◆ DOT_WIDTH_MILS

#define DOT_WIDTH_MILS   0.0254

Dashed and dotted line patterns.

Note: these are all macros because they're included from files with different IU definitions.

Function Documentation

◆ GetArcToSegmentCount()

int GetArcToSegmentCount ( int  aRadius,
int  aErrorMax,
double  aArcAngleDegree 
)
Returns
the number of segments to approximate a arc by segments with a given max error (this number is >= 1)
Parameters
aRadiusis the radius od the circle or arc
aErrorMaxis the max error This is the max distance between the middle of a segment and the circle.
aArcAngleDegreeis the arc angle in degrees

◆ GetCircletoPolyCorrectionFactor()

double GetCircletoPolyCorrectionFactor ( int  aSegCountforCircle)
Returns
the correction factor to approximate a circle by segments
Parameters
aSegCountforCircleis the number of segments to approximate the circle

When creating a polygon from a circle, the polygon is inside the circle. Only corners are on the circle. This is incorrect when building clearance areas of circles, that need to build the equivalent polygon outside the circle The correction factor is a scaling factor to apply to the radius to build a polygon outside the circle (only the middle of each segment is on the circle

◆ GetVectorSnapped45()

template<typename T >
VECTOR2<T> GetVectorSnapped45 ( const VECTOR2< T > &  aVec)

Snap a vector onto the nearest 0, 45 or 90 degree line.

The magnitude of the vector is NOT kept, instead the co-ordinates are set equal (and/or opposite) or to zero as needed. The effect of this is that if the starting vector is on a square grid, the resulting snapped vector will still be on the same grid.

Parameters
avector to be snapped
Returns
the snapped vector