28 # pragma warning (disable : 4127)
54 const float p,
bool clipGreater,
int axis,
63 float negate = clipGreater ? -1 : 1;
66 for (i0 = 0; (i0 < inPoly.
length()) && c1; ++i0) {
68 c1 = (negate * pt1[axis]) < (negate * p);
86 for (
int i = 1; i <= inPoly.
length(); ++i) {
87 T pt2 = inPoly[(i + i0) % inPoly.
length()];
88 bool c2 = (negate * pt2[axis]) < (negate * p);
92 if (!c1 && c2 && (i > 1)) {
101 if (pt2[axis] == pt1[axis]) {
104 alpha = (p - pt1[axis]) / (pt2[axis] - pt1[axis]);
107 }
else if (! (c1 || c2) && (i != 1)) {
164 return max.
x - min.
x;
172 return max.
y - min.
y;
220 return (max + min) * 0.5;
261 return xyxy(x, y, x + w, y + h);
277 return (v.
x >= min.
x) && (v.
y >= min.
y) && (v.
x <= max.
x) && (v.
y <= max.
y);
282 return (min.
x <= r.
min.
x) && (min.
y <= r.
min.
y) &&
291 return (min.
x < r.
max.
x) && (min.
y < r.
max.
y) &&
298 return (min.
x <= r.
max.
x) && (min.
y <= r.
max.
y) &&
303 return xyxy(min.
x * s, min.
y * s, max.
x * s, max.
y * s);
307 return xyxy(min * s, max * s);
311 return xyxy(min / s, max / s);
315 return xyxy(min / s, max / s);
319 return xyxy(min + v, max + v);
323 return xyxy(min - v, max - v);
327 return (min == other.
min) && (max == other.
max);
331 return (min != other.
min) || (max != other.
max);
362 width() - 2.0f * delta,
369 float newX =
x0() - delta;
370 float newY =
y0() - delta;
371 float newW =
width() + 2.0f * delta;
372 float newH =
height() + 2.0f * delta;
375 newX = (
x0() +
width()) / 2.0f;
389 }
else if (! other.
isEmpty()) {
414 const bool greaterThan =
true;
415 const bool lessThan =
false;
421 bool entirelyClipped =
427 if (entirelyClipped) {
438 float textureAspect = hh / ww;
441 if (viewAspect > textureAspect) {
443 float h =
width() * textureAspect;
448 float w =
height() / textureAspect;
449 float x = (
width() - w) / 2;
Vector2 extent() const
Definition: Rect2D.h:146
bool operator!=(const Rect2D &other) const
Definition: Rect2D.h:330
float area() const
Definition: Rect2D.h:223
class Rect2D AABox2D
Definition: Box2D.h:24
Rect2D operator/(const Vector2 &s) const
Definition: Rect2D.h:314
Rect2D operator/(float s) const
Definition: Rect2D.h:310
void clip(const Array< T > &inPoly, Array< T > &outPoly) const
Definition: Rect2D.h:412
Vector2 wh() const
Definition: Rect2D.h:211
float fnan()
Definition: g3dmath.cpp:82
Point2 corner(int i) const
Definition: Rect2D.h:339
float y0() const
Definition: Rect2D.h:184
bool intersects(const Rect2D &r) const
Definition: Rect2D.h:289
bool isFinite() const
Definition: Rect2D.h:227
bool isFinite() const
Definition: Vector2.h:476
Point2 x0y1() const
Definition: Rect2D.h:201
#define X
Definition: CollisionDetection.cpp:2281
static bool clipSide2D(const float p, bool clipGreater, int axis, const Array< T > &inPoly, Array< T > &outPoly)
Definition: Rect2D.h:53
Vector2 min(const Vector2 &v) const
Definition: Vector2.h:452
static Rect2D inf()
Definition: Rect2D.h:271
Rect2D operator*(float s) const
Definition: Rect2D.h:302
Rect2D(bool)
Definition: Rect2D.h:121
Rect2D largestCenteredSubRect(float ww, float hh) const
Definition: Rect2D.h:437
bool operator==(const Rect2D &other) const
Definition: Rect2D.h:326
Rect2D lerp(const Rect2D &other, float alpha) const
Definition: Rect2D.h:231
Rect2D(const Rect2D &r)
Definition: Rect2D.h:130
bool any(float x)
Definition: g3dmath.h:424
static G3D::Matrix::T negate(G3D::Matrix::T x)
Definition: Matrix.cpp:8
Vector2 lerp(const Vector2 &v, float alpha) const
Definition: Vector2.h:133
bool isEmpty() const
Definition: Rect2D.h:139
int length() const
Definition: Array.h:438
Point2 x1y1() const
Definition: Rect2D.h:206
Rect2D border(float delta) const
Definition: Rect2D.h:359
void serialize(class BinaryOutput &b) const
Definition: Rect2D.cpp:28
Rect2D operator+(const Vector2 &v) const
Definition: Rect2D.h:318
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Rect2D expand(float delta) const
Definition: Rect2D.h:368
Vector2 Point2
Definition: Vector2.h:492
float width() const
Definition: Rect2D.h:160
float y
Definition: Vector2.h:50
float y1() const
Definition: Rect2D.h:188
Rect2D(const Rect2D &a, const Rect2D &b)
Definition: Rect2D.h:397
float uniformRandom(float low=0.0f, float hi=1.0f)
Definition: g3dmath.h:694
T min(const T &x, const T &y)
Definition: g3dmath.h:305
Easy loading and saving of human-readable configuration files.
Definition: Any.h:184
static const Rect2D & empty()
Definition: Rect2D.cpp:22
Rect2D operator*(const Vector2 &s) const
Definition: Rect2D.h:306
float height() const
Definition: Rect2D.h:168
void deserialize(class BinaryInput &b)
Definition: Rect2D.cpp:34
#define debugAssert(exp)
Definition: debugAssert.h:160
G3D::int16 y
Definition: Vector2int16.h:38
void merge(const Rect2D &other)
Definition: Rect2D.h:386
float x0() const
Definition: Rect2D.h:176
float x
Definition: Vector2.h:49
void clear(bool shrink=true)
Definition: Array.h:407
Rect2D intersect(const Rect2D &other) const
Definition: Rect2D.h:460
Any toAny() const
Definition: Rect2D.cpp:59
Point2 x1y0() const
Definition: Rect2D.h:197
bool contains(const Point2 &v) const
Definition: Rect2D.h:275
Point2 randomPoint() const
Uniformly random point on the interior.
Definition: Rect2D.h:155
static Rect2D xyxy(float x0, float y0, float x1, float y1)
Definition: Rect2D.h:240
bool intersectsOrTouches(const Rect2D &r) const
Definition: Rect2D.h:296
static Rect2D xyxy(const Point2 &v0, const Point2 &v1)
Definition: Rect2D.h:251
Point2 x0y0() const
Definition: Rect2D.h:193
Definition: BinaryOutput.h:52
bool contains(const Rect2D &r) const
Definition: Rect2D.h:280
Point2 center() const
Definition: Rect2D.h:219
bool isNaN() const
Definition: Vector2.h:95
Rect2D operator-(const Vector2 &v) const
Definition: Rect2D.h:322
static Rect2D xywh(float x, float y, float w, float h)
Definition: Rect2D.h:260
Point2 max
Definition: Rect2D.h:42
G3D::int16 x
Definition: Vector2int16.h:37
static Rect2D xywh(const Point2 &v, const Vector2 &w)
Definition: Rect2D.h:264
void append(const T &value)
Definition: Array.h:583
static const Vector2 & zero()
Definition: Vector2.cpp:67
Point2 min
Definition: Rect2D.h:42
Vector2 max(const Vector2 &v) const
Definition: Vector2.h:458
float x1() const
Definition: Rect2D.h:180
Rect2D(const Vector2 &wh)
Definition: Rect2D.h:144
#define Y
Definition: CollisionDetection.cpp:2282
static const Vector2 & inf()
Definition: Vector2.cpp:82
Rect2D()
Definition: Rect2D.h:134