9 #ifndef Navigation_Box2LL_H
10 #define Navigation_Box2LL_H
50 KY_INLINE
bool IsValid() {
return CountX() >= 0 && CountY() >= 0; }
58 KY_INLINE
void Set(
const Vec2LL& min_,
const Vec2LL& max_) { m_min = min_; m_max = max_; }
61 KY_INLINE
void SetMin(
const Vec2LL& min_) { m_min = min_; }
64 KY_INLINE
void SetMax(
const Vec2LL& max_) { m_max = max_; }
67 KY_INLINE
const Vec2LL&
Min()
const {
return m_min; }
70 KY_INLINE
const Vec2LL&
Max()
const {
return m_max; }
94 KY_INLINE
bool IsInside(
const Vec2LL& pos)
const {
return pos.
x >= m_min.
x && pos.
x <= m_max.
x && pos.
y >= m_min.
y && pos.
y <= m_max.
y; }
114 KY_INLINE
Box2LL&
operator+=(
const Vec2LL& v) { m_min += v; m_max += v;
return *
this; }
120 KY_INLINE
bool operator==(
const Box2LL& other)
const {
return other.m_min == m_min && other.m_max == m_max; }
126 ExpandByVec2_MinMaxOnly(pos);
133 ExpandByVec2_MinMaxOnly(box.m_min);
134 ExpandByVec2_MinMaxOnly(box.m_max);
140 m_min -= enlargement;
141 m_max += enlargement;
173 return CountX() > 0 && CountY() > 0;
189 m_min.
x =
Kaim::Max(box_1.m_min.x, box_2.m_min.x);
190 m_max.
x =
Kaim::Min(box_1.m_max.x, box_2.m_max.x);
191 m_min.
y =
Kaim::Max(box_1.m_min.y, box_2.m_min.y);
192 m_max.
y =
Kaim::Min(box_1.m_max.y, box_2.m_max.y);
193 return CountX() > 0 && CountY() > 0;
197 KY_INLINE
KyInt64 CountX() {
return m_max.
x - m_min.
x + 1; }
198 KY_INLINE
KyInt64 CountY() {
return m_max.
y - m_min.
y + 1; }
200 void ExpandByVec2_MinMaxOnly(
const Vec2LL& pos)
217 template <
class OSTREAM>
218 inline OSTREAM& operator<<(OSTREAM& os,
const Kaim::Box2LL& v)
220 os <<
"{" << v.
Min() <<
";" << v.
Max() <<
"}";
Box2LL & operator+=(const Vec2LL &v)
Adds the specified two-dimensional vector to both the minima and maxima of the box.
Definition: box2ll.h:123
KyInt64 x
The size of the vector along the X axis.
Definition: vec2ll.h:175
void ExpandByBox2(const Box2LL &box)
Enlarges the extents of the bounding box to include the area covered by the specified bounding box...
Definition: box2ll.h:142
bool IsValid()
Indicates whether or not the extents of the bounding box are valid.
Definition: box2ll.h:59
void Enlarge(KyInt64 enlargement)
Enlarges the extents of the bounding box by the specified amount in all directions.
Definition: box2ll.h:149
Box2LL & operator-=(const Vec2LL &v)
Subtracts the specified two-dimensional vector from both the minima and maxima of the box...
Definition: box2ll.h:126
void Set(const Vec2LL &min_, const Vec2LL &max_)
Sets the extents of the bounding box to the specified values.
Definition: box2ll.h:67
void SetMax(const Vec2LL &max_)
Sets the maxima of the bounding box to the specified coordinates.
Definition: box2ll.h:73
bool IntersectWith(const Box2LL &box)
Resizes this bounding box to contain only the grid cells that are common to both it and box...
Definition: box2ll.h:179
T Min(const T &a, const T &b)
Returns the lesser of the two specified values.
Definition: fastmath.h:113
Box2LL()
Creates a new Box2LL with invalid extents: you must call Set() before using it.
Definition: box2ll.h:37
This class defines a two-dimensional vector whose coordinates are stored using 64-bit integers...
Definition: vec2ll.h:27
void ExpandByVec2(const Vec2LL &pos)
Enlarges the extents of the bounding box to include the specified two-dimensional point...
Definition: box2ll.h:134
Box2LL & operator*=(KyInt64 s)
Multiplies both the minima and maxima of the box by the specified value.
Definition: box2ll.h:117
bool operator==(const Box2LL &other) const
Check equality.
Definition: box2ll.h:129
KyInt64 y
The size of the vector along the Y axis.
Definition: vec2ll.h:176
Vec2LL CornerNorthEast() const
Retrieves the coordinates of the North-East corner of the bounding box.
Definition: box2ll.h:89
const Vec2LL & Min() const
Retrieves the minima of the bounding box.
Definition: box2ll.h:76
Vec2LL CornerSouthWest() const
Retrieves the coordinates of the South-West corner of the bounding box.
Definition: box2ll.h:84
void MakeZero()
Sets both the minima and maxima of the bounding box to (0,0).
Definition: box2ll.h:62
void Set(KyInt64 _x, KyInt64 _y)
Sets the coordinates of the vector to match the specified values.
Definition: vec2ll.h:55
T Max(const T &a, const T &b)
Returns the greater of the two specified values.
Definition: fastmath.h:121
Vec2LL CornerSouthEast() const
Retrieves the coordinates of the South-East corner of the bounding box.
Definition: box2ll.h:94
void Clear()
Clears all information maintained by this object.
Definition: box2ll.h:110
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
void SetMin(const Vec2LL &min_)
Sets the minima of the bounding box to the specified coordinates.
Definition: box2ll.h:70
const Vec2LL & Max() const
Retrieves the maxima of the bounding box.
Definition: box2ll.h:79
bool IsInside(const Vec2LL &pos) const
Returns true if the specified position is contained within the extents of the bounding box or if the ...
Definition: box2ll.h:103
Vec2LL CornerNorthWest() const
Retrieves the coordinates of the North-West corner of the bounding box.
Definition: box2ll.h:99
bool IsInsideStrictly(const Vec2LL &pos) const
Returns true if the specified position is contained entirely within the extents of the bounding box...
Definition: box2ll.h:106
Box2LL & operator/=(KyInt64 s)
Divides both the minima and maxima of the box by the specified value.
Definition: box2ll.h:120
#define KyInt64MAXVAL
The maximum value that can be stored in the KyInt64 variable type.
Definition: types.h:234
void GetEnlarged(KyInt64 enlargement, Box2LL &enlarged) const
Enlarges the extents of the bounding box by the specified amount in all directions, and stores the new dimensions in the enlarged parameter.
Definition: box2ll.h:159
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
bool SetAsIntersection(const Box2LL &box_1, const Box2LL &box_2)
Resizes this bounding box to contain only the grid cells that are common to both box_1 and box_2...
Definition: box2ll.h:200
Each instance of this class also maintains a count of the number of elements (or grid cells) containe...
Definition: box2ll.h:24