17#include <geos/export.h>
18#include <geos/geom/Coordinate.h>
19#include <geos/geom/Quadrant.h>
20#include <geos/algorithm/CircularArcs.h>
21#include <geos/algorithm/Orientation.h>
22#include <geos/triangulate/quadedge/TrianglePredicate.h>
32 using CoordinateXY = geom::CoordinateXY;
34 CircularArc(
const CoordinateXY& q0,
const CoordinateXY& q1,
const CoordinateXY& q2)
38 , m_center_known(
false)
39 , m_radius_known(
false)
40 , m_orientation_known(
false)
43 const CoordinateXY& p0;
44 const CoordinateXY& p1;
45 const CoordinateXY& p2;
52 if (!m_orientation_known) {
53 m_orientation = algorithm::Orientation::index(p0, p1, p2);
54 m_orientation_known =
true;
61 if (!m_center_known) {
62 m_center = algorithm::CircularArcs::getCenter(p0, p1, p2);
63 m_center_known =
true;
71 if (!m_radius_known) {
72 m_radius = getCenter().distance(p0);
73 m_radius_known =
true;
86 return std::isnan(getRadius());
103 if (orientation() == algorithm::Orientation::COUNTERCLOCKWISE) {
119 return p0.distance(p2);
122 return getAngle()*getRadius();
131 auto R = getRadius();
132 auto theta = getAngle();
133 return R*R/2*(theta - std::sin(theta));
138 return std::atan2(p0.y - getCenter().y, p0.x - getCenter().x);
143 return std::atan2(p2.y - getCenter().y, p2.x - getCenter().x);
150 double theta = std::atan2(q.y - getCenter().y, q.x - getCenter().x);
151 return containsAngle(theta);
157 if (q == p0 || q == p1 || q == p2) {
161 auto dist = std::abs(q.distance(getCenter()) - getRadius());
167 if (triangulate::quadedge::TrianglePredicate::isInCircleNormalized(p0, p1, p2, q) != geom::Location::BOUNDARY) {
171 return containsPointOnCircle(q);
179 if (theta == t0 || theta == t2) {
183 if (orientation() == algorithm::Orientation::COUNTERCLOCKWISE) {
204 auto quad = geom::Quadrant::quadrant(getCenter(), q);
207 if (orientation() == algorithm::Orientation::CLOCKWISE) {
208 isUpward = (quad == geom::Quadrant::SW || quad == geom::Quadrant::NW);
210 isUpward = (quad == geom::Quadrant::SE || quad == geom::Quadrant::NE);
218 using iterator_category = std::forward_iterator_tag;
219 using difference_type = std::ptrdiff_t;
220 using value_type = geom::CoordinateXY;
221 using pointer =
const geom::CoordinateXY*;
222 using reference =
const geom::CoordinateXY&;
224 Iterator(
const CircularArc& arc,
int i) : m_arc(arc), m_i(i) {}
226 reference operator*()
const {
227 return m_i == 0 ? m_arc.p0 : (m_i == 1 ? m_arc.p1 : m_arc.p2);
230 Iterator& operator++() {
235 Iterator operator++(
int) {
236 Iterator ret = *
this;
241 bool operator==(
const Iterator& other)
const {
242 return m_i == other.m_i;
245 bool operator!=(
const Iterator& other)
const {
246 return !(*
this == other);
250 const CircularArc& m_arc;
255 Iterator begin()
const {
256 return Iterator(*
this, 0);
259 Iterator end()
const {
260 return Iterator(*
this, 3);
264 mutable CoordinateXY m_center;
265 mutable double m_radius;
266 mutable int m_orientation;
267 mutable bool m_center_known =
false;
268 mutable bool m_radius_known =
false;
269 mutable bool m_orientation_known =
false;
Definition CircularArc.h:29
bool containsPointOnCircle(const CoordinateXY &q) const
Definition CircularArc.h:149
bool isUpwardAtPoint(const CoordinateXY &q) const
Definition CircularArc.h:203
bool isCircle() const
Return whether this arc forms a complete circle.
Definition CircularArc.h:80
bool containsAngle(double theta) const
Check to see if a given angle lies on this arc.
Definition CircularArc.h:175
const CoordinateXY & getCenter() const
Return the center point of the circle associated with this arc.
Definition CircularArc.h:60
int orientation() const
Definition CircularArc.h:51
bool isLinear() const
Returns whether this arc forms a straight line (p0, p1, and p2 are collinear)
Definition CircularArc.h:85
double getAngle() const
Return the inner angle of the sector associated with this arc.
Definition CircularArc.h:90
bool containsPoint(const CoordinateXY &q)
Definition CircularArc.h:156
double getLength() const
Return the length of the arc.
Definition CircularArc.h:117
double getArea() const
Return the area enclosed by the arc p0-p1-p2 and the line segment p2-p0.
Definition CircularArc.h:126
double getRadius() const
Return the radius of the circle associated with this arc.
Definition CircularArc.h:70
double theta0() const
Return the angle of p0.
Definition CircularArc.h:137
double theta2() const
Return the angle of p2.
Definition CircularArc.h:142
Basic namespace for all GEOS functionalities.
Definition geos.h:39