ImFusion SDK 4.3
AlignedRectangle2D Class Reference

#include <ImFusion/Core/Geometry/Rectangle.h>

Class representing an axis aligned rectangle in 2D space. More...

Detailed Description

Class representing an axis aligned rectangle in 2D space.

The coordinate convention for this class is bottom <= top and left <= right, both of which are enforced in the constructor. Unless stated otherwise, all operations that involve comparisons use the same tolerance epsilon as vec3::isApprox (which is 1e-12).

See also
Intersections between geometry primitives can be computed using the sets of free functions Geometry::intersection() and Geometry::intersects().

Public Member Functions

 AlignedRectangle2D (const vec2 &lowerLeft, const vec2 &upperRight)
 
 AlignedRectangle2D (const AlignedRectangle2D &)=default
 
AlignedRectangle2Doperator= (const AlignedRectangle2D &)=default
 
bool operator== (const AlignedRectangle2D &) const
 
bool operator!= (const AlignedRectangle2D &) const
 
bool isApprox (const AlignedRectangle2D &) const
 
bool includesPoint (const vec2 &point) const
 
vec2 closestPoint (const vec2 &point) const
 
double distanceToPoint (const vec2 &point) const
 
Utils::Variant< std::pair< double, double >, double, std::nullptr_tlineSegmentIntersection (const vec2 &lineStart, const vec2 &lineEnd, bool extentToInfiniteLine=false) const
 Finds the intersection with a 2D line segment defined by its end points.
 
bool intersectsDisk (const vec2 &center, double radius) const
 Checks if the rectangle overlaps with a given disk.
 
const vec2 & lowerLeft () const
 
const vec2 & upperRight () const
 
double left () const
 
double right () const
 
double top () const
 
double bottom () const
 
double width () const
 
double height () const
 
vec2 center () const
 
vec2 extent () const
 

Static Public Member Functions

static AlignedRectangle2D fromXYWidthHeight (double x, double y, double width, double height)
 Create a rectangle by providing the x and y coordintes of the lower-left corner and a width and height.
 
static AlignedRectangle2D fromCenterExtent (vec2 center, vec2 extent)
 Create a rectangle by providing the point in the center and an extent (i.e. width and height).
 

Member Function Documentation

◆ lineSegmentIntersection()

Utils::Variant< std::pair< double, double >, double, std::nullptr_t > lineSegmentIntersection ( const vec2 & lineStart,
const vec2 & lineEnd,
bool extentToInfiniteLine = false ) const

Finds the intersection with a 2D line segment defined by its end points.

Objects involving NAN will never intersect. Returns one or more lambda values (such that p = lineStart + lambda * (lineEnd - lineStart)) for the start and end of the intersection, or nullptr in case of no intersection

◆ intersectsDisk()

bool intersectsDisk ( const vec2 & center,
double radius ) const

Checks if the rectangle overlaps with a given disk.

Note that negative radius causes undefined behaviour.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close