KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
FlatGeo Class Reference

Static helper methods for 2D (flat / Cartesian) geometric computations. More...

#include <flatgeo.h>

Static Public Member Functions

static double vectorAngle (const Line &l1, const Line &l2)
 Compute the signed vector angle between two lines.
 
static Angle angle (const Line &l1, const Line &l2)
 Compute the angle between two lines as an Angle object.
 
static Angle angle (const QPointF &p1, const QPointF &vertex, const QPointF &p2)
 Compute the angle at a vertex formed by two rays.
 
static double distance (const QPointF &p1, const QPointF &p2)
 Compute the Euclidean distance between two points.
 
static double degrees (double angle)
 Convert radians to degrees.
 
static double radians (double angle)
 Convert degrees to radians.
 
static double angularDifference (const Line &l1, const Line &l2)
 Compute the absolute angular difference between two lines.
 
static Point getPoint (const QPointF &from, double bearing, double distance)
 Compute a point at a given bearing and distance from a source point.
 
static QPointF intersection (const Line &l1, const Line &l2)
 Compute the intersection point of two lines.
 
static bool isInCircle (const QPointF &point, const Circle &circle)
 Test whether a point lies within a circle.
 
static void getLineABC (const Line &line, double &a, double &b, double &c)
 Compute the A, B, C coefficients of the line equation Ax + By + C = 0.
 
static QPointF move (const QPointF &point, double bearing, double distance)
 Move a point by a given bearing and distance.
 
static QPointF rotate (const QPointF &point, const QPointF &centroid, double angle)
 Rotate a point around a centroid by an angle.
 
static bool arePointsEqual (const QPointF &p1, const QPointF &p2, int precision=0)
 Test whether two points are equal within a given precision.
 
static bool isPointLeftOf (const QPointF &point, const QPointF &other)
 Test whether point is to the left of other (smaller X).
 
static bool isPointRightOf (const QPointF &point, const QPointF &other)
 Test whether point is to the right of other (larger X).
 
static bool isPointAbove (const QPointF &point, const QPointF &other)
 Test whether point is above other (smaller Y).
 
static bool isPointBelow (const QPointF &point, const QPointF &other)
 Test whether point is below other (larger Y).
 
static bool isRectLeftOf (const QRectF &rect, const QPointF &other)
 Test whether rect's right edge is left of other.
 
static bool isRectRightOf (const QRectF &rect, const QPointF &other)
 Test whether rect's left edge is right of other.
 
static bool isRectAbove (const QRectF &rect, const QPointF &other)
 Test whether rect's bottom edge is above other.
 
static bool isRectBelow (const QRectF &rect, const QPointF &other)
 Test whether rect's top edge is below other.
 
static bool isRectLeftOf (const QRectF &rect, const QRectF &other)
 Test whether other is to the left of rect.
 
static bool isRectRightOf (const QRectF &rect, const QRectF &other)
 Test whether other is to the right of rect.
 
static bool isRectAbove (const QRectF &rect, const QRectF &other)
 Test whether other is above rect.
 
static bool isRectBelow (const QRectF &rect, const QRectF &other)
 Test whether other is below rect.
 
static Geo::SpatialRelationship relationTo (const QPointF &origin, const QPointF &other)
 Determine the spatial relationship of a point relative to an origin point.
 
static Geo::SpatialRelationship relationTo (const QRectF &origin, const QPointF &other)
 Determine the spatial relationship of a point relative to a rectangle.
 
static Geo::SpatialRelationship relationTo (const QPointF &origin, const QRectF &other)
 Determine the spatial relationship of a rectangle relative to an origin point.
 
static Geo::SpatialRelationship relationTo (const QRectF &origin, const QRectF &other)
 Determine the spatial relationship between two rectangles.
 
static QString makePointString (const QPoint &p)
 Format an integer point as a comma-separated string.
 
static QString makePointString (const QPointF &p)
 Format a floating-point point as a comma-separated string.
 

Static Public Attributes

static const int Precision = 6
 Number of decimal places used for rounding in geometric comparisons.
 

Detailed Description

Static helper methods for 2D (flat / Cartesian) geometric computations.

All coordinates use Qt's screen coordinate system where Y increases downward. Angles are in degrees unless otherwise specified.

Definition at line 22 of file flatgeo.h.

Member Function Documentation

◆ angle() [1/2]

static Angle FlatGeo::angle ( const Line l1,
const Line l2 
)
static

Compute the angle between two lines as an Angle object.

Parameters
l1First line
l2Second line
Returns
Angle between the lines

◆ angle() [2/2]

static Angle FlatGeo::angle ( const QPointF &  p1,
const QPointF &  vertex,
const QPointF &  p2 
)
static

