Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
point_utils.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
45# ifndef POINT_UTILS_H
46# define POINT_UTILS_H
47
48# include <point.H>
49
50[[deprecated("Use area_of_triangle() from point.H")]]
51inline Geom_Number area_of_triangle_legacy(const Point & a,
52 const Point & b,
53 const Point & c)
54{
55 return area_of_triangle(a, b, c);
56}
57
58[[deprecated("Use points_are_colinear via Point::is_colinear_with()")]]
59inline bool points_are_colinear(const Point & a,
60 const Point & b,
61 const Point & c)
62{
63 return area_of_parallelogram(a, b, c) == 0;
64}
65
66[[deprecated("Use orientation() from point.H")]]
67inline bool c_is_to_left_(const Point & a, const Point & b, const Point & c)
68{
69 return area_of_parallelogram(a, b, c) > 0;
70}
71
72[[deprecated("Use orientation() from point.H")]]
73inline bool is_clockwise(const Point & a, const Point & b, const Point & c)
74{
75 return area_of_parallelogram(a, b, c) < 0;
76}
77
78[[deprecated("Use orientation() from point.H")]]
79inline bool left_on(const Point & a, const Point & b, const Point & c)
80{
81 return area_of_parallelogram(a, b, c) >= 0;
82}
83
84[[deprecated("Use Segment::intersects_properly_with() from point.H")]]
85inline bool proper_intersection(const Point & a, const Point & b,
86 const Point & c, const Point & d)
87{
88 if (points_are_colinear(a, b, c) or
89 points_are_colinear(a, b, d) or
90 points_are_colinear(c, d, a) or
91 points_are_colinear(c, d, b))
92 return false;
93
94 return (c_is_to_left_(a, b, c) xor c_is_to_left_(a, b, d)) and
95 (c_is_to_left_(c, d, a) xor c_is_to_left_(c, d, b));
96}
97
98[[deprecated("Use Point::is_between() from point.H")]]
99inline bool between(const Point & a, const Point & b, const Point & c)
100{
101 if (not points_are_colinear(a, b, c))
102 return false;
103
104 if (a.get_x() != b.get_x())
105 return (((a.get_x() <= c.get_x()) and (c.get_x() <= b.get_x())) or
106 ((a.get_x() >= c.get_x()) and (c.get_x() >= b.get_x())));
107
108 return (((a.get_y() <= c.get_y()) and (c.get_y() <= b.get_y())) or
109 ((a.get_y() >= c.get_y()) and (c.get_y() >= b.get_y())));
110}
111
112[[deprecated("Use Segment::intersects_with() from point.H")]]
113inline bool intersect_improp(const Point & a, const Point & b,
114 const Point & c, const Point & d)
115{
116 return between(a, b, c) or between(a, b, d) or
117 between(c, d, a) or between(c, d, b);
118}
119
120[[deprecated("Use segments_intersect() from point.H")]]
121inline bool intersectp(const Point & a, const Point & b,
122 const Point & c, const Point & d)
123{
124 if (proper_intersection(a, b, c, d))
125 return true;
126
127 return intersect_improp(a, b, c, d);
128}
129
130
131# endif // POINT_UTILS_H
2D point and geometric utilities.
bool c_is_to_left_(const Point &a, const Point &b, const Point &c)
Definition point_utils.H:67
bool intersectp(const Point &a, const Point &b, const Point &c, const Point &d)
Geom_Number area_of_triangle_legacy(const Point &a, const Point &b, const Point &c)
Definition point_utils.H:51
bool left_on(const Point &a, const Point &b, const Point &c)
Definition point_utils.H:79
bool between(const Point &a, const Point &b, const Point &c)
Definition point_utils.H:99
bool intersect_improp(const Point &a, const Point &b, const Point &c, const Point &d)
bool is_clockwise(const Point &a, const Point &b, const Point &c)
Definition point_utils.H:73
bool proper_intersection(const Point &a, const Point &b, const Point &c, const Point &d)
Definition point_utils.H:85
bool points_are_colinear(const Point &a, const Point &b, const Point &c)
Definition point_utils.H:59