Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Geom::Rect Class Reference

Axis aligned, non-empty rectangle. More...

#include <rect.h>

Inheritance diagram for Geom::Rect:
Geom::GenericRect< Coord >

Public Member Functions

Create rectangles.
 Rect ()
 Create a rectangle that contains only the point at (0,0).
 
 Rect (Interval const &a, Interval const &b)
 Create a rectangle from X and Y intervals.
 
 Rect (Point const &a, Point const &b)
 Create a rectangle from two points.
 
 Rect (Coord x0, Coord y0, Coord x1, Coord y1)
 
 Rect (Base const &b)
 
 Rect (IntRect const &ir)
 
Inspect dimensions.
bool hasZeroArea (Coord eps=EPSILON) const
 Check whether the rectangle has zero area up to specified tolerance.
 
bool isFinite () const
 Check whether the rectangle has finite area.
 
Coord diameter () const
 Calculate the diameter of the smallest circle that would contain the rectangle.
 
Test other rectangles and points for inclusion.
bool interiorIntersects (Rect const &r) const
 Check whether the interiors of the rectangles have any common points.
 
bool interiorContains (Point const &p) const
 Check whether the interior includes the given point.
 
bool interiorContains (Rect const &r) const
 Check whether the interior includes all points in the given rectangle.
 
bool interiorContains (OptRect const &r) const
 
Rounding to integer coordinates
IntRect roundOutwards () const
 Return the smallest integer rectangle which contains this one.
 
OptIntRect roundInwards () const
 Return the largest integer rectangle which is contained in this one.
 
Return an expanded or shrunk copy of the rectangle.
Rect expandedBy (Coord amount) const
 Return a new rectangle which results from expanding this one by the same amount along both axes.
 
Rect expandedBy (Coord x, Coord y) const
 Return a new rectangle which results from expanding this one by possibly different amounts along both axes.
 
Rect shrunkBy (Coord amount) const
 Return a new rectangle which results from shrinking this one by the same amount along both axes.
 
Rect shrunkBy (Coord x, Coord y) const
 Return a new rectangle which results from shrinking this one by possibly different amounts along both axes.
 
SVG viewbox functionality.
Affine transformTo (Rect const &viewport, Aspect const &aspect=Aspect()) const
 Transform contents to viewport.
 
Operators
Rectoperator*= (Affine const &m)
 Transform the rectangle by an affine.
 
bool operator== (IntRect const &ir) const
 
bool operator== (Rect const &other) const
 
- Public Member Functions inherited from Geom::GenericRect< Coord >
CIntervaloperator[] (unsigned i)
 
CInterval const & operator[] (unsigned i) const
 
CIntervaloperator[] (Dim2 d)
 
CInterval const & operator[] (Dim2 d) const
 
CPoint min () const
 Get the corner of the rectangle with smallest coordinate values.
 
CPoint max () const
 Get the corner of the rectangle with largest coordinate values.
 
CPoint corner (unsigned i) const
 Return the n-th corner of the rectangle.
 
Coord top () const
 Return top coordinate of the rectangle (+Y is downwards).
 
Coord bottom () const
 Return bottom coordinate of the rectangle (+Y is downwards).
 
Coord left () const
 Return leftmost coordinate of the rectangle (+X is to the right).
 
Coord right () const
 Return rightmost coordinate of the rectangle (+X is to the right).
 
Coord width () const
 Get the horizontal extent of the rectangle.
 
Coord height () const
 Get the vertical extent of the rectangle.
 
Coord aspectRatio () const
 Get the ratio of width to height of the rectangle.
 
CPoint dimensions () const
 Get rectangle's width and height as a point.
 
CPoint midpoint () const
 Get the point in the geometric center of the rectangle.
 
Coord area () const
 Compute the rectangle's area.
 
bool hasZeroArea () const
 Check whether the rectangle has zero area.
 
Coord maxExtent () const
 Get the larger extent (width or height) of the rectangle.
 
Coord minExtent () const
 Get the smaller extent (width or height) of the rectangle.
 
Coord distanceSq (CPoint const &p) const
 Get rectangle's distance SQUARED away from the given point.
 
CPoint clamp (CPoint const &p) const
 Clamp point to the rectangle.
 
CPoint nearestEdgePoint (CPoint const &p) const
 Get the nearest point on the edge of the rectangle.
 
bool intersects (GenericRect< Coord > const &r) const
 Check whether the rectangles have any common points.
 
bool intersects (OptCRect const &r) const
 Check whether the rectangles have any common points.
 
bool contains (GenericRect< Coord > const &r) const
 Check whether the rectangle includes all points in the given rectangle.
 
bool contains (OptCRect const &r) const
 Check whether the rectangle includes all points in the given rectangle.
 
bool contains (CPoint const &p) const
 Check whether the given point is within the rectangle.
 
void setLeft (Coord val)
 Set the minimum X coordinate of the rectangle.
 
void setRight (Coord val)
 Set the maximum X coordinate of the rectangle.
 
void setTop (Coord val)
 Set the minimum Y coordinate of the rectangle.
 
