PLaSK library
|
Rectangle class. More...
#include <plask/geometry/primitives.hpp>
Public Member Functions | |
constexpr Vec< 2, double > | size () const |
Get size of box. | |
constexpr double | height () const |
Calculate height of this. | |
constexpr double | width () const |
Calculate width of this. | |
constexpr Vec< 2, double > | center () 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 . | |
Box2D & | operator+= (const Vec< 2, double > &translation_vec) |
Translate this by translation_vec . | |
Box2D & | operator-= (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, double > | moveInside (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 double & | left () const |
Return left edge of the box. | |
double & | left () |
Return left edge of the box. | |
const double & | right () const |
Return right edge of the box. | |
double & | right () |
Return right edge of the box. | |
const double & | bottom () const |
Return bottom edge of the box. | |
double & | bottom () |
Return bottom edge of the box. | |
const double & | top () const |
Return top edge of the box. | |
double & | top () |
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, double > | lower |
Lower corner of box (with minimal all coordinates). | |
Vec< 2, double > | upper |
Upper corner of box (with maximal all coordinates). | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Box2D &to_print) |
Print box to stream. | |
Rectangle class.
Allows for some basic operation on boxes. Has almost identical interface as .
Definition at line 34 of file primitives.hpp.
|
inline |
Construct uninitialized .
Definition at line 66 of file primitives.hpp.
|
inlineconstexpr |
Construct box.
lower | lower corner of box (with minimal all coordinates) |
upper | upper corner of box (with maximal all coordinates) |
Definition at line 73 of file primitives.hpp.
|
inlineconstexpr |
Construct box.
x_lo,y_lo | lower corner of box (with minimal all coordinates) |
x_up,y_up | upper corner of box (with maximal all coordinates) |
Definition at line 80 of file primitives.hpp.
|
inline |
Return bottom edge of the box.
Assume that box is already correct.
Definition at line 340 of file primitives.hpp.
Return bottom edge of the box.
Assume that box is already correct.
Definition at line 334 of file primitives.hpp.
Check if the point is inside the box.
p | point |
Definition at line 44 of file primitives.cpp.
Get the minimal box which include this
and other
box.
other | box |
this
and other
box Definition at line 82 of file primitives.cpp.
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.
|
inline |
Change i-th coordinate to oposite (mirror).
WARNING This function does not check if it is valid (for efficiency reasons)
flipDir | number of coordinate |
Definition at line 287 of file primitives.hpp.
|
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)
i | number of coordinate |
Definition at line 300 of file primitives.hpp.
|
inline |
|
inline |
Definition at line 361 of file primitives.hpp.
|
inline |
Definition at line 359 of file primitives.hpp.
|
inline |
Definition at line 360 of file primitives.hpp.
|
inline |
Definition at line 362 of file primitives.hpp.
Calculate the biggest box which is included in this and other
box.
other | box to clip |
other
box Definition at line 77 of file primitives.cpp.
Check if this and other boxes have common points.
other | box |
Definition at line 49 of file primitives.cpp.
|
inlinestatic |
Definition at line 82 of file primitives.hpp.
|
inline |
Check if this box is valid (non-empty).
Valid box has: upper.c0 >= lower.c0 && upper.c1 >= lower.c1
true
only if this box is valid (non-empty) Definition at line 262 of file primitives.hpp.
|
inline |
Return left edge of the box.
Assume that box is already correct.
Definition at line 316 of file primitives.hpp.
Return left edge of the box.
Assume that box is already correct.
Definition at line 310 of file primitives.hpp.
Make this box, the minimal one which include this
and other
box.
other | box to include in this |
Definition at line 63 of file primitives.cpp.
Make this box, the minimal one which include this
and given point p
.
p | point which should be inside box |
Definition at line 58 of file primitives.cpp.
Change this to the biggest box which is included in this and other
box.
other | box to clip this |
Definition at line 70 of file primitives.cpp.
|
inline |
Set this box coordinates to invalid once, so isValid() returns false
after this call.
Definition at line 268 of file primitives.hpp.
Translate a point to be inside the box by shifting to the closest edge.
This method assumes that the box is fixed.
p | given point |
Definition at line 87 of file primitives.cpp.
Compare two boxes, this
and r
.
r | box to compare |
true
only if this
box and p
don't have equals coordinates Definition at line 34 of file primitives.cpp.
Get translated copy of this.
translation_vec | translation vector |
translation_vec
Definition at line 168 of file primitives.hpp.
Translate this by translation_vec
.
translation_vec | translation vector |
Definition at line 203 of file primitives.hpp.
Get translated copy of this.
translation_vec | translation vector |
translation_vec
Definition at line 177 of file primitives.hpp.
Translate this by translation_vec
.
translation_vec | translation vector |
Definition at line 213 of file primitives.hpp.
Compare two boxes, this
and r
.
r | box to compare |
this
box and p
have equals coordinates Definition at line 30 of file primitives.cpp.
|
inline |
Return right edge of the box.
Assume that box is already correct.
Definition at line 328 of file primitives.hpp.
Return right edge of the box.
Assume that box is already correct.
Definition at line 322 of file primitives.hpp.
Definition at line 356 of file primitives.hpp.
Definition at line 354 of file primitives.hpp.
Definition at line 355 of file primitives.hpp.
Definition at line 357 of file primitives.hpp.
Get size of box.
Definition at line 45 of file primitives.hpp.
|
inline |
Return top edge of the box.
Assume that box is already correct.
Definition at line 352 of file primitives.hpp.
Return top edge of the box.
Assume that box is already correct.
Definition at line 346 of file primitives.hpp.
Translate this by translation_vec
.
translation_vec | translation vector |
Definition at line 194 of file primitives.hpp.
Get translated copy of this.
translation_vec | translation vector |
translation_vec
Definition at line 159 of file primitives.hpp.
Translate this in dir_index
direction by trasnalation_in_dir
.
dir_index | direction index, 0 or 1 |
trasnalation_in_dir | translation in dir_index direction |
Definition at line 233 of file primitives.hpp.
Get translated copy of this.
trasnalation_in_up_dir | translation in up direction |
trasnalation_in_up_dir
Definition at line 186 of file primitives.hpp.
Translate this up by trasnalation_in_up_dir
.
trasnalation_in_up_dir | translation in up direction |
Definition at line 223 of file primitives.hpp.
Print box to stream.
out | print destination, output stream |
to_print | box to print |
Definition at line 252 of file primitives.hpp.
Lower corner of box (with minimal all coordinates).
Definition at line 36 of file primitives.hpp.
Upper corner of box (with maximal all coordinates).
Definition at line 39 of file primitives.hpp.