57 return almostBetween(point.
x, left, right) && almostBetween(point.
y, bottom, top);
64 enum class Side : int {Left, Bottom, Right, Top};
76 auto intersection = Intersection{};
77 auto t = std::numeric_limits<T>::infinity();
78 if (direction.
x > static_cast<T>(0.0))
80 t = (right - origin.
x) / direction.
x;
81 intersection.side = Side::Right;
82 intersection.point = origin + t * direction;
84 else if (direction.
x < static_cast<T>(0.0))
86 t = (left - origin.
x) / direction.
x;
87 intersection.side = Side::Left;
88 intersection.point = origin + t * direction;
90 if (direction.
y > static_cast<T>(0.0))
92 auto newT = (top - origin.
y) / direction.
y;
95 intersection.side = Side::Top;
96 intersection.point = origin + newT * direction;
99 else if (direction.
y < static_cast<T>(0.0))
101 auto newT = (bottom - origin.
y) / direction.
y;
104 intersection.side = Side::Bottom;
105 intersection.point = origin + newT * direction;
112 int getIntersections(
const Vector2<T>& origin,
const Vector2<T>& destination, std::array<Intersection, 2>& intersections)
const 117 auto direction = destination - origin;
118 auto t = std::array<T, 2>();
119 auto i = std::size_t(0);
121 if (strictlyLower(origin.x, left) || strictlyLower(destination.
x, left))
123 t[i] = (left - origin.x) / direction.
x;
124 if (strictlyBetween(t[i], static_cast<T>(0.0), static_cast<T>(1.0)))
126 intersections[i].side = Side::Left;
127 intersections[i].point = origin + t[i] * direction;
129 if (almostBetween(intersections[i].point.y, bottom, top))
134 if (strictlyGreater(origin.x, right) || strictlyGreater(destination.
x, right))
136 t[i] = (right - origin.x) / direction.
x;
137 if (strictlyBetween(t[i], static_cast<T>(0.0),
static_cast<T
>(1.0)))
139 intersections[i].side = Side::Right;
140 intersections[i].point = origin + t[i] * direction;
142 if (almostBetween(intersections[i].point.y, bottom, top))
147 if (strictlyLower(origin.y, bottom) || strictlyLower(destination.
y, bottom))
149 t[i] = (bottom - origin.y) / direction.
y;
150 if (i < 2 && strictlyBetween(t[i], static_cast<T>(0.0),
static_cast<T
>(1.0)))
152 intersections[i].side = Side::Bottom;
153 intersections[i].point = origin + t[i] * direction;
155 if (almostBetween(intersections[i].point.x, left, right))
160 if (strictlyGreater(origin.y, top) || strictlyGreater(destination.
y, top))
162 t[i] = (top - origin.y) / direction.
y;
163 if (i < 2 && strictlyBetween(t[i], static_cast<T>(0.0),
static_cast<T
>(1.0)))
165 intersections[i].side = Side::Top;
166 intersections[i].point = origin + t[i] * direction;
168 if (almostBetween(intersections[i].point.x, left, right))
173 if (i == 2 && t[0] > t[1])
174 std::swap(intersections[0], intersections[1]);
Data structure representing a partitioning of the space.
Class representing a box.
Implementation of Fortune's algorithm.
Class representing a 2D vector.