geomc 1.0
A c++ linear algebra template library
|
An N-dimensional axis-aligned interval. More...
#include <geomc/shape/Rect.h>
Public Types | |
using | elem_t |
The coordinate type of this object. | |
using | point_t |
The type of a point in this object's space. | |
Public Member Functions | |
constexpr | Rect () |
Construct an empty interval. | |
template<index_t... J> requires ((J + ...) == N) | |
constexpr | Rect (const Rect< T, J > &... r) |
Construct a Rect from lower-dimensional Rects. | |
constexpr | Rect (point_t lo, point_t hi) |
Construct a Rect with extremes lo and hi . If for any axis lo > hi , the Rect is empty. | |
constexpr | Rect (point_t p) |
Construct a Rect containing only the point p . | |
Rect< T, N > | abs () const |
Normalize the sign of the region. | |
Rect< T, 1 > | axis (size_t k) const |
Return the one dimensional range spanned along axis k . | |
Rect< T, N > | bounds () const |
point_t | center () const |
Center point. | |
Rect< T, N > | centered_on (point_t c) const |
Place a copy at a new location. | |
point_t | clip (point_t p) const |
Clamp the coordinates of p to lie within this Rect. | |
std::pair< point_t, bool > | contact_vector (const Rect< T, N > &other) const |
Return a vector which moves this into precise disjoint contact with other , and a boolean indicating whether the two shapes currently overlap. | |
bool | contains (const Rect< T, N > &box) const |
Box containment. | |
bool | contains (point_t pt) const |
Point containment test. | |
point_t | convex_support (point_t d) const |
Rect< T, N > | dilated (point_t c) const |
Morphological dilation. | |
point_t | dimensions () const |
Axial size. | |
T | dist2 (point_t p) const |
Squared distance to the interior of the Rect. | |
point_t | face_areas () const |
Measure of the axial faces of this Rect. | |
Rect< T, N > | fitted_to (Rect< T, N > other) const |
Return a rect having the same aspect (ratios of axial lengths) as this one, sized and positioned to minimally contain other . | |
Rect< T, 1 > | intersect (const Ray< T, N > &r) const |
Ray-shape intersection test. | |
bool | intersects (const Convex< T, N, Shape > &other) const |
Convex shape overlap test. | |
bool | intersects (const Rect< T, N > &box) const |
Range intersection test. | |
bool | intersects (const Sphere< T, N > &sph) const |
bool | intersects (const Transformed< Rect< T, N > > &box) const |
Transformed range intersection test. | |
bool | is_empty () const |
Empty region test. | |
auto | length () const |
Return a "normalized" length measure encoding the size of this box. | |
T | measure_boundary () const |
Measure of the boundary of this Rect. | |
T | measure_interior () const |
N-dimensional volume. | |
Rect< T, N > | minkowski_sum (const Rect< T, N > &other) const |
Minkowski sum. | |
point_t | normal (point_t p) const |
Outward-facing direction. | |
template<typename U, index_t M> | |
operator Rect< U, M > () const | |
Element-wise typecast. | |
bool | operator!= (const Rect< T, N > &b) const |
Inequality test. | |
Rect< T, N > | operator& (const Rect< T, N > &b) const |
Interval intersection. | |
Rect< T, N > & | operator&= (const Rect< T, N > &b) |
Interval intersection. | |
template<typename... I> requires (... and std::convertible_to<I, size_t>) | |
Rect< T, sizeof...(I)> | operator() (I... indices) const |
Dimensionally slice a Rect. | |
template<index_t M> | |
Rect< T, M+N > | operator* (const Rect< T, M > &r) const |
Interval cartesian product. | |
Rect< T, N > | operator* (point_t a) const |
Scale transformation. | |
Rect< T, N > & | operator*= (point_t a) |
Scale transformation. | |
Rect< T, N > | operator+ (point_t dx) const |
Translation. | |
Rect< T, N > & | operator+= (point_t dx) |
Translation. | |
Rect< T, N > | operator- (const Rect< T, N > &other) |
Interval exclusion. | |
Rect< T, N > | operator- (point_t dx) const |
Translation. | |
Rect< T, N > & | operator-= (const Rect< T, N > &other) |
Interval exclusion. | |
Rect< T, N > & | operator-= (point_t dx) |
Translation. | |
Rect< T, N > | operator/ (point_t a) const |
Scale transformation. | |
Rect< T, N > & | operator/= (point_t a) |
Scale transformation. | |
bool | operator== (const Rect< T, N > &b) const |
Equality test. | |
Rect< T, N > | operator| (const point_t &p) |
Point union. | |
Rect< T, N > | operator| (const Rect< T, N > &b) const |
Interval union. | |
Rect< T, N > & | operator|= (const point_t &p) |
Point union. | |
Rect< T, N > & | operator|= (const Rect< T, N > &b) |
Interval union. | |
point_t | project (point_t p) const |
Return the point on the surface of the shape which is nearest to p . | |
point_t | remap (point_t s) const |
Map the unit interval to the region. | |
template<index_t M> requires (N == 1 and M > 1) | |
Vec< T, M > | remap (Vec< T, M > s) const |
Map the unit interval to the region, broadcasting to a different dimension. | |
T | sdf (point_t p) const |
Return the signed distance to the surface of the shape. | |
void | set_corners (point_t corner1, point_t corner2) |
Reconstruct from corner points. | |
void | set_dimensions (point_t dim) |
Change the size of the region, adjusting about its center. | |
point_t | unmap (point_t p) const |
Find p 's fractional position within this Rect. | |
template<index_t M> requires (N == 1 and M > 1) | |
Vec< T, M > | unmap (Vec< T, M > p) const |
Find p 's fractional position within this Rect, broadcasting to a different dimension. | |
Static Public Member Functions | |
static constexpr bool | admits_cusps () |
static bool | contains (VecType< T, N > lo, VecType< T, N > hi, VecType< T, N > pt) |
Test whether a point is in the N-dimensional range [lo, hi] . | |
static Rect< T, N > | from_center (VecType< T, N > c, VecType< T, N > dims) |
Construct a Rect from a center point and extent. | |
static Rect< T, N > | from_corners (point_t c1, point_t c2) |
Construct a Rect containing the two corners c1 and c2 . | |
static Rect< T, N > | from_edge (VecType< T, N > edge, VecType< T, N > dims) |
Construct a Rect from a corner point and an extent. | |
template<typename PointIterator> | |
static Rect< T, N > | from_point_sequence (PointIterator begin, PointIterator end) |
Construct a Rect containing all the points in the sequence between begin and end . | |
static Rect< T, N > | from_size (VecType< T, N > dims) |
Construct a Rect at the origin having dimensions dims . | |
Public Attributes | |
point_t | hi |
Upper extremes. | |
point_t | lo |
Lower extremes. | |
Static Public Attributes | |
static const Rect< T, N > | empty |
A Rect that contains no points. | |
static const point_t | endpoint_measure |
static const Rect< T, N > | full |
A Rect that contains all points. | |
static constexpr index_t | N |
The dimension of this object. | |
static const Rect< T, N > | signed_unit_interval |
A Rect covering the range [-1, 1] along all axes. | |
static const Rect< T, N > | unit_interval |
A Rect covering the range [0, 1] along all axes. | |
Protected Types | |
typedef PointType< T, N > | ptype |
An N-dimensional axis-aligned interval.
This class works naturally with both 1D and multi-dimensional ranges. 1D ranges have point type T
, while multi-dimensional ranges have point type Vec<T,N>
. A typedef of this may be accessed via:
Rect<T,N>::point_t
Example:
Rect<double,4>::point_t
is Vec<double,4>
; lo
and hi
are Vec4d
.Rect<double,1>::point_t
is double
; lo
and hi
are double
.If any coordinate of lo
is greater than the same coordinate of hi
, then the Rect
is empty.
Rect boundaries are inclusive. The points lo
and hi
are considered to be inside the Rect. Therefore, Rect
s that contain only a single point, edge, or face are considered non-empty.
Note that this convention differs slightly from conventional "interval" logic on integers, wherein the upper boundary is excluded. This convention was chosen so that adding any point to a Rect as a vertex ensures that the Rect thereafter includes that point. To iterate over the range within an integer Rect, consider using a GridIterator object, which abstracts away the boundary logic for you.
|
inherited |
The type of a point in this object's space.
An N-vector of T if N > 1, otherwise a T.
|
inlineconstexpr |
Construct an empty interval.
Sets lower and upper bounds to the maximum and minimum values of T
, respectively.
A union between this Rect and any finite shape is an identity operation.
Normalize the sign of the region.
If any extent has negative sign (lo > hi), the lo
and hi
coordinates for that axis are swapped. The result is a non-empty Rect.
|
inline |
Center point.
Place a copy at a new location.
Make a new Rect having the same size as this one, but with its center at c
.
c | New center point. |
Box containment.
true
if and only if this Rect
fully contains box
, in other words that there is no point contained by box
which is not contained by this
.
|
inline |
Point containment test.
true
if and only if pt
is inside this rectangle. Points on the surface of the Rect are considered to be contained by it.
|
inlinestatic |
Test whether a point is in the N-dimensional range [lo, hi]
.
If lo
> hi
along any axis, then the range is empty and the function returns false
.
lo | Lower extreme |
hi | Upper extreme |
pt | Test point |
true
if pt
is inside the exremes Morphological dilation.
Return a Rect with the boundary extended coordinate-wise by the amount c
in all directions.
|
inline |
Axial size.
Note that for integer type Rects, since both the high and low boundaries are included, the length along each axis is hi - lo + 1
.
|
inline |
|
inline |
Measure of the axial faces of this Rect.
The i
th component of the result is the area of the face perpendicular to the i
th axis.
Return a rect having the same aspect (ratios of axial lengths) as this one, sized and positioned to minimally contain other
.
The fitted box will be a rigid rescaling and translation of this box. No reflections or rotations will be performed. The signs of the dimensions will be the same as this Rect.
Not available for integral ranges, since in general the aspect can't be preserved.
Zero dimensions will be ignored and not adjusted. To expand the zero dimensions, take the union of other
with the result.
other | Rect to contain. |
Convex shape overlap test.
other
; false otherwise. Range intersection test.
true
if and only if there is a point overlapped by both Rect
s.
|
inline |
Transformed range intersection test.
Alias for box.intersects(*this)
.
|
inline |
Empty region test.
true
if and only if this region contains no points; which will be the case if lo[i] > hi[i]
for any axis i
.
|
inline |
Return a "normalized" length measure encoding the size of this box.
Computed as the N
th root of the volume.
|
inline |
|
inline |
|
inline |
Minkowski sum.
Combine this Rect with another using the Minkowski sum.
|
inline |
Element-wise typecast.
U
. Inequality test.
true
if and only if any extreme of b
is different from the corresponding extreme in this
. Interval intersection.
Compute a Rect representing the area overlapped by both this
and b
. This is the unsigned intersection, which means that an intersection with an empty interval yields another empty interval. If empty intervals should instead subtract from nonempty intervals, use signed_intersection().
The unsigned intersection is the most common form of interval intersection, and is the more efficient of the two.
Interval intersection.
Confine this Rect to the area overlapping b
. This is the unsigned intersection, which means that an intersection with an empty interval yields another empty interval. If empty intervals should instead subtract from nonempty intervals, use signed_intersection().
The unsigned intersection is the most common form of interval intersection, and is the more efficient of the two.
this
for convenience.
|
inline |
|
inline |
Interval cartesian product.
Extrude this Rect into a higher dimension, by treating the extents of r
as the extents along the new dimensions. In other words, concatenate the coordinates of this
and r
into a new Rect.
For example, the product of a 2D rectangle with a 1D range is a 3D box. If multiplied in that order, the product will have the extents of the rectangle along its first two axes and the extents of the 1D range along its third axis.
M | Dimensionality of r . |
Scale transformation.
a | Scale factor. |
a
. Scale transformation.
Scale this Rect about the origin by factor a
.
a | Scale factor |
this
, for convenience. Translation.
dx | Amount by which to translate this region. Add dx to the coordinates of all the bounds. |
Translation.
dx | Amount by which to translate this region. Add dx to the coordinates of all the bounds. |
this
, for convenience. Translation.
dx | Amount by which to translate this region. Subtract dx from the coordinates of all the bounds. |
Interval exclusion.
For any dimension where this
fully contains other
, the result is the empty interval. Any dimension of other
that is empty has no effect.
other | Range to remove from this Rect . |
this
, for convenience. Translation.
dx | Amount by which to translate this region. Subtract dx from the coordinates of all the bounds. |
this
, for convenience. Scale transformation.
a | Scale factor. |
1 / a
. Scale transformation.
Scale this Rect about the origin by factor 1 / a
.
a | Scale factor |
this
, for convenience. Equality test.
true
if and only if all the corresponding extremes of b
are the same. Point union.
this
and the point p
. Interval union.
this
and box b
. Point union.
Extend this
to fully contain p
.
this
, for convenience. Interval union.
Extend this
to fully contain b
.
this
, for convenience. Map the unit interval to the region.
Remap s
on the [0,1]
interval to the extents of this Rect. In other words, interpolate the corners of this Rect using s as an interpolation parameter.
Inverse operation of unmap()
.
Values of s
between 0 and 1 correspond to points inside this Rect.
|
inline |
Map the unit interval to the region, broadcasting to a different dimension.
Requires that N == 1
.
Each coordinate of s
is treated as a fraction within this 1-D Rect.
Reconstruct from corner points.
Re-configure this region to exactly contain the two given points.
|
inline |
Change the size of the region, adjusting about its center.
dim | New lengths along each axis. |
Find p
's fractional position within this Rect.
Inverse operation of remap()
.