PLaSK library
Loading...
Searching...
No Matches
plask::Box2D Struct Reference

Rectangle class. More...

#include <plask/geometry/primitives.hpp>

Public Member Functions

constexpr Vec< 2, doublesize () const
 Get size of box.
 
constexpr double height () const
 Calculate height of this.
 
constexpr double width () const
 Calculate width of this.
 
constexpr Vec< 2, doublecenter () const
 Calculate center point.
 
 Box2D ()
 Construct uninitialized .
 
constexpr Box2D (const Vec< 2, double > &lower, const Vec< 2, double > &upper)
 Construct box.
 
constexpr Box2D (double x_lo, double y_lo, double x_up, double y_up)
 Construct box.
 
bool operator== (const Box2D &r) const
 Compare two boxes, this and r.
 
bool operator!= (const Box2D &r) const
 Compare two boxes, this and r.
 
void fix ()
 Ensure that lower[0] <= upper[0] and lower[1] <= upper[1].
 
bool contains (const Vec< 2, double > &p) const
 Check if the point is inside the box.
 
bool intersects (const Box2D &other) const
 Check if this and other boxes have common points.
 
void makeInclude (const Vec< 2, double > &p)
 Make this box, the minimal one which include this and given point p.
 
void makeInclude (const Box2D &other)
 Make this box, the minimal one which include this and other box.
 
void makeIntersection (const Box2D &other)
 Change this to the biggest box which is included in this and other box.
 
Box2D intersection (Box2D other) const
 Calculate the biggest box which is included in this and other box.
 
Box2D extension (Box2D other) const
 Get the minimal box which include this and other box.
 
Box2D translated (const Vec< 2, double > &translation_vec) const
 Get translated copy of this.
 
Box2D operator+ (const Vec< 2, double > &translation_vec) const
 Get translated copy of this.
 
Box2D operator- (const Vec< 2, double > &translation_vec) const
 Get translated copy of this.
 
Box2D translatedUp (const double trasnalation_in_up_dir) const
 Get translated copy of this.
 
void translate (const Vec< 2, double > &translation_vec)
 Translate this by translation_vec.
 
Box2Doperator+= (const Vec< 2, double > &translation_vec)
 Translate this by translation_vec.
 
Box2Doperator-= (const Vec< 2, double > &translation_vec)
 Translate this by translation_vec.
 
void translateUp (const double trasnalation_in_up_dir)
 Translate this up by trasnalation_in_up_dir.
 
void translateDir (unsigned dir_index, const double trasnalation_in_dir)
 Translate this in dir_index direction by trasnalation_in_dir.
 
Vec< 2, doublemoveInside (Vec< 2, double > p) const
 Translate a point to be inside the box by shifting to the closest edge.
 
bool isValid () const
 Check if this box is valid (non-empty).
 
void makeInvalid ()
 Set this box coordinates to invalid once, so isValid() returns false after this call.
 
double getArea () const
 Calculate area of the box.
 
void flip (size_t flipDir)
 Change i-th coordinate to oposite (mirror).
 
Box2D flipped (size_t i) const
 Get vector similar to this but with changed i-th coordinate to oposite.
 
const doubleleft () const
 Return left edge of the box.
 
doubleleft ()
 Return left edge of the box.
 
const doubleright () const
 Return right edge of the box.
 
doubleright ()
 Return right edge of the box.
 
const doublebottom () const
 Return bottom edge of the box.
 
doublebottom ()
 Return bottom edge of the box.
 
const doubletop () const
 Return top edge of the box.
 
doubletop ()
 Return top edge of the box.
 
void setLeft (double v)
 
void setRight (double v)
 
void setBottom (double v)
 
void setTop (double v)
 
double getLeft () const
 
double getRight () const
 
double getBottom () const
 
double getTop () const
 

Static Public Member Functions

static Box2D invalidInstance ()
 

Public Attributes

Vec< 2, doublelower
 Lower corner of box (with minimal all coordinates).
 
