17template <
class Number,
class Label>
22template <
class Number,
class Label>
23template <std::
floating_po
int ResultNumber>
26 detail::lowerFloatingBound<ResultNumber>(
x()),
27 detail::lowerFloatingBound<ResultNumber>(
y()),
28 detail::upperFloatingBound<ResultNumber>(
x()),
29 detail::upperFloatingBound<ResultNumber>(
y()),
33template <
class Number,
class Label>
38template <
class Number,
class Label>
43template <
class Number,
class Label>
51template <
class Po
intType,
class LabelType>
52template <std::
floating_po
int ResultNumber,
class Value>
53constexpr ResultNumber Segment<PointType, LabelType>::lowerCoordinateBound(
const Value& value) {
54 if constexpr (
requires { value.template lowerBound<ResultNumber>(); }) {
55 return value.template lowerBound<ResultNumber>();
57 return static_cast<ResultNumber
>(value);
61template <
class Po
intType,
class LabelType>
62template <std::
floating_po
int ResultNumber,
class Value>
63constexpr ResultNumber Segment<PointType, LabelType>::upperCoordinateBound(
const Value& value) {
64 if constexpr (
requires { value.template upperBound<ResultNumber>(); }) {
65 return value.template upperBound<ResultNumber>();
67 return static_cast<ResultNumber
>(value);
71template <
class Po
intType,
class LabelType>
79template <
class Po
intType,
class LabelType>
80template <std::
floating_po
int ResultNumber>
82 ResultNumber xmin = lowerCoordinateBound<ResultNumber>(
min().
x());
83 ResultNumber ymin = lowerCoordinateBound<ResultNumber>(
min().
y());
84 ResultNumber xmax = upperCoordinateBound<ResultNumber>(
max().
x());
85 ResultNumber ymax = upperCoordinateBound<ResultNumber>(
max().
y());
87 std::swap(ymin, ymax);
92template <
class Po
intType,
class LabelType>
97template <
class Po
intType,
class LabelType>
102template <
class Po
intType,
class LabelType>
110template <
class Po
intType,
class LabelType>
115template <
class Po
intType,
class LabelType>
116template <std::
floating_po
int ResultNumber>
121template <
class Po
intType,
class LabelType>
126template <
class Po
intType,
class LabelType>
131template <
class Po
intType,
class LabelType>
139template <
class Po
intType,
class LabelType>
144template <
class Po
intType,
class LabelType>
145template <std::
floating_po
int ResultNumber>
148 detail::lowerFloatingBound<ResultNumber>(
min().
x()),
149 detail::lowerFloatingBound<ResultNumber>(
min().
y()),
150 detail::upperFloatingBound<ResultNumber>(
max().
x()),
151 detail::upperFloatingBound<ResultNumber>(
max().
y()),
155template <
class Po
intType,
class LabelType>
157 return makeCorner(max().
x(), min().
y());
160template <
class Po
intType,
class LabelType>
162 return makeCorner(min().
x(), max().
y());
165template <
class Po
intType,
class LabelType>
166template <
bool Oriented>
170 const auto bottom_left =
min();
171 const auto bottom_right = bottomRight();
172 const auto top_right =
max();
173 const auto top_left = topLeft();
187template <
class Po
intType,
class LabelType>
198template <
class Po
intType,
class LabelType>
202 boundaryAt<false>(0),
203 boundaryAt<false>(1),
204 boundaryAt<false>(2),
205 boundaryAt<false>(3),
209template <
class Po
intType,
class LabelType>
223template <
class Po
intType,
class LabelType>
228template <
class Po
intType,
class LabelType>
229template <std::
floating_po
int ResultNumber>
234template <
class Po
intType,
class LabelType>
239template <
class Po
intType,
class LabelType>
248template <
class Po
intType,
class LabelType>
309template <
class Po
intType,
class LabelType>
310template <Po
intConcept OtherPo
int>
318 points_[0] = points_[1] = makeCorner(
x,
y);
343 points_[0] = (min_x == old_min.x() && min_y == old_min.y())
345 : makeCorner(min_x, min_y);
346 points_[1] = (max_x == old_max.x() && max_y == old_max.y())
348 : makeCorner(max_x, max_y);
351template <
class Po
intType,
class LabelType>
352template <RectangleConcept OtherRectangle>
362template <
class Po
intType,
class LabelType>
363template <
class TShape>
364 requires(!detail::is_point_v<TShape> && !
RectangleConcept<TShape> &&
requires(
const TShape& shape) { shape.bbox(); })
366 insert(shape.bbox());
373template <
class Po
intType,
class LabelType>
375 if (!bbox_.empty()) {
378 if (points_.empty()) {
381 if (points_.size() <= 6) {
387 const auto unimodalMax = [](
auto first,
auto last,
auto key) {
391 const auto mid = lo + (hi - lo) / 2;
392 if (key(*mid) < key(*(mid + 1)))
405 const NumberType min_x = points_[0].x();
406 const auto mi = maxIndex();
407 const NumberType max_x = points_[mi].x();
408 const NumberType min_y = unimodalMax(points_.begin(), points_.begin() + mi + 1,
409 [](
const PointType& p) { return -p.y(); })->y();
410 const NumberType max_y = std::max(
411 unimodalMax(points_.begin() + mi, points_.end(),
412 [](
const PointType& p) { return p.y(); })->y(),
415 return bbox_ = Rectangle<PointType>(min_x, min_y, max_x, max_y,
true) + translation_;
418template <
class Po
intType,
class LabelType>
419template <std::
floating_po
int ResultNumber>
424template <
class Po
intType,
class LabelType>
425template <Po
intConcept OtherPo
int>
431 std::vector<PointType> points =
vertices();
436template <
class Po
intType,
class LabelType>
437template <
class TShape>
438 requires(!detail::is_point_v<TShape> &&
requires(
const TShape& shape) { shape.vertices(); })
442 insert(shape.vertices());
448template <
class Po
intType,
class LabelType>
450 if (!bbox_.empty()) {
453 if (points_.empty()) {
459template <
class Po
intType,
class LabelType>
460template <std::
floating_po
int ResultNumber>
468template <
class Po
intType,
class LabelType>
470 if (!bbox_.empty()) {
473 if (components_.empty()) {
479 for (std::size_t i = 1; i < components_.size(); ++i) {
485template <
class Po
intType,
class LabelType>
486template <std::
floating_po
int ResultNumber>
494template <
class Po
intType,
class LabelType,
class Storage>
496 if (!bbox_.empty()) {
499 if (points_.empty()) {
505template <
class Po
intType,
class LabelType,
class Storage>
506template <std::
floating_po
int ResultNumber>
514template <
class Po
intType,
class LabelType>
516 if (!bbox_.empty()) {
519 if (points_.empty()) {
525template <
class Po
intType,
class LabelType>
526template <std::
floating_po
int ResultNumber>
535template <
class Po
intType,
class LabelType>
536template <
class ResultNumber>
541 throw std::logic_error(
"HalfplaneIntersection::bbox is only defined for a nonempty bounded region");
543 using C = detail::promoted_number_t<detail::promoted_number_t<NumberType>>;
554 const std::size_t n = halfplanes_.size();
555 const std::size_t pos = linearUpperBound(query);
556 const std::size_t predIdx = (pos == 0 ? n : pos) - 1;
557 const auto& pred = halfplanes_[predIdx];
558 if (detail::directionEqual(pred, query)) {
561 return {
static_cast<C
>(wantX ? pred.source().
x() : pred.source().y()), C(1)};
563 const auto& succ = halfplanes_[pos == n ? 0 : pos];
566 const C sx =
static_cast<C
>(h.source().
x());
567 const C sy =
static_cast<C
>(h.source().
y());
568 const C tx =
static_cast<C
>(h.target().
x());
569 const C ty =
static_cast<C
>(h.target().
y());
570 struct Row { C ax, ay, b; };
571 return Row{ty - sy, sx - tx, sx * ty - sy * tx};
573 const auto r1 = row(pred);
574 const auto r2 = row(succ);
575 const C den = r1.ax * r2.ay - r1.ay * r2.ax;
578 return {r1.b * r2.ay - r2.b * r1.ay, den};
580 return {r1.ax * r2.b - r2.ax * r1.b, den};
588 const auto convert = [](
const Fraction& f,
bool roundUp) -> ResultNumber {
589 if constexpr (std::is_floating_point_v<ResultNumber>) {
591 return detail::asNumber<ResultNumber>(f.num) / detail::asNumber<ResultNumber>(f.den);
595 return detail::asNumber<ResultNumber>(f.num) / detail::asNumber<ResultNumber>(f.den);
600 return static_cast<ResultNumber
>(f.num / f.den);
604 C quotient = f.num / f.den;
605 const C remainder = f.num % f.den;
606 if (remainder != C(0)) {
607 if (roundUp && f.num > C(0)) {
610 if (!roundUp && f.num < C(0)) {
614 return static_cast<ResultNumber
>(quotient);
618 ResultPoint(convert(xMax,
true), convert(yMax,
true)));
621template <
class Po
intType,
class LabelType>
622template <std::
floating_po
int ResultNumber>
Definition forward.hpp:313
Geometric measurements and canonical representative-point helpers.
Definition arrangement.hpp:67
@ y
Definition intervaltree.hpp:24
@ x
Definition intervaltree.hpp:24
Rectangle() -> Rectangle< Point<>, NoLabel >
Definition rectangle.hpp:2384
constexpr bool is_Rational_v
Definition rational.hpp:37
@ vertex
Definition bitmatrix.hpp:37
OrientedSegment() -> OrientedSegment< Point<>, NoLabel >
Public declaration of pgl::Rectangle.
constexpr const Rectangle< PointType > & bbox() const
Computes the bounding box of the convex polygon.
Definition bounding.hpp:374
constexpr Rectangle< Point< ResultNumber > > fbox() const
Computes the floating-point bounding box of the convex polygon.
Definition bounding.hpp:420
constexpr void insert(const OtherPoint &point)
Enlarges the convex polygon so that it contains the given point.
Definition bounding.hpp:426
constexpr bool contains(const OtherPoint &point) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1135
constexpr const std::vector< PointType > vertices() const
Returns the vertices of the convex polygon.
Definition convex.hpp:508
PointType_ PointType
Definition convex.hpp:171
constexpr Rectangle< Point< ResultNumber, typename PointType::LabelType > > bbox() const
Computes the bounding box of the region.
Definition bounding.hpp:538
Halfplane< PointType > HalfplaneType
Definition halfplaneintersection.hpp:248
constexpr bool empty() const
Returns whether the region is the empty set.
Definition halfplaneintersection.hpp:649
constexpr bool isBounded() const
Returns whether the region is bounded.
Definition halfplaneintersection.hpp:811
PointType_ PointType
Definition halfplaneintersection.hpp:245
PointType::NumberType NumberType
Definition halfplaneintersection.hpp:246
constexpr Rectangle< Point< ResultNumber > > fbox() const
Computes the floating-point bounding box of the region.
Definition bounding.hpp:623
constexpr Rectangle< Point< ResultNumber > > fbox() const
Computes the floating-point bounding box of the chain.
Definition bounding.hpp:507
constexpr const Rectangle< PointType > & bbox() const
Computes the bounding box of the chain.
Definition bounding.hpp:495
constexpr std::array< OrientedSegment, 1 > orientedEdges() const
Returns the unique oriented edge of the oriented segment.
Definition bounding.hpp:132
constexpr Rectangle< PointType > bbox() const
Returns the bounding box of the oriented segment.
Definition bounding.hpp:111
constexpr const PointType & source() const
Returns the source endpoint.
Definition orientedsegment.hpp:178
constexpr Rectangle< Point< ResultNumber > > fbox() const
Returns a bounding box of the oriented segment with floating point coordinates.
Definition bounding.hpp:117
constexpr const PointType & target() const
Returns the target endpoint.
Definition orientedsegment.hpp:190
constexpr std::array< Segment< PointType >, 1 > edges() const
Returns the unique geometric edge of the oriented segment.
Definition bounding.hpp:127
constexpr std::array< PointType, 2 > vertices() const
Returns the two endpoints in source-to-target order.
Definition bounding.hpp:122
Two-dimensional point with optional label payload.
Definition point.hpp:129
constexpr std::array< Point, 1 > vertices() const
Returns the unique vertex of the point-shaped object.
Definition bounding.hpp:34
constexpr Rectangle< Point< ResultNumber > > fbox() const
Returns a floating-point bounding box containing the point.
Definition bounding.hpp:24
constexpr std::array< OrientedSegment< Point >, 0 > orientedEdges() const
Returns the oriented boundary edges.
Definition bounding.hpp:44
constexpr Rectangle< Point > bbox() const
Returns the bounding box of the point.
Definition bounding.hpp:18
constexpr std::array< Segment< Point >, 0 > edges() const
Returns the point boundary edges.
Definition bounding.hpp:39
constexpr Rectangle< Point< ResultNumber > > fbox() const
Computes the floating-point bounding box of the set.
Definition bounding.hpp:487
constexpr const Rectangle< PointType > & bbox() const
Computes the bounding box of the set.
Definition bounding.hpp:469
constexpr const Rectangle< PointType > & bbox() const
Computes the bounding box of the polygon.
Definition bounding.hpp:449
constexpr Rectangle< Point< ResultNumber > > fbox() const
Computes the floating-point bounding box of the polygon.
Definition bounding.hpp:461
constexpr const Rectangle< PointType > & bbox() const
Computes the bounding box of the polyline.
Definition bounding.hpp:515
constexpr Rectangle< Point< ResultNumber > > fbox() const
Computes the floating-point bounding box of the polyline.
Definition bounding.hpp:527
Axis-aligned rectangle stored by minimum and maximum corners.
Definition rectangle.hpp:75
std::conditional_t< Oriented, OrientedSegment< PointType >, Segment< PointType > > BoundaryType
Definition rectangle.hpp:88
constexpr Rectangle< Point< ResultNumber > > fbox() const
Returns a bounding box of the rectangle with floating point coordinates.
Definition bounding.hpp:146
PointType::NumberType NumberType
Definition rectangle.hpp:77
constexpr const PointType & min() const
Returns the minimum corner (min x, min y).
Definition rectangle.hpp:347
constexpr bool empty() const
Returns whether the rectangle is the empty set of points.
Definition rectangle.hpp:290
constexpr std::array< OrientedSegment< PointType >, 4 > orientedEdges() const
Returns the four boundary edges in counterclockwise order.
Definition bounding.hpp:210
constexpr std::array< Segment< PointType >, 4 > edges() const
Returns the four edges as unordered segments.
Definition bounding.hpp:199
constexpr std::array< PointType, 4 > vertices() const
Returns the four vertices in counterclockwise order.
Definition bounding.hpp:188
constexpr std::ptrdiff_t index(const PointType &point) const
Definition rectangle.hpp:330
PointType_ PointType
Definition rectangle.hpp:76
constexpr const PointType & max() const
Returns the maximum corner (max x, max y).
Definition rectangle.hpp:359
constexpr std::size_t size() const
Definition rectangle.hpp:307
constexpr Rectangle()
Creates the empty rectangle [(0,0),(-1,-1)].
Definition rectangle.hpp:120
constexpr void insert(const OtherPoint &point)
Enlarges the rectangle so that it contains the given point.
Definition bounding.hpp:311
constexpr Rectangle bbox() const
Returns the bounding box of the rectangle.
Definition bounding.hpp:140
Unoriented closed segment between two endpoints plus optional segment label.
Definition segment.hpp:58
constexpr Rectangle< Point< ResultNumber > > fbox() const
Returns a bounding box of the segment with floating point coordinates.
Definition bounding.hpp:81
constexpr std::array< PointType, 2 > vertices() const
Returns the two endpoints in canonical order.
Definition bounding.hpp:93
constexpr Rectangle< PointType > bbox() const
Returns the bounding box of the segment.
Definition bounding.hpp:72
constexpr std::array< Segment, 1 > edges() const
Returns the unique boundary edge of the segment.
Definition bounding.hpp:98
constexpr const PointType & max() const
Returns the largest stored endpoint.
Definition segment.hpp:199
constexpr const PointType & min() const
Returns the smallest stored endpoint.
Definition segment.hpp:190
constexpr std::array< OrientedSegment< PointType >, 1 > orientedEdges() const
Returns the unique oriented boundary edge in canonical order.
Definition bounding.hpp:103
constexpr const PointType & b() const
Returns the second vertex.
Definition triangle.hpp:217
constexpr std::array< PointType, 3 > vertices() const
Returns the vertices in canonical order.
Definition bounding.hpp:235
constexpr const PointType & a() const
Returns the first vertex.
Definition triangle.hpp:208
constexpr Rectangle< PointType > bbox() const
Returns the axis-aligned bounding box of the vertices.
Definition bounding.hpp:224
constexpr Rectangle< Point< ResultNumber > > fbox() const
Returns a floating-point bounding box containing the triangle.
Definition bounding.hpp:230
constexpr std::array< Segment< PointType >, 3 > edges() const
Returns the three unoriented boundary edges.
Definition bounding.hpp:240
constexpr const PointType & c() const
Returns the third vertex.
Definition triangle.hpp:226
constexpr std::array< OrientedSegment< PointType >, 3 > orientedEdges() const
Returns the three oriented boundary edges.
Definition bounding.hpp:249