KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
geo.h
1/**
2 * @brief Geometry enumerations and utility functions for sides, directions, and spatial relationships.
3 */
4#ifndef GEO_H
5#define GEO_H
6
7#include <QList>
8#include "Kanoop/kanoopcommon.h"
9
10/**
11 * @brief Geometry namespace providing enumerations and free functions for spatial reasoning.
12 */
13namespace Geo {
14
15/**
16 * @brief Bitmask identifying which side(s) of a rectangle are relevant.
17 */
18enum Side
19{
20 NoSide = 0x0000, ///< No side
21 Top = 0x0001, ///< Top edge
22 Left = 0x0002, ///< Left edge
23 Bottom = 0x0004, ///< Bottom edge
24 Right = 0x0008, ///< Right edge
25 TopLeftCorner = 0x0010, ///< Top-left corner
26 TopRightCorner = 0x0020, ///< Top-right corner
27 BottomLeftCorner = 0x0040, ///< Bottom-left corner
28 BottomRightCorner = 0x0080, ///< Bottom-right corner
29};
30Q_DECLARE_FLAGS(Sides, Side)
31Q_DECLARE_OPERATORS_FOR_FLAGS(Sides)
32
33/**
34 * @brief Cardinal directions, aliased to the corresponding Side values.
35 */
37{
38 NoDirection = NoSide, ///< No direction
39 Up = Top, ///< Upward (toward smaller Y)
40 Down = Bottom, ///< Downward (toward larger Y)
41 ToLeft = Left, ///< Leftward (toward smaller X)
42 ToRight = Right ///< Rightward (toward larger X)
43};
44Q_DECLARE_FLAGS(Directions, Direction)
45Q_DECLARE_OPERATORS_FOR_FLAGS(Directions)
46
47/**
48 * @brief Spatial relationship between two geometric objects.
49 */
51 NoRelationship = 0x0000, ///< No defined relationship
52 IntersectsWith = 0x0001, ///< Objects intersect
53 Contains = 0x0002, ///< Origin contains other
54 ContainedBy = 0x0004, ///< Origin is contained by other
55 AwayFrom = 0x0008, ///< Moving away from other
56 Towards = 0x0010, ///< Moving toward other
57 Above = 0x0020, ///< Origin is above other
58 Below = 0x0040, ///< Origin is below other
59 ToLeftOf = 0x0080, ///< Origin is to the left of other
60 ToRightOf = 0x0100, ///< Origin is to the right of other
61 Contained = 0x0200, ///< Origin is contained within other
62};
63Q_DECLARE_FLAGS(SpatialRelationships, SpatialRelationship)
64Q_DECLARE_OPERATORS_FOR_FLAGS(SpatialRelationships)
65
66/**
67 * @brief Coordinate axes.
68 */
69enum Axis {
70 NoAxis = 0x0000, ///< No axis
71 XAxis = 0x0001, ///< X axis
72 YAxis = 0x0002, ///< Y axis
73 ZAxis = 0x0004, ///< Z axis
74};
75Q_DECLARE_FLAGS(Axes, Axis)
76Q_DECLARE_OPERATORS_FOR_FLAGS(Axes)
77
78/**
79 * @brief Return a list of all four cardinal directions.
80 * @return List containing Up, Down, ToLeft, ToRight
81 */
82KANOOP_EXPORT QList<Direction> allDirections();
83
84/**
85 * @brief Convert a Direction to the corresponding Side value.
86 * @param direction Direction to convert
87 * @return Equivalent Side flag
88 */
89KANOOP_EXPORT Side directionToSide(Direction direction);
90
91/**
92 * @brief Convert a Side to the corresponding Direction value.
93 * @param side Side to convert
94 * @return Equivalent Direction value
95 */
96KANOOP_EXPORT Direction sideToDirection(Side side);
97
98/**
99 * @brief Convert a cardinal Direction to a compass bearing in degrees.
100 * @param direction Direction to convert
101 * @return Bearing in degrees (0 = Up/North, 90 = Right/East, etc.)
102 */
103KANOOP_EXPORT double directionToBearing(Direction direction);
104
105/**
106 * @brief Convert a compass bearing to the nearest cardinal Direction.
107 * @param bearing Bearing in degrees
108 * @return Nearest cardinal Direction
109 */
110KANOOP_EXPORT Direction bearingToDirection(double bearing);
111
112/**
113 * @brief Return the opposite of a cardinal Direction.
114 * @param direction Input direction
115 * @return Opposite direction (e.g. Up -> Down)
116 */
117KANOOP_EXPORT Direction oppositeDirection(Direction direction);
118
119} // namespace Geo
120
121#endif // GEO_H
Geographic type enumerations and string-conversion helpers for Qt geometry types.
Definition geotypes.h:14
KANOOP_EXPORT Side directionToSide(Direction direction)
Convert a Direction to the corresponding Side value.
SpatialRelationship
Spatial relationship between two geometric objects.
Definition geo.h:50
@ IntersectsWith
Objects intersect.
Definition geo.h:52
@ ContainedBy
Origin is contained by other.
Definition geo.h:54
@ ToLeftOf
Origin is to the left of other.
Definition geo.h:59
@ Below
Origin is below other.
Definition geo.h:58
@ Towards
Moving toward other.
Definition geo.h:56
@ AwayFrom
Moving away from other.
Definition geo.h:55
@ NoRelationship
No defined relationship.
Definition geo.h:51
@ Contained
Origin is contained within other.
Definition geo.h:61
@ ToRightOf
Origin is to the right of other.
Definition geo.h:60
@ Above
Origin is above other.
Definition geo.h:57
@ Contains
Origin contains other.
Definition geo.h:53
Direction
Cardinal directions, aliased to the corresponding Side values.
Definition geo.h:37
@ ToRight
Rightward (toward larger X)
Definition geo.h:42
@ ToLeft
Leftward (toward smaller X)
Definition geo.h:41
@ Down
Downward (toward larger Y)
Definition geo.h:40
@ NoDirection
No direction.
Definition geo.h:38
@ Up
Upward (toward smaller Y)
Definition geo.h:39
Axis
Coordinate axes.
Definition geo.h:69
@ XAxis
X axis.
Definition geo.h:71
@ NoAxis
No axis.
Definition geo.h:70
@ ZAxis
Z axis.
Definition geo.h:73
@ YAxis
Y axis.
Definition geo.h:72
Side
Bitmask identifying which side(s) of a rectangle are relevant.
Definition geo.h:19
@ Left
Left edge.
Definition geo.h:22
@ NoSide
No side.
Definition geo.h:20
@ BottomLeftCorner
Bottom-left corner.
Definition geo.h:27
@ Bottom
Bottom edge.
Definition geo.h:23
@ Right
Right edge.
Definition geo.h:24
@ TopLeftCorner
Top-left corner.
Definition geo.h:25
@ Top
Top edge.
Definition geo.h:21
@ BottomRightCorner
Bottom-right corner.
Definition geo.h:28
@ TopRightCorner
Top-right corner.
Definition geo.h:26
KANOOP_EXPORT Direction sideToDirection(Side side)
Convert a Side to the corresponding Direction value.
KANOOP_EXPORT Direction oppositeDirection(Direction direction)
Return the opposite of a cardinal Direction.
KANOOP_EXPORT double directionToBearing(Direction direction)
Convert a cardinal Direction to a compass bearing in degrees.
KANOOP_EXPORT QList< Direction > allDirections()
Return a list of all four cardinal directions.
KANOOP_EXPORT Direction bearingToDirection(double bearing)
Convert a compass bearing to the nearest cardinal Direction.