Vec< 2, doubleupper
 Upper corner of box (with maximal all coordinates).
 

Friends

std::ostream & operator<< (std::ostream &out, const Box2D &to_print)
 Print box to stream.
 

Detailed Description

Rectangle class.

Allows for some basic operation on boxes. Has almost identical interface as .

Definition at line 34 of file primitives.hpp.

Constructor & Destructor Documentation

◆ Box2D() [1/3]

plask::Box2D::Box2D ( )
inline

Construct uninitialized .

Definition at line 66 of file primitives.hpp.

◆ Box2D() [2/3]

constexpr plask::Box2D::Box2D ( const Vec< 2, double > &  lower,
const Vec< 2, double > &  upper 
)
inlineconstexpr

Construct box.

Parameters
lowerlower corner of box (with minimal all coordinates)
upperupper corner of box (with maximal all coordinates)

Definition at line 73 of file primitives.hpp.

◆ Box2D() [3/3]

constexpr plask::Box2D::Box2D ( double  x_lo,
double  y_lo,
double  x_up,
double  y_up 
)
inlineconstexpr

Construct box.

Parameters
x_lo,y_lolower corner of box (with minimal all coordinates)
x_up,y_upupper corner of box (with maximal all coordinates)

Definition at line 80 of file primitives.hpp.

Member Function Documentation

◆ bottom() [1/2]

double & plask::Box2D::bottom ( )
inline

Return bottom edge of the box.

Assume that box is already correct.

Returns
bottom edge of the box

Definition at line 340 of file primitives.hpp.

◆ bottom() [2/2]

const double & plask::Box2D::bottom ( ) const
inline

Return bottom edge of the box.

Assume that box is already correct.

Returns
bottom edge of the box

Definition at line 334 of file primitives.hpp.

◆ center()

constexpr Vec< 2, double > plask::Box2D::center ( ) const
inlineconstexpr

Calculate center point.

Returns
center of the box

Definition at line 63 of file primitives.hpp.

◆ contains()

bool plask::Box2D::contains ( const Vec< 2, double > &  p) const

Check if the point is inside the box.

Parameters
ppoint
Returns
true only if point is inside this box

Definition at line 44 of file primitives.cpp.

◆ extension()

Box2D plask::Box2D::extension ( Box2D  other) const

Get the minimal box which include this and other box.

Parameters
otherbox
Returns
the minimal box which include this and other box

Definition at line 82 of file primitives.cpp.

◆ fix()

void plask::Box2D::fix ( )

Ensure that lower[0] <= upper[0] and lower[1] <= upper[1].

Exchange x or y of lower and upper if necessary.

Definition at line 38 of file primitives.cpp.

◆ flip()

void plask::Box2D::flip ( size_t  flipDir)
inline

Change i-th coordinate to oposite (mirror).

WARNING This function does not check if it is valid (for efficiency reasons)

Parameters
flipDirnumber of coordinate

Definition at line 287 of file primitives.hpp.

◆ flipped()

Box2D plask::Box2D::flipped ( size_t  i) const
inline

Get vector similar to this but with changed i-th coordinate to oposite.

WARNING This function does not check if it is valid (for efficiency reasons)

Parameters
inumber of coordinate
Returns
box similar to this but with mirrored i-th coordinate

Definition at line 300 of file primitives.hpp.

◆ getArea()

double plask::Box2D::getArea ( ) const
inline

Calculate area of the box.

Returns
area of the box

Definition at line 277 of file primitives.hpp.

◆ getBottom()

double plask::Box2D::getBottom ( ) const
inline

Definition at line 361 of file primitives.hpp.

◆ getLeft()

double plask::Box2D::getLeft ( ) const
inline

Definition at line 359 of file primitives.hpp.

◆ getRight()

double plask::Box2D::getRight ( ) const
inline

Definition at line 360 of file primitives.hpp.

◆ getTop()

double plask::Box2D::getTop ( ) const
inline

Definition at line 362 of file primitives.hpp.

◆ height()

