10 #ifndef QD_CPP_RATPOINT_INCLUDED_IVILAB_UARIZONAVISION
11 #define QD_CPP_RATPOINT_INCLUDED_IVILAB_UARIZONAVISION 1
18 #include <l/l_sys_lib.h>
19 #include <l/l_sys_io.h>
21 #ifndef UNLIMITED_RATIONAL_PRECISION_QD_CPP_IVILAB
22 #define UNLIMITED_RATIONAL_PRECISION_QD_CPP_IVILAB 0
25 #if UNLIMITED_RATIONAL_PRECISION_QD_CPP_IVILAB
26 #include <boost/multiprecision/cpp_int.hpp>
28 #include <boost/rational.hpp>
40 #if UNLIMITED_RATIONAL_PRECISION_QD_CPP_IVILAB
41 typedef boost::multiprecision::cpp_rational
Rat;
45 typedef boost::rational< PixPoint::Integer >
Rat;
48 typedef boost::rational< long long >
Rat;
72 return a.
x == b.
x && a.
y == b.
y;
84 return a.
y < b.
y || (a.
y==b.
y && a.
x < b.
x);
105 s << p.
x.numerator();
106 if (p.
x.denominator() > 1) s <<
'/' << p.
x.denominator();
108 s <<
", " << p.
y.numerator();
109 if (p.
y.denominator() > 1) s <<
'/' << p.
y.denominator();
155 const PixPoint_line_segment&,
156 const PixPoint_line_segment&
162 template <
typename LINE_SEGMENT>
164 const LINE_SEGMENT& s,
165 const LINE_SEGMENT& t
172 && ( (
is_on(s, t.a) && t.a != s.a && t.a != s.b)
173 || (
is_on(s, t.b) && t.b != s.a && t.b != s.b)
174 || (
is_on(t, s.a) && s.a != t.a && s.a != t.b)
175 || (
is_on(t, s.b) && s.b != t.a && s.b != t.b)
176 || (t.a==s.a && t.b==s.b)
177 || (t.a==s.b && t.b==s.a)
183 template <
typename LINE_SEGMENT>
185 const LINE_SEGMENT& s,
186 const LINE_SEGMENT& t,
187 LINE_SEGMENT* shared_continuum
199 if ((t.a==s.a && t.b==s.b) || (t.a==s.b && t.b==s.a))
201 *shared_continuum = s;
205 if (
is_on(s, t.a) && t.a != s.a && t.a != s.b)
209 *shared_continuum = LINE_SEGMENT(s.a, t.a);
211 else if (
is_on(t, s.b))
213 *shared_continuum = LINE_SEGMENT(t.a, s.b);
217 *shared_continuum = t;
222 if (
is_on(s, t.b) && t.b != s.a && t.b != s.b)
226 *shared_continuum = LINE_SEGMENT(s.a, t.b);
228 else if (
is_on(t, s.b))
230 *shared_continuum = LINE_SEGMENT(t.b, s.b);
234 *shared_continuum = t;
239 if (
is_on(t, s.a) && s.a != t.a && s.a != t.b)
243 *shared_continuum = LINE_SEGMENT(s.a, t.a);
245 else if (
is_on(s, t.b))
247 *shared_continuum = LINE_SEGMENT(s.a, t.b);
251 *shared_continuum = s;
255 if (
is_on(t, s.b) && s.b != t.a && s.b != t.b)
259 *shared_continuum = LINE_SEGMENT(s.b, t.a);
261 else if (
is_on(s, t.b))
263 *shared_continuum = LINE_SEGMENT(s.b, t.b);
267 *shared_continuum = s;
302 const RatPoint_line_segment&,
307 bool is_on(
const RatPoint_line_segment&,
const RatPoint&);
311 const RatPoint_line_segment&,
312 const RatPoint_line_segment&
339 const RatPoint_line_segment&,
340 const RatPoint_line_segment&
369 if (s.
a == t.
a || s.
a == t.
b)
371 intersection ->
a = intersection -> b = s.
a;
376 intersection ->
a = intersection -> b = s.
b;
399 const RatPoint_line_segment& s,
bool are_parallel(const PixPoint_line_segment &s, const PixPoint_line_segment &t)
test whether these segments lie on parallel lines or are collinear.
Definition: ratpoint.h:138
PixPoint b
Definition: ratpoint.h:117
#define KJB(x)
Definition: l_util.h:9
RatPoint(const PixPoint &p)
construct from one PixPoint (just copy it)
Definition: ratpoint.h:55
#define KJB_THROW(ex)
Definition: l_exception.h:46
#define ASSERT(condition, message)
Definition: Assert.h:45
basic line segment when endpoints are PixPoints (int coords)
Definition: ratpoint.h:115
#define NTX(a)
Definition: l_exception.h:89
Rat x
Definition: ratpoint.h:52
RatPoint b
Definition: ratpoint.h:279
RatPoint_line_segment(const RatPoint &p, const RatPoint &q)
Definition: ratpoint.h:281
bool is_intersecting(const PixPoint_line_segment &s, const PixPoint_line_segment &t)
Test whether two closed line segments intersect.
Definition: ratpoint.cpp:68
Rat y
Definition: ratpoint.h:52
very basic structure to represent X, Y points with rational coords.
Definition: ratpoint.h:38
closed line segment with rational coords
Definition: ratpoint.h:277
std::ostream & operator<<(std::ostream &o, const Doubly_connected_edge_list &d)
Print a text representation of the DCEL tables (but not the cache)
Definition: dcel.cpp:1270
PixPoint_line_segment(const PixPoint &p, const PixPoint &q)
Definition: ratpoint.h:119
Integer x
x coordinate of the pixel
Definition: pixpoint.h:79
boost::rational< long long > Rat
Definition: ratpoint.h:48
bool is_degenerate(const PixPoint_line_segment &s)
Definition: ratpoint.h:126
bool is_on(const RatPoint_line_segment &s, const RatPoint &c)
test whether a given point lies on a given segment
Definition: ratpoint.cpp:151
bool operator<=(const RatPoint &a, const RatPoint &b)
"row-major" ordering of points
Definition: ratpoint.h:89
bool are_sharing_a_continuum(const LINE_SEGMENT &s, const LINE_SEGMENT &t)
test whether two segments share an infinity of common points
Definition: ratpoint.h:163
RatPoint_line_segment(const PixPoint_line_segment &s)
Definition: ratpoint.h:286
bool operator==(const RatPoint &a, const RatPoint &b)
test equality of two RatPoints, totally unsurprising.
Definition: ratpoint.h:70
RatPoint::Rat triangle_area(const RatPoint_line_segment &s, const RatPoint &apex)
find signed area of triangle defined by segment endpoints and apex.
Definition: ratpoint.cpp:141
RatPoint(const Rat &rx, const Rat &ry)
construct from two rational cartesian coordinates
Definition: ratpoint.h:61
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
bool operator<(const RatPoint &a, const RatPoint &b)
"row-major" ordering of points
Definition: ratpoint.h:82
bool operator!=(const RatPoint &a, const RatPoint &b)
test inequality of two RatPoints.
Definition: ratpoint.h:76
Representation of an (x,y) pair of pixel coordinates.
Definition: pixpoint.h:57
RatPoint operator-(const RatPoint &a, const RatPoint &b)
subtraction of RatPoints as if they are position vectors
Definition: ratpoint.h:96
RatPoint a
Definition: ratpoint.h:279
PixPoint a
Definition: ratpoint.h:117
bool segment_intersection(const RatPoint_line_segment &s, const RatPoint_line_segment &t, RatPoint_line_segment *intersection)
if segments intersect, return true and compute intersection
Definition: ratpoint.h:355
Support for error handling exception classes in libKJB.
Integer y
y coordinate of the pixel
Definition: pixpoint.h:79
Contains definition for classes PixPath, PixPathAc, DoubleCircle.
RatPoint line_intersection(const RatPoint_line_segment &s, const RatPoint_line_segment &t)
find intersection point of nonparallel lines through these segments
Definition: ratpoint.cpp:84