geomc 1.0
A c++ linear algebra template library
|
An N-dimensional axis-aligned interval. More...
#include <geomc/shape/Rect.h>
Public Types | |
typedef PointType< T, N >::point_t | point_t |
Type of object confined by this Rect. | |
typedef T | elem_t |
The coordinate type of this shape. | |
Public Member Functions | |
constexpr | Rect () |
Construct an empty interval. More... | |
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. More... | |
constexpr | Rect (point_t p) |
Construct a Rect containing only the point p . | |
Rect< T, N > | operator| (const Rect< T, N > &b) const |
Interval union. More... | |
Rect< T, N > & | operator|= (const Rect< T, N > &b) |
Interval union. More... | |
Rect< T, N > | operator| (const point_t &p) |
Point union. More... | |
Rect< T, N > & | operator|= (const point_t &p) |
Point union. More... | |
Rect< T, N > | operator& (const Rect< T, N > &b) const |
Interval intersection. More... | |
Rect< T, N > & | operator&= (const Rect< T, N > &b) |
Interval intersection. More... | |
Rect< T, N > | operator+ (point_t dx) const |
Translation. More... | |
Rect< T, N > | operator- (point_t dx) const |
Translation. More... | |
Rect< T, N > & | operator+= (point_t dx) |
Translation. More... | |
Rect< T, N > & | operator-= (point_t dx) |
Translation. More... | |
Rect< T, N > | operator- (const Rect< T, N > &other) |
Interval exclusion. More... | |
Rect< T, N > & | operator-= (const Rect< T, N > &other) |
Interval exclusion. More... | |
bool | operator== (Rect< T, N > b) const |
Equality test. More... | |
bool | operator!= (Rect< T, N > b) const |
Inequality test. More... | |
Rect< T, N > | operator* (point_t a) const |
Scale transformation. More... | |
Rect< T, N > & | operator*= (point_t a) |
Scale transformation. More... | |
Rect< T, N > | operator/ (point_t a) const |
Scale transformation. More... | |
Rect< T, N > & | operator/= (point_t a) |
Scale transformation. More... | |
template<index_t M> | |
Rect< T, M+N > | operator* (const Rect< T, M > &r) const |
Interval cartesian product. More... | |
template<typename U , index_t M> | |
operator Rect< U, M > () const | |
Element-wise typecast. More... | |
bool | contains (point_t pt) const |
Point containment test. More... | |
bool | contains (const Rect< T, N > &box) const |
Box containment. More... | |
Rect< T, 1 > | axis (size_t k) const |
Return the one dimensional range spanned along axis k . | |
bool | intersects (const Rect< T, N > &box) const |
Range intersection test. More... | |
point_t | center () const |
Center point. More... | |
point_t | dimensions () const |
Axial size. More... | |
void | set_dimensions (point_t dim) |
Change the size of the region, adjusting about its center. More... | |
void | set_corners (point_t corner1, point_t corner2) |
Reconstruct from corner points. More... | |
Rect< T, N > | centered_on (point_t c) const |
Place a copy at a new location. More... | |
Rect< T, N > | dilated (point_t c) const |
Morphological dilation. More... | |
Rect< T, N > | minkowski_sum (const Rect< T, N > &other) const |
Minkowski sum. More... | |
T | volume () const |
N-dimensional volume. More... | |
bool | is_empty () const |
Empty region test. More... | |
point_t | clip (point_t p) const |
Clamp the coordinates of p to lie within this Rect. More... | |
point_t | project (point_t p) const |
Return the point on the surface of the shape which is nearest to p . More... | |
T | sdf (point_t p) const |
Return the signed distance to the surface of the shape. | |
T | dist2 (point_t p) const |
Squared distance to the interior of the Rect. More... | |
point_t | remap (point_t s) const |
Map the unit interval to the region. More... | |
point_t | unmap (point_t p) const |
Find p 's fractional position within this Rect. More... | |
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. | |
point_t | convex_support (point_t d) const |
Rect< T, 1 > | intersect (const Ray< T, N > &r) const |
Ray-shape intersection test. | |
Rect< T, N > | bounds () const |
bool | intersects (const Convex< T, N, Shape > &other) const |
Convex shape overlap test. More... | |
Vec< T, N > | normal (Vec< T, N > p) const |
Unit-length outward-facing direction. More... | |
Static Public Member Functions | |
static Rect< T, N > | from_center (typename Rect< T, N >::point_t c, typename Rect< T, N >::point_t dims) |
Construct a Rect from a center point and extent. More... | |
static Rect< T, N > | from_corner (typename Rect< T, N >::point_t corner, typename Rect< T, N >::point_t dims) |
Construct a Rect from a corner point and an extent. More... | |
static Rect< T, N > | spanning_corners (point_t c1, point_t c2) |
Construct a Rect containing the two corners c1 and c2 . More... | |
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 . More... | |
static bool | contains (typename Rect< T, N >::point_t lo, typename Rect< T, N >::point_t hi, typename Rect< T, N >::point_t pt) |
Test whether a point is in the N-dimensional range [lo, hi] . More... | |
Public Attributes | |
point_t | lo |
Lower extremes. | |
point_t | hi |
Upper extremes. | |
Static Public Attributes | |
static const point_t | endpoint_measure |
static const Rect< T, N > | unit_interval = Rect<T,N>((T)0, (T)1) |
A Rect covering the range [0, 1] along all axes. | |
static const Rect< T, N > | signed_unit_interval = Rect<T,N>((T)-1, (T)1) |
A Rect covering the range [-1, 1] along all axes. | |
static const Rect< T, N > | full |
A Rect that contains all points. More... | |
static const Rect< T, N > | empty |
A Rect that contains no points. More... | |
static constexpr size_t | N = _N |
The dimension of this shape. | |
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.
|
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.
|
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 |
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 |
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
. Minkowski sum.
Combine this Rect with another using the Minkowski sum.
Unit-length outward-facing direction.
For any point, return the direction which points directly away from the nearest point on the shape, away from its interior.
This should be the same as the gradient of the sdf().
|
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. 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. 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. |
|
inline |
N-dimensional volume.
Compute the measure of the region contained by this Rect as the product of its dimensions. Result measures a length if N
is 1; an area if N
is 2; a volume if 3; etc.
A Rect that contains no points.
A Rect that contains all points.