constexpr double plask::Box2D::height ( ) const
inlineconstexpr

Calculate height of this.

Returns
height of the box

Definition at line 51 of file primitives.hpp.

◆ intersection()

Box2D plask::Box2D::intersection ( Box2D  other) const

Calculate the biggest box which is included in this and other box.

Parameters
otherbox to clip
Returns
the biggest box which is included in this and other box

Definition at line 77 of file primitives.cpp.

◆ intersects()

bool plask::Box2D::intersects ( const Box2D other) const

Check if this and other boxes have common points.

Parameters
otherbox
Returns
true only if this and other have common points

Definition at line 49 of file primitives.cpp.

◆ invalidInstance()

static Box2D plask::Box2D::invalidInstance ( )
inlinestatic

Definition at line 82 of file primitives.hpp.

◆ isValid()

bool plask::Box2D::isValid ( ) const
inline

Check if this box is valid (non-empty).

Valid box has: upper.c0 >= lower.c0 && upper.c1 >= lower.c1

Returns
true only if this box is valid (non-empty)

Definition at line 262 of file primitives.hpp.

◆ left() [1/2]

double & plask::Box2D::left ( )
inline

Return left edge of the box.

Assume that box is already correct.

Returns
left edge of the box

Definition at line 316 of file primitives.hpp.

◆ left() [2/2]

const double & plask::Box2D::left ( ) const
inline

Return left edge of the box.

Assume that box is already correct.

Returns
left edge of the box

Definition at line 310 of file primitives.hpp.

◆ makeInclude() [1/2]

void plask::Box2D::makeInclude ( const Box2D other)

Make this box, the minimal one which include this and other box.

Parameters
otherbox to include in this

Definition at line 63 of file primitives.cpp.

◆ makeInclude() [2/2]

void plask::Box2D::makeInclude ( const Vec< 2, double > &  p)

Make this box, the minimal one which include this and given point p.

Parameters
ppoint which should be inside box

Definition at line 58 of file primitives.cpp.

◆ makeIntersection()

void plask::Box2D::makeIntersection ( const Box2D other)

Change this to the biggest box which is included in this and other box.

Parameters
otherbox to clip this

Definition at line 70 of file primitives.cpp.

◆ makeInvalid()

void plask::Box2D::makeInvalid ( )
inline

Set this box coordinates to invalid once, so isValid() returns false after this call.

See also
isValid()

Definition at line 268 of file primitives.hpp.

◆ moveInside()

Vec< 2, double > plask::Box2D::moveInside ( Vec< 2, double p) const

Translate a point to be inside the box by shifting to the closest edge.

This method assumes that the box is fixed.

Parameters
pgiven point
Returns
point shifted to the boxes

Definition at line 87 of file primitives.cpp.

◆ operator!=()

bool plask::Box2D::operator!= ( const Box2D r) const

Compare two boxes, this and r.

Parameters
rbox to compare
Returns
true only if this box and p don't have equals coordinates

Definition at line 34 of file primitives.cpp.

◆ operator+()

Box2D plask::Box2D::operator+ ( const Vec< 2, double > &  translation_vec) const
inline

Get translated copy of this.

Parameters
translation_vectranslation vector
Returns
this translated by translation_vec

Definition at line 168 of file primitives.hpp.

◆ operator+=()

Box2D & plask::Box2D::operator+= ( const Vec< 2, double > &  translation_vec)
inline

Translate this by translation_vec.

Parameters
translation_vectranslation vector

Definition at line 203 of file primitives.hpp.

◆ operator-()

Box2D plask::Box2D::operator- ( const Vec< 2, double > &  translation_vec) const
inline

Get translated copy of this.

Parameters
translation_vectranslation vector
Returns
this translated by translation_vec

Definition at line 177 of file primitives.hpp.

◆ operator-=()

Box2D & plask::Box2D::operator-= ( const Vec< 2, double > &  translation_vec)
inline

Translate this by translation_vec.

Parameters
translation_vectranslation vector

