9 #ifndef Navigation_Box2i_H
10 #define Navigation_Box2i_H
131 Box2i(
const Vec2i& min_,
const Vec2i& max_) : m_min(min_), m_max(max_) { UpdateCountXY(); }
147 KY_INLINE
void MakeZero() { m_min.
Set(0, 0); m_max.
Set(0, 0); UpdateCountXY(); }
152 KY_INLINE
void Set(
const Vec2i& min_,
const Vec2i& max_) { m_min = min_; m_max = max_; UpdateCountXY(); }
159 KY_INLINE
void SetSafe(
const Vec2i& min_,
const Vec2i& max_) { m_min = min_; m_max = max_; UpdateCountXYSafe(); }
162 KY_INLINE
void SetMin(
const Vec2i& min_) { m_min = min_; UpdateCountXY(); }
165 KY_INLINE
void SetMax(
const Vec2i& max_) { m_max = max_; UpdateCountXY(); }
168 KY_INLINE
const Vec2i&
Min()
const {
return m_min; }
171 KY_INLINE
const Vec2i&
Max()
const {
return m_max; }
194 KY_INLINE
const Vec2i&
CountXY()
const {
return m_countXY; }
204 KY_INLINE
bool IsInside(
const Vec2i& pos)
const {
return pos.
x >= m_min.
x && pos.
x <= m_max.
x && pos.
y >= m_min.
y && pos.
y <= m_max.
y; }
216 return (operand1 & operand2 & operand3 & operand4) != 0;
241 KY_INLINE
Box2i&
operator-=(
const Vec2i& v) { m_min -= v; m_max -= v;
return *
this; }
244 KY_INLINE
bool operator==(
const Box2i& other)
const {
return other.m_min == m_min && other.m_max == m_max; }
245 KY_INLINE
bool operator!=(
const Box2i& other)
const {
return !(*
this == other); }
300 ExpandByVec2_MinMaxOnly(pos);
309 ExpandByVec3_MinMaxOnly(pos);
318 ExpandByVec3_MinMaxOnly(triangle.
A);
319 ExpandByVec3_MinMaxOnly(triangle.
B);
320 ExpandByVec3_MinMaxOnly(triangle.
C);
338 m_min -= enlargement;
339 m_max += enlargement;
385 if (m_min.
x <= m_max.
x && m_min.
y <= m_max.
y)
396 KY_INLINE
void UpdateCountX() { m_countXY.
x = m_max.
x - m_min.
x + 1; }
397 KY_INLINE
void UpdateCountY() { m_countXY.
y = m_max.
y - m_min.
y + 1; }
398 KY_INLINE
void UpdateCountXY() { UpdateCountX(); UpdateCountY(); }
399 KY_INLINE
void ClearCountXY() { m_countXY.
x = -1; m_countXY.
y = -1; }
401 KY_INLINE
void UpdateCountXYSafe()
415 void ExpandByVec2_MinMaxOnly(
const Vec2i& pos)
425 void ExpandByVec3_MinMaxOnly(
const Vec3i& pos)
443 friend class GridUtils;
456 template <
class OSTREAM>
457 inline OSTREAM& operator<<(OSTREAM& os,
const Kaim::Box2i& v)
459 os <<
"{" << v.
Min() <<
";" << v.
Max() <<
"}";
void MakeZero()
Sets both the minima and maxima of the bounding box to (0,0).
Definition: box2i.h:157
Box2i & operator+=(const Vec2i &v)
Adds the specified two-dimensional vector to both the minima and maxima of the box.
Definition: box2i.h:249
const Vec2i & Max() const
Retrieves the maxima of the bounding box.
Definition: box2i.h:181
Vec3i A
The position of the first corner of the triangle.
Definition: triangle3i.h:65
void SwapEndianness(Kaim::Endianness::Target e, Box2i &self)
Swaps the endianness of the data in the specified object.
Definition: box2i.h:473
Box2i & operator-=(const Vec2i &v)
Subtracts the specified two-dimensional vector from both the minima and maxima of the box...
Definition: box2i.h:252
This class represents a two-dimensional axis-aligned bounding box whose dimensions are stored using 3...
Definition: box2i.h:119
void SetSafe(const Vec2i &min_, const Vec2i &max_)
Sets the extents of the bounding box to the specified values.
Definition: box2i.h:169
KyInt32 GetColumnMajorIndex(const Vec2i &pos) const
Retrieves the index of the grid cell at the specified (X,Y) position, counting cells column-by-column...
Definition: box2i.h:277
KyInt32 Isel(KyInt32 a, KyInt32 x, KyInt32 y)
If a is greater than 0, returns x. Otherwise, returns y.
Definition: fastmath.h:70
void ExpandByTriangle(const Triangle3i &triangle)
Enlarges the extents of the bounding box to include the (X,Y) extents of the specified three-dimensio...
Definition: box2i.h:334
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
void Set(KyInt32 _x, KyInt32 _y)
Sets the coordinates of the vector to match the specified values.
Definition: vec2i.h:54
T Min(const T &a, const T &b)
Returns the lesser of the two specified values.
Definition: fastmath.h:113
KyInt32 x
The size of the vector along the X axis.
Definition: vec2i.h:283
Vec2i CornerNorthEast() const
Retrieves the coordinates of the North-East corner of the bounding box.
Definition: box2i.h:191
Box2i()
Creates a new Box2i with invalid extents: you must call Set() before using it.
Definition: box2i.h:132
bool IntersectWith(const Box2i &box)
Resizes this bounding box to contain only the grid cells that are common to both it and box...
Definition: box2i.h:386
KyInt32 GetColumnMajorIndexFromLocalPos(const Vec2i &localPos) const
Retrieves the index of the grid cell at the specified (X,Y) position, counting cells column-by-column...
Definition: box2i.h:304
void GetEnlarged(KyInt32 enlargement, Box2i &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: box2i.h:366
Vec2i CornerSouthWest() const
Retrieves the coordinates of the South-West corner of the bounding box.
Definition: box2i.h:186
KyInt32 y
The size of the vector along the Y axis.
Definition: vec2i.h:284
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
KyInt32 GetRowMajorIndex(const Vec2i &pos) const
Retrieves the index of the grid cell at the specified (X,Y) position, counting cells row-by-row...
Definition: box2i.h:297
#define KyInt32MAXVAL
The maximum value that can be stored in the KyInt32 variable type.
Definition: types.h:224
bool SetAsIntersection(const Box2i &box_1, const Box2i &box_2)
Resizes this bounding box to contain only the grid cells that are common to both box_1 and box_2...
Definition: box2i.h:400
bool IsInsideStrictly(const Vec2i &pos) const
Returns true if the specified position is contained entirely within the extents of the bounding box...
Definition: box2i.h:231
void SetMax(const Vec2i &max_)
Sets the maxima of the bounding box to the specified coordinates.
Definition: box2i.h:175
Vec2i CornerSouthEast() const
Retrieves the coordinates of the South-East corner of the bounding box.
Definition: box2i.h:196
T Max(const T &a, const T &b)
Returns the greater of the two specified values.
Definition: fastmath.h:121
This class defines a two-dimensional vector whose coordinates are stored using 32-bit integers...
Definition: vec2i.h:26
Definition: gamekitcrowddispersion.h:20
void ExpandByVec3(const Vec3i &pos)
Enlarges the extents of the bounding box to include the (X,Y) coordinates of the specified three-dime...
Definition: box2i.h:325
Vec3i B
The position of the second corner of the triangle.
Definition: triangle3i.h:66
KyInt32 CountY() const
Retrieves the number of grid cells contained within this box along its Y axis.
Definition: box2i.h:210
Vec2i CornerNorthWest() const
Retrieves the coordinates of the North-West corner of the bounding box.
Definition: box2i.h:201
bool FastIsInside(const Vec2i &pos) const
Returns true if the specified position is contained within the extents of the bounding box or if the ...
Definition: box2i.h:220
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
Box2i & operator*=(KyInt32 s)
Multiplies both the minima and maxima of the box by the specified value.
Definition: box2i.h:243
void Set(const Vec2i &min_, const Vec2i &max_)
Sets the extents of the bounding box to the specified values.
Definition: box2i.h:162
const Vec2i & Min() const
Retrieves the minima of the bounding box.
Definition: box2i.h:178
KyInt32 GetRowMajorIndexFromLocalPos(const Vec2i &localPos) const
Retrieves the index of the grid cell at the specified (X,Y) position, counting cells row-by-row...
Definition: box2i.h:311
const Vec2i & CountXY() const
Retrieves the number of grid cells contained within this box along its X and Y axes.
Definition: box2i.h:204
void SetMin(const Vec2i &min_)
Sets the minima of the bounding box to the specified coordinates.
Definition: box2i.h:172
bool IsInside(const Vec2i &pos) const
Returns true if the specified position is contained within the extents of the bounding box or if the ...
Definition: box2i.h:214
friend void SwapEndianness(Kaim::Endianness::Target e, Box2i &self)
Swaps the endianness of the data in the specified object.
Definition: box2i.h:473
void Enlarge(KyInt32 enlargement)
Enlarges the extents of the bounding box by the specified amount in all directions.
Definition: box2i.h:355
KyInt32 CountX() const
Retrieves the number of grid cells contained within this box along its X axis.
Definition: box2i.h:207
void ExpandByBox2(const Box2i &box)
Enlarges the extents of the bounding box to include the area covered by the specified bounding box...
Definition: box2i.h:345
Box2i & operator/=(KyInt32 s)
Divides both the minima and maxima of the box by the specified value.
Definition: box2i.h:246
void ExpandByVec2(const Vec2i &pos)
Enlarges the extents of the bounding box to include the specified two-dimensional point...
Definition: box2i.h:316
This class represents a triangle in three-dimensional space, whose dimensions are stored using intege...
Definition: triangle3i.h:23
bool IsValid() const
Indicates whether or not the extents of the bounding box are valid.
Definition: box2i.h:154
void Clear()
Clears all information maintained by this object.
Definition: box2i.h:235
bool operator==(const Box2i &other) const
Check equality.
Definition: box2i.h:255
Vec3i C
The position of the third corner of the triangle.
Definition: triangle3i.h:67
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37