void setBottom (Coord val)
 Set the maximum Y coordinate of the rectangle.
 
void setMin (CPoint const &p)
 Set the upper left point of the rectangle.
 
void setMax (CPoint const &p)
 Set the lower right point of the rectangle.
 
void expandTo (CPoint const &p)
 Enlarge the rectangle to contain the given point.
 
void unionWith (CRect const &b)
 Enlarge the rectangle to contain the argument.
 
void unionWith (OptCRect const &b)
 Enlarge the rectangle to contain the argument.
 
void expandBy (Coord amount)
 Expand the rectangle in both directions by the specified amount.
 
void expandBy (Coord x, Coord y)
 Expand the rectangle in both directions.
 
void expandBy (CPoint const &p)
 Expand the rectangle by the coordinates of the given point.
 
void shrinkBy (Coord amount)
 Shrink the rectangle in both directions by the specified amount.
 
void shrinkBy (Coord x, Coord y)
 Shrink the rectangle in both directions by possibly different amounts.
 
GenericRect< Coord > & operator+= (CPoint const &p)
 Offset the rectangle by a vector.
 
GenericRect< Coord > & operator-= (CPoint const &p)
 Offset the rectangle by the negation of a vector.
 
GenericRect< Coord > & operator|= (CRect const &o)
 Union two rectangles.
 
GenericRect< Coord > & operator|= (OptCRect const &o)
 
bool operator== (CRect const &o) const
 Test for equality of rectangles.
 
 GenericRect ()=default
 Create a rectangle that contains only the point at (0, 0).
 
 GenericRect (CInterval const &a, CInterval const &b)
 Create a rectangle from X and Y intervals.
 
 GenericRect (CPoint const &a, CPoint const &b)
 Create a rectangle from two points.
 
 GenericRect (Coord x0, Coord y0, Coord x1, Coord y1)
 Create rectangle from coordinates of two points.
 

Private Types

typedef GenericRect< CoordBase
 

Related Symbols

(Note that these are not member symbols.)

Coord distance (Point const &p, Rect const &rect)
 Returns the smallest distance between p and rect.
 

Additional Inherited Members

- Public Types inherited from Geom::GenericRect< Coord >
using D1Value = CInterval
 
using D1Reference = CInterval &
 
using D1ConstReference = CInterval const &
 
- Static Public Member Functions inherited from Geom::GenericRect< Coord >
static CRect from_range (InputIterator start, InputIterator end)
 Create a rectangle from a range of points.
 
static CRect from_array (CPoint const *c, unsigned n)
 Create a rectangle from a C-style array of points it should contain.
 
static CRect from_xywh (Coord x, Coord y, Coord w, Coord h)
 Create rectangle from origin and dimensions.
 
static CRect from_xywh (CPoint const &xy, CPoint const &wh)
 Create rectangle from origin and dimensions.
 
static CRect infinite ()
 Create infinite rectangle.
 
- Protected Attributes inherited from Geom::GenericRect< Coord >
CInterval f [2]
 

Detailed Description

Axis aligned, non-empty rectangle.

Definition at line 90 of file rect.h.

Member Typedef Documentation

◆ Base

Definition at line 93 of file rect.h.

Constructor & Destructor Documentation

◆ Rect() [1/6]

Geom::Rect::Rect ( )
inline

Create a rectangle that contains only the point at (0,0).

Definition at line 98 of file rect.h.

◆ Rect() [2/6]

Geom::Rect::Rect ( Interval const &  a,
Interval const &  b 
)
inline

Create a rectangle from X and Y intervals.

Definition at line 100 of file rect.h.

◆ Rect() [3/6]

Geom::Rect::Rect ( Point const &  a,
Point const &  b 
)
inline

Create a rectangle from two points.

Definition at line 102 of file rect.h.

◆ Rect() [4/6]

Geom::Rect::Rect ( Coord  x0,
Coord  y0,
Coord  x1,
Coord  y1 
)
inline

Definition at line 103 of file rect.h.

◆ Rect() [5/6]

Geom::Rect::Rect ( Base const &  b)
inline

Definition at line 104 of file rect.h.

◆ Rect() [6/6]

Geom::Rect::Rect ( IntRect const &  ir)
inline

Definition at line 105 of file rect.h.

Member Function Documentation

◆ diameter()

Coord Geom::Rect::diameter ( ) const
inline

Calculate the diameter of the smallest circle that would contain the rectangle.

Definition at line 117 of file rect.h.

References Geom::GenericRect< Coord >::corner(), and distance().

◆ expandedBy() [1/2]

Rect Geom::Rect::expandedBy ( Coord  amount) const

Return a new rectangle which results from expanding this one by the same amount along both axes.

Definition at line 130 of file rect.cpp.

◆ expandedBy() [2/2]

Rect Geom::Rect::expandedBy ( Coord  x,
Coord  y 
) const

Return a new rectangle which results from expanding this one by possibly different amounts along both axes.

Definition at line 137 of file rect.cpp.

◆ hasZeroArea()

bool Geom::Rect::hasZeroArea ( Coord  eps = EPSILON) const
inline