Definition at line 213 of file primitives.hpp.

◆ operator==()

bool plask::Box2D::operator== ( const Box2D r) const

Compare two boxes, this and r.

Parameters
rbox to compare
Returns
true only if this box and p have equals coordinates

Definition at line 30 of file primitives.cpp.

◆ right() [1/2]

double & plask::Box2D::right ( )
inline

Return right edge of the box.

Assume that box is already correct.

Returns
right edge of the box

Definition at line 328 of file primitives.hpp.

◆ right() [2/2]

const double & plask::Box2D::right ( ) const
inline

Return right edge of the box.

Assume that box is already correct.

Returns
right edge of the box

Definition at line 322 of file primitives.hpp.

◆ setBottom()

void plask::Box2D::setBottom ( double  v)
inline

Definition at line 356 of file primitives.hpp.

◆ setLeft()

void plask::Box2D::setLeft ( double  v)
inline

Definition at line 354 of file primitives.hpp.

◆ setRight()

void plask::Box2D::setRight ( double  v)
inline

Definition at line 355 of file primitives.hpp.

◆ setTop()

void plask::Box2D::setTop ( double  v)
inline

Definition at line 357 of file primitives.hpp.

◆ size()

constexpr Vec< 2, double > plask::Box2D::size ( ) const
inlineconstexpr

Get size of box.

Returns
size of box (its width and height)

Definition at line 45 of file primitives.hpp.

◆ top() [1/2]

double & plask::Box2D::top ( )
inline

Return top edge of the box.

Assume that box is already correct.

Returns
top edge of the box

Definition at line 352 of file primitives.hpp.

◆ top() [2/2]

const double & plask::Box2D::top ( ) const
inline

Return top edge of the box.

Assume that box is already correct.

Returns
top edge of the box

Definition at line 346 of file primitives.hpp.

◆ translate()

void plask::Box2D::translate ( const Vec< 2, double > &  translation_vec)
inline

Translate this by translation_vec.

Parameters
translation_vectranslation vector

Definition at line 194 of file primitives.hpp.

◆ translated()

Box2D plask::Box2D::translated ( const Vec< 2, double > &  translation_vec) const
inline

Get translated copy of this.

Parameters
translation_vectranslation vector
Returns
this translated by translation_vec

Definition at line 159 of file primitives.hpp.

◆ translateDir()

void plask::Box2D::translateDir ( unsigned  dir_index,
const double  trasnalation_in_dir 
)
inline

Translate this in dir_index direction by trasnalation_in_dir.

Parameters
dir_indexdirection index, 0 or 1
trasnalation_in_dirtranslation in dir_index direction

Definition at line 233 of file primitives.hpp.

◆ translatedUp()

Box2D plask::Box2D::translatedUp ( const double  trasnalation_in_up_dir) const
inline

Get translated copy of this.

Parameters
trasnalation_in_up_dirtranslation in up direction
Returns
this translated up by trasnalation_in_up_dir

Definition at line 186 of file primitives.hpp.

◆ translateUp()

void plask::Box2D::translateUp ( const double  trasnalation_in_up_dir)
inline

Translate this up by trasnalation_in_up_dir.

Parameters
trasnalation_in_up_dirtranslation in up direction

Definition at line 223 of file primitives.hpp.

◆ width()

constexpr double plask::Box2D::width ( ) const
inlineconstexpr

Calculate width of this.

Returns
width of the box

Definition at line 57 of file primitives.hpp.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const Box2D to_print 
)
friend

Print box to stream.

Parameters
outprint destination, output stream
to_printbox to print
Returns
out stream

Definition at line 252 of file primitives.hpp.

Member Data Documentation

◆ lower

Vec<2, double> plask::Box2D::lower

Lower corner of box (with minimal all coordinates).

Definition at line 36 of file primitives.hpp.

◆ upper

Vec<2, double> plask::Box2D::upper

Upper corner of box (with maximal all coordinates).

Definition at line 39 of file primitives.hpp.


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