Compute the angle at a vertex formed by two rays.

Parameters
p1First point on the first ray
vertexVertex of the angle
p2First point on the second ray
Returns
Angle at the vertex

◆ angularDifference()

static double FlatGeo::angularDifference ( const Line l1,
const Line l2 
)
static

Compute the absolute angular difference between two lines.

Parameters
l1First line
l2Second line
Returns
Absolute angular difference in degrees

◆ arePointsEqual()

static bool FlatGeo::arePointsEqual ( const QPointF &  p1,
const QPointF &  p2,
int  precision = 0 
)
static

Test whether two points are equal within a given precision.

Parameters
p1First point
p2Second point
precisionNumber of decimal places to compare (0 = integer precision)
Returns
true if the points are equal within the specified precision

◆ degrees()

static double FlatGeo::degrees ( double  angle)
static

Convert radians to degrees.

Parameters
angleAngle in radians
Returns
Equivalent angle in degrees

◆ distance()

static double FlatGeo::distance ( const QPointF &  p1,
const QPointF &  p2 
)
static

Compute the Euclidean distance between two points.

Parameters
p1First point
p2Second point
Returns
Distance in scene units

◆ getLineABC()

static void FlatGeo::getLineABC ( const Line line,
double &  a,
double &  b,
double &  c 
)
static

Compute the A, B, C coefficients of the line equation Ax + By + C = 0.

Parameters
lineInput line
aOutput coefficient A
bOutput coefficient B
cOutput coefficient C

◆ getPoint()

static Point FlatGeo::getPoint ( const QPointF &  from,
double  bearing,
double  distance 
)
static

Compute a point at a given bearing and distance from a source point.

Parameters
fromOrigin point
bearingCompass bearing in degrees (0 = up/north)
distanceDistance from origin
Returns
Resulting Point

◆ intersection()

static QPointF FlatGeo::intersection ( const Line l1,
const Line l2 
)
static

Compute the intersection point of two lines.

Parameters
l1First line
l2Second line
Returns
Intersection point, or an undefined point if lines are parallel

◆ isInCircle()

static bool FlatGeo::isInCircle ( const QPointF &  point,
const Circle circle 
)
static

Test whether a point lies within a circle.

Parameters
pointPoint to test
circleCircle to test against
Returns
true if the point is inside or on the circle boundary

◆ isPointAbove()

static bool FlatGeo::isPointAbove ( const QPointF &  point,
const QPointF &  other 
)
inlinestatic

Test whether point is above other (smaller Y).

Parameters
pointPoint to test.
otherReference point.
Returns
True if point.y < other.y.

Definition at line 161 of file flatgeo.h.

◆ isPointBelow()

static bool FlatGeo::isPointBelow ( const QPointF &  point,
const QPointF &  other 
)
inlinestatic

Test whether point is below other (larger Y).

Parameters
pointPoint to test.
otherReference point.
Returns
True if point.y > other.y.

Definition at line 169 of file flatgeo.h.

◆ isPointLeftOf()

static bool FlatGeo::isPointLeftOf ( const QPointF &  point,
const QPointF &  other 
)
inlinestatic

Test whether point is to the left of other (smaller X).

Parameters
pointPoint to test.
otherReference point.
Returns
True if point.x < other.x.

Definition at line 145 of file flatgeo.h.

◆ isPointRightOf()

static bool FlatGeo::isPointRightOf ( const QPointF &  point,
const QPointF &  other 
)
inlinestatic

Test whether point is to the right of other (larger X).

Parameters
pointPoint to test.
otherReference point.
Returns
True if point.x > other.x.

Definition at line 153 of file flatgeo.h.

◆ isRectAbove() [1/2]

static bool FlatGeo::isRectAbove ( const QRectF &  rect,
const QPointF &  other 
)
inlinestatic

Test whether rect's bottom edge is above other.

Parameters
rectRectangle to test.
otherReference point.
Returns
True if rect's bottom < other.y.

Definition at line 193 of file flatgeo.h.

◆ isRectAbove() [2/2]

static bool FlatGeo::isRectAbove ( const QRectF &  rect,
const QRectF &  other 
)
inlinestatic

Test whether other is above rect.

Parameters
rectReference rectangle
otherRectangle to compare
Returns
true if other.y < rect.y

Definition at line 225 of file flatgeo.h.

◆ isRectBelow() [1/2]

static bool FlatGeo::isRectBelow ( const QRectF &  rect,
const QPointF &  other 
)
inlinestatic

Test whether rect's top edge is below other.

Parameters
rectRectangle to test.
otherReference point.
Returns
True if rect.y > other.y.

Definition at line 201 of file flatgeo.h.

