KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
geocircle.h
1/**
2 * @brief A geographic circle defined by a GeoCoordinate centre and a radius in metres.
3 */
4#ifndef GEOCIRCLE_H
5#define GEOCIRCLE_H
6#include <QtMath>
7
8#include "Kanoop/geo/geocoordinate.h"
9#include "Kanoop/kanoopcommon.h"
10
11/**
12 * @brief Represents a circular region on the Earth's surface.
13 *
14 * The centre is a GeoCoordinate and the radius is in metres.
15 * Use contains() to test whether another coordinate falls within the circle.
16 */
17class KANOOP_EXPORT GeoCircle
18{
19public:
20 /** @brief Default constructor — creates an invalid circle with zero radius. */
22 _radius(0) {}
23
24 /**
25 * @brief Construct a GeoCircle from a centre coordinate and radius.
26 * @param center Centre of the circle (geographic coordinate)
27 * @param radius Radius in metres
28 */
29 GeoCircle(const GeoCoordinate& center, double radius) :
30 _center(center),
31 _radius(radius) {}
32
33 /** @brief Equality comparison.
34 * @param other Circle to compare against
35 * @return true if centre and radius are equal */
36 bool operator==(const GeoCircle& other) const;
37 /** @brief Inequality comparison.
38 * @param other Circle to compare against
39 * @return true if circles are not equal */
40 bool operator!=(const GeoCircle& other) const { return !(*this == other); }
41
42 /**
43 * @brief Return the centre coordinate.
44 * @return Centre GeoCoordinate
45 */
46 GeoCoordinate center() const { return _center; }
47
48 /**
49 * @brief Set the centre coordinate.
50 * @param value New centre GeoCoordinate
51 */
52 void setCenter(GeoCoordinate value) { _center = value; }
53
54 /**
55 * @brief Return the radius in metres.
56 * @return Radius value
57 */
58 double radius() const { return _radius; }
59
60 /**
61 * @brief Set the radius in metres.
62 * @param value New radius value
63 */
64 void setRadius(double value) { _radius = value; }
65
66 /**
67 * @brief Return the diameter in metres.
68 * @return Diameter (2 × radius)
69 */
70 double diameter() const { return _radius * 2; }
71
72 /**
73 * @brief Return the area in square metres.
74 * @return Area (π × radius²)
75 */
76 double area() const { return M_PI * (_radius * _radius); }
77
78 /**
79 * @brief Test whether a coordinate falls within this circle.
80 * @param point Coordinate to test
81 * @return true if the great-circle distance from centre to point is ≤ radius
82 */
83 bool contains(const GeoCoordinate& point) const;
84
85 /**
86 * @brief Test whether this circle has a valid centre and non-zero radius.
87 * @return true if centre is valid and radius != 0
88 */
89 bool isValid() const { return _center.isValid() && _radius != 0; }
90
91 /**
92 * @brief Format this circle as a human-readable string.
93 * @return String of the form "lat, lon, radius"
94 */
95 QString toString() const
96 {
97 return QString("%1, %2").arg(_center.toString()).arg(radius());
98 }
99
100 /**
101 * @brief Parse a GeoCircle from a string produced by toString().
102 * @param value String representation
103 * @return Parsed GeoCircle
104 */
105 static GeoCircle fromString(const QString& value);
106
107private:
108 GeoCoordinate _center;
109 double _radius;
110};
111
112#endif // GEOCIRCLE_H
A geographic circle defined by a GeoCoordinate centre and a radius in metres.
Definition geocircle.h:18
bool isValid() const
Test whether this circle has a valid centre and non-zero radius.
Definition geocircle.h:89
bool operator==(const GeoCircle &other) const
Equality comparison.
GeoCoordinate center() const
Return the centre coordinate.
Definition geocircle.h:46
GeoCircle(const GeoCoordinate &center, double radius)
Construct a GeoCircle from a centre coordinate and radius.
Definition geocircle.h:29
bool operator!=(const GeoCircle &other) const
Inequality comparison.
Definition geocircle.h:40
double radius() const
Return the radius in metres.
Definition geocircle.h:58
double area() const
Return the area in square metres.
Definition geocircle.h:76
double diameter() const
Return the diameter in metres.
Definition geocircle.h:70
bool contains(const GeoCoordinate &point) const
Test whether a coordinate falls within this circle.
QString toString() const
Format this circle as a human-readable string.
Definition geocircle.h:95
void setCenter(GeoCoordinate value)
Set the centre coordinate.
Definition geocircle.h:52
GeoCircle()
Default constructor — creates an invalid circle with zero radius.
Definition geocircle.h:21
void setRadius(double value)
Set the radius in metres.
Definition geocircle.h:64
static GeoCircle fromString(const QString &value)
Parse a GeoCircle from a string produced by toString().
A WGS-84 geographic coordinate (latitude, longitude, altitude).