17#include <geos/export.h>
18#include <geos/geom/Coordinate.h>
19#include <geos/geom/LineSegment.h>
20#include <geos/geom/Quadrant.h>
21#include <geos/algorithm/CircularArcs.h>
22#include <geos/algorithm/Orientation.h>
26class CurveToLineParams;
52 CircularArc(std::unique_ptr<CoordinateSequence>, std::size_t pos);
53 CircularArc(std::unique_ptr<CoordinateSequence>, std::size_t pos,
const CoordinateXY& center,
double radius,
int orientation);
67 template<typename CoordType>
68 static
CircularArc create(const CoordType& p0, const CoordType& p1, const CoordType& p2)
70 auto seq = std::make_unique<CoordinateSequence>(3, CoordType::template has<Ordinate::Z>(), CoordType::template has<Ordinate::M>());
80 static CircularArc create(
const CoordinateXY& p0,
const CoordinateXY& p2,
const CoordinateXY& center,
double radius,
int orientation);
82 static CircularArc create(
const CoordinateXYM& p0,
const CoordinateXYM& p2,
const CoordinateXY& center,
double radius,
int orientation);
83 static CircularArc create(
const CoordinateXYZM& p0,
const CoordinateXYZM& p2,
const CoordinateXY& center,
double radius,
int orientation);
93 if (!m_center_known) {
95 m_center = algorithm::CircularArcs::getCenter(p0(), p1(), p2());
97 m_center = algorithm::CircularArcs::getCenter(p2(), p1(), p0());
99 m_center_known =
true;
109 std::size_t getCoordinatePosition()
const {
118 CoordinateXY getReverseDirectionPoint()
const;
134 if (!m_orientation_known) {
135 m_orientation = algorithm::Orientation::index(p0(), p1(), p2());
136 m_orientation_known =
true;
138 return m_orientation;
143 if (!m_radius_known) {
145 m_radius = getCenter().distance(p0());
147 m_radius = getCenter().distance(p2());
149 m_radius_known =
true;
157 CoordinateXY midpoint = algorithm::CircularArcs::getMidpoint(p0(), p2(), getCenter(), getRadius(), isCCW());
158 return algorithm::Distance::pointToSegment(midpoint, p0(), p2());
162 return getOrientation() == algorithm::Orientation::COUNTERCLOCKWISE;
167 return p0().equals(p2());
172 return !std::isfinite(getRadius());
177 return algorithm::CircularArcs::getAngle(p0(), getCenter());
182 return algorithm::CircularArcs::getAngle(p1(), getCenter());
187 return algorithm::CircularArcs::getAngle(p2(), getCenter());
200 double theta = std::atan2(q.y - getCenter().y, q.x - getCenter().x);
201 return containsAngle(theta);
204 CoordinateXY closestPoint(
const CoordinateXY& p)
const;
205 std::array<CoordinateXY, 2> closestPoints(
const CoordinateXY& p1,
const CoordinateXY& p2)
const;
206 std::array<CoordinateXY, 2> closestPoints(
const CircularArc& other)
const;
208 double distance(
const CoordinateXY& p)
const;
209 double distance(
const CoordinateXY& p1,
const CoordinateXY& p2)
const;
218 bool equals(
const CircularArc& other,
double tol)
const;
222 using iterator_category = std::forward_iterator_tag;
223 using difference_type = std::ptrdiff_t;
224 using value_type = geom::CoordinateXY;
225 using pointer =
const geom::CoordinateXY*;
226 using reference =
const geom::CoordinateXY&;
228 Iterator(
const CircularArc& arc,
int i) : m_arc(arc), m_i(i) {}
230 reference operator*()
const {
231 return m_i == 0 ? m_arc.p0() : (m_i == 1 ? m_arc.p1() : m_arc.p2());
234 Iterator& operator++() {
239 Iterator operator++(
int) {
240 Iterator ret = *
this;
245 bool operator==(
const Iterator& other)
const {
246 return m_i == other.m_i;
249 bool operator!=(
const Iterator& other)
const {
250 return !(*
this == other);
254 const CircularArc& m_arc;
259 Iterator begin()
const {
260 return Iterator(*
this, 0);
263 Iterator end()
const {
264 return Iterator(*
this, 3);
267 template<
typename T=CoordinateXY>
268 const T& p0()
const {
269 return m_seq->getAt<T>(m_pos);
272 template<
typename T=CoordinateXY>
273 const T& p1()
const {
274 return m_seq->getAt<T>(m_pos + 1);
277 template<
typename T=CoordinateXY>
278 const T& p2()
const {
279 return m_seq->getAt<T>(m_pos + 2);
282 std::string toString()
const;
285 auto applyAt(std::size_t i, F&& f)
const {
286 return m_seq->applyAt(m_pos + i, f);
290 const CoordinateSequence* m_seq;
293 mutable CoordinateXY m_center;
294 mutable double m_radius;
295 mutable int m_orientation;
296 mutable bool m_center_known =
false;
297 mutable bool m_radius_known =
false;
298 mutable bool m_orientation_known =
false;
299 bool m_own_coordinates;
Definition CircularArc.h:34
CoordinateXY getDirectionPoint() const
bool containsPointOnCircle(const CoordinateXY &q) const
Definition CircularArc.h:199
CircularArc(std::unique_ptr< CoordinateSequence >, std::size_t pos)
bool isCircle() const
Return whether this arc forms a complete circle.
Definition CircularArc.h:166
CircularArc(const CoordinateSequence &, std::size_t pos)
bool containsAngle(double theta) const
Check to see if a given angle lies on this arc.
int getOrientation() const
Definition CircularArc.h:133
const CoordinateXY & getCenter() const
Return the center point of the circle associated with this arc.
Definition CircularArc.h:92
double getSagitta() const
Return the distance from the centerpoint of the arc to the line segment formed by the end points of t...
Definition CircularArc.h:156
void addLinearizedPoints(CoordinateSequence &seq, const algorithm::CurveToLineParams ¶ms) const
bool isLinear() const
Returns whether this arc forms a straight line (p0, p1, and p2 are collinear)
Definition CircularArc.h:171
double getAngle() const
Return the inner angle of the sector associated with this arc.
double getLength() const
Return the length of the arc.
double getArea() const
Return the area enclosed by the arc p0-p1-p2 and the line segment p2-p0.
double getRadius() const
Return the radius of the circle associated with this arc.
Definition CircularArc.h:142
bool containsPoint(const CoordinateXY &q) const
double theta0() const
Return the angle of p0.
Definition CircularArc.h:176
double theta1() const
Return the angle of p1.
Definition CircularArc.h:181
double theta2() const
Return the angle of p2.
Definition CircularArc.h:186
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:220
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
Basic namespace for all GEOS functionalities.
Definition geos.h:38