◆ isRectBelow() [2/2]

static bool FlatGeo::isRectBelow ( const QRectF &  rect,
const QRectF &  other 
)
inlinestatic

Test whether other is below rect.

Parameters
rectReference rectangle
otherRectangle to compare
Returns
true if other.y > rect's bottom edge

Definition at line 233 of file flatgeo.h.

◆ isRectLeftOf() [1/2]

static bool FlatGeo::isRectLeftOf ( const QRectF &  rect,
const QPointF &  other 
)
inlinestatic

Test whether rect's right edge is left of other.

Parameters
rectRectangle to test.
otherReference point.
Returns
True if rect's right edge < other.x.

Definition at line 177 of file flatgeo.h.

◆ isRectLeftOf() [2/2]

static bool FlatGeo::isRectLeftOf ( const QRectF &  rect,
const QRectF &  other 
)
inlinestatic

Test whether other is to the left of rect.

Parameters
rectReference rectangle
otherRectangle to compare
Returns
true if other.x < rect.x

Definition at line 209 of file flatgeo.h.

◆ isRectRightOf() [1/2]

static bool FlatGeo::isRectRightOf ( const QRectF &  rect,
const QPointF &  other 
)
inlinestatic

Test whether rect's left edge is right of other.

Parameters
rectRectangle to test.
otherReference point.
Returns
True if rect.x > other.x.

Definition at line 185 of file flatgeo.h.

◆ isRectRightOf() [2/2]

static bool FlatGeo::isRectRightOf ( const QRectF &  rect,
const QRectF &  other 
)
inlinestatic

Test whether other is to the right of rect.

Parameters
rectReference rectangle
otherRectangle to compare
Returns
true if other.x > rect's right edge

Definition at line 217 of file flatgeo.h.

◆ makePointString() [1/2]

static QString FlatGeo::makePointString ( const QPoint &  p)
static

Format an integer point as a comma-separated string.

Parameters
pPoint to format
Returns
String of the form "x, y"

◆ makePointString() [2/2]

static QString FlatGeo::makePointString ( const QPointF &  p)
static

Format a floating-point point as a comma-separated string.

Parameters
pPoint to format
Returns
String of the form "x, y"

◆ move()

static QPointF FlatGeo::move ( const QPointF &  point,
double  bearing,
double  distance 
)
static

Move a point by a given bearing and distance.

Parameters
pointStarting point
bearingDirection of movement in degrees
distanceDistance to move
Returns
New QPointF after movement

◆ radians()

static double FlatGeo::radians ( double  angle)
static

Convert degrees to radians.

Parameters
angleAngle in degrees
Returns
Equivalent angle in radians

◆ relationTo() [1/4]

static Geo::SpatialRelationship FlatGeo::relationTo ( const QPointF &  origin,
const QPointF &  other 
)
static

Determine the spatial relationship of a point relative to an origin point.

Parameters
originReference point
otherPoint to compare
Returns
SpatialRelationship flags describing the relative position

◆ relationTo() [2/4]

static Geo::SpatialRelationship FlatGeo::relationTo ( const QPointF &  origin,
const QRectF &  other 
)
static

Determine the spatial relationship of a rectangle relative to an origin point.

Parameters
originReference point
otherRectangle to compare
Returns
SpatialRelationship flags describing the relative position

◆ relationTo() [3/4]

static Geo::SpatialRelationship FlatGeo::relationTo ( const QRectF &  origin,
const QPointF &  other 
)
static

Determine the spatial relationship of a point relative to a rectangle.

Parameters
originReference rectangle
otherPoint to compare
Returns
SpatialRelationship flags describing the relative position

◆ relationTo() [4/4]

static Geo::SpatialRelationship FlatGeo::relationTo ( const QRectF &  origin,
const QRectF &  other 
)
static

Determine the spatial relationship between two rectangles.

Parameters
originReference rectangle
otherRectangle to compare
Returns
SpatialRelationship flags describing the relative position

◆ rotate()

static QPointF FlatGeo::rotate ( const QPointF &  point,
const QPointF &  centroid,
double  angle 
)
static

Rotate a point around a centroid by an angle.

Parameters
pointPoint to rotate
centroidCentre of rotation
angleRotation angle in degrees (clockwise)
Returns
Rotated QPointF

◆ vectorAngle()

static double FlatGeo::vectorAngle ( const Line l1,
const Line l2 
)
static

Compute the signed vector angle between two lines.

Parameters
l1First line
l2Second line
Returns
Signed angle in degrees

Member Data Documentation

◆ Precision

const int FlatGeo::Precision = 6
static

Number of decimal places used for rounding in geometric comparisons.

Definition at line 285 of file flatgeo.h.


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