Check whether the rectangle has zero area up to specified tolerance.

Parameters
epsMaximum value of the area to consider empty
Returns
True if rectangle has an area smaller than tolerance, false otherwise

Definition at line 113 of file rect.h.

References Geom::GenericRect< Coord >::area().

Referenced by Inkscape::UI::Dialog::Export::exportRaster(), Inkscape::UI::Tools::fit_item(), SPItem::getCenter(), Inkscape::UI::Dialog::ExportPreview::setBox(), SPItem::setCenter(), sp_export_png_file(), and sp_generate_internal_bitmap().

◆ interiorContains() [1/3]

bool Geom::Rect::interiorContains ( OptRect const &  r) const
inline

Definition at line 240 of file rect.h.

References interiorContains().

◆ interiorContains() [2/3]

bool Geom::Rect::interiorContains ( Point const &  p) const
inline

Check whether the interior includes the given point.

Definition at line 127 of file rect.h.

References Geom::GenericRect< Coord >::f, Geom::X, and Geom::Y.

Referenced by interiorContains(), wrap_interiorContains_coord(), and wrap_interiorContains_ivl().

◆ interiorContains() [3/3]

bool Geom::Rect::interiorContains ( Rect const &  r) const
inline

Check whether the interior includes all points in the given rectangle.

Interior of the rectangle is the entire rectangle without its borders.

Definition at line 132 of file rect.h.

References Geom::GenericRect< Coord >::f, Geom::X, and Geom::Y.

◆ interiorIntersects()

bool Geom::Rect::interiorIntersects ( Rect const &  r) const
inline

Check whether the interiors of the rectangles have any common points.

Definition at line 123 of file rect.h.

References Geom::GenericRect< Coord >::f, Geom::X, and Geom::Y.

◆ isFinite()

bool Geom::Rect::isFinite ( ) const
inline

Check whether the rectangle has finite area.

Definition at line 115 of file rect.h.

References Geom::X, and Geom::Y.

◆ operator*=()

Rect & Geom::Rect::operator*= ( Affine const &  m)

Transform the rectangle by an affine.

The result of the transformation might not be axis-aligned. The return value of this operation will be the smallest axis-aligned rectangle containing all points of the true result.

Definition at line 87 of file rect.cpp.

References Geom::GenericRect< Coord >::corner(), Geom::GenericRect< Coord >::f, Geom::X, and Geom::Y.

◆ operator==() [1/2]

bool Geom::Rect::operator== ( IntRect const &  ir) const
inline

Definition at line 188 of file rect.h.

References Geom::GenericRect< Coord >::f, Geom::X, and Geom::Y.

◆ operator==() [2/2]

bool Geom::Rect::operator== ( Rect const &  other) const
inline

Definition at line 191 of file rect.h.

References Geom::GenericRect< Coord >::operator==().

◆ roundInwards()

OptIntRect Geom::Rect::roundInwards ( ) const
inline

Return the largest integer rectangle which is contained in this one.

Definition at line 146 of file rect.h.

References Geom::GenericRect< Coord >::f, roundInwards(), Geom::X, and Geom::Y.

Referenced by roundInwards(), and Geom::TEST().

◆ roundOutwards()

◆ shrunkBy() [1/2]

Rect Geom::Rect::shrunkBy ( Coord  amount) const

Return a new rectangle which results from shrinking this one by the same amount along both axes.

Definition at line 144 of file rect.cpp.

Referenced by Inkscape::UI::Widget::ColorPlate::get_area(), Inkscape::UI::Widget::round_rect(), and Inkscape::Util::rounded_rectangle().

◆ shrunkBy() [2/2]

Rect Geom::Rect::shrunkBy ( Coord  x,
Coord  y 
) const

Return a new rectangle which results from shrinking this one by possibly different amounts along both axes.

Definition at line 151 of file rect.cpp.

◆ transformTo()

Affine Geom::Rect::transformTo ( Rect const &  viewport,
Aspect const &  aspect = Aspect() 
) const

Transform contents to viewport.

Computes an affine that transforms the contents of this rectangle to the specified viewport. The aspect parameter specifies how to to the transformation (whether the aspect ratio of content should be kept and where it should be placed in the viewport).

Definition at line 99 of file rect.cpp.

References Geom::Aspect::align, Geom::align_factors(), Geom::ALIGN_NONE, Geom::GenericRect< Coord >::dimensions(), Geom::GenericRect< C >::dimensions(), Geom::Aspect::expansion, Geom::EXPANSION_MEET, Geom::GenericRect< C >::min(), Geom::GenericRect< Coord >::min(), offset, scale, Geom::X, and Geom::Y.

Friends And Related Symbol Documentation

◆ distance()

Coord distance ( Point const &  p,
Rect const &  rect 
)
related

Returns the smallest distance between p and rect.

Definition at line 176 of file rect.cpp.

References Geom::GenericRect< C >::bottom(), Geom::GenericRect< C >::left(), Geom::GenericRect< C >::right(), Geom::GenericRect< C >::top(), Geom::X, and Geom::Y.

Referenced by diameter().


The documentation for this class was generated from the following files: