24 Box2i(
const Vec2i& min_,
const Vec2i& max_) : m_min(min_), m_max(max_) { UpdateCountXY(); }
27 bool operator==(
const Box2i& other)
const {
return other.m_min == m_min && other.m_max == m_max; }
28 bool operator!=(
const Box2i& other)
const {
return other.m_min != m_min || other.m_max != m_max; }
38 bool IsValid()
const {
return CountX() > 0 &&
CountY() > 0; }
42 void Set(
const Vec2i& min_,
const Vec2i& max_) { m_min = min_; m_max = max_; UpdateCountXY(); }
44 void Set(
KyInt32 min_x,
KyInt32 min_y,
KyInt32 max_x,
KyInt32 max_y) { m_min.x = min_x; m_min.y = min_y; m_max.x = max_x; m_max.y = max_y; UpdateCountXY(); }
45 void SetSafe(
const Vec2i& min_,
const Vec2i& max_) { m_min = min_; m_max = max_; UpdateCountXYSafe(); }
47 void SetMin(
const Vec2i& min_) { m_min = min_; UpdateCountXY(); }
48 void SetMax(
const Vec2i& max_) { m_max = max_; UpdateCountXY(); }
50 const Vec2i& Min()
const {
return m_min; }
51 const Vec2i& Max()
const {
return m_max; }
60 KyInt32 East()
const {
return m_max.x; }
61 KyInt32 North()
const {
return m_max.y; }
62 KyInt32 West()
const {
return m_min.x; }
63 KyInt32 South()
const {
return m_max.y; }
65 Vec2i NorthEast()
const {
return m_max; }
66 Vec2i NorthWest()
const {
return Vec2i(m_min.x, m_max.y); }
67 Vec2i SouthWest()
const {
return m_min; }
68 Vec2i SouthEast()
const {
return Vec2i(m_max.x, m_min.y); }
72 bool DoesContain(
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; }
74 bool DoesContainStrictly(
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; }
84 default:
return pos.y > m_min.y;
109 void ExpandByPos(
const Vec2i& pos)
111 ExpandByVec2_MinMaxOnly(pos);
115 void ExpandByPos(
const Vec3i& pos)
117 ExpandByVec3_MinMaxOnly(pos);
121 void ExpandByTriangle(
const Triangle3i& triangle)
123 ExpandByVec3_MinMaxOnly(triangle.A);
124 ExpandByVec3_MinMaxOnly(triangle.B);
125 ExpandByVec3_MinMaxOnly(triangle.C);
129 void ExpandByBox(
const Box2i& box)
131 m_min.x = Kaim::Min(m_min.x, box.m_min.x);
132 m_max.x = Kaim::Max(m_max.x, box.m_max.x);
133 m_min.y = Kaim::Min(m_min.y, box.m_min.y);
134 m_max.y = Kaim::Max(m_max.y, box.m_max.y);
140 void Enlarge(
KyInt32 enlargement)
142 Vec2i e(enlargement, enlargement);
148 void GetEnlarged(
KyInt32 enlargement,
Box2i& enlarged)
const
151 enlarged.Enlarge(enlargement);
156 Vec2i e(enlargement, enlargement);
157 return Box2i(m_min - e, m_max + e);
165 bool DoesIntersectWith(
const Box2i& box)
const
167 KyInt32 min_x = Kaim::Max(m_min.x, box.m_min.x);
168 KyInt32 max_x = Kaim::Min(m_max.x, box.m_max.x);
169 KyInt32 min_y = Kaim::Max(m_min.y, box.m_min.y);
170 KyInt32 max_y = Kaim::Min(m_max.y, box.m_max.y);
171 return (min_x <= max_x && min_y <= max_y);
177 m_min.x = Kaim::Max(box_1.m_min.x, box_2.m_min.x);
178 m_max.x = Kaim::Min(box_1.m_max.x, box_2.m_max.x);
179 m_min.y = Kaim::Max(box_1.m_min.y, box_2.m_min.y);
180 m_max.y = Kaim::Min(box_1.m_max.y, box_2.m_max.y);
182 if (m_min.x <= m_max.x && m_min.y <= m_max.y)
193 void UpdateCountX() { m_countXY.x = m_max.x - m_min.x + 1; }
194 void UpdateCountY() { m_countXY.y = m_max.y - m_min.y + 1; }
195 void UpdateCountXY() { UpdateCountX(); UpdateCountY(); }
196 void ClearCountXY() { m_countXY.x = -1; m_countXY.y = -1; }
198 void UpdateCountXYSafe()
212 void ExpandByVec2_MinMaxOnly(
const Vec2i& pos)
216 m_min.x = Kaim::Min(m_min.x, posx);
217 m_max.x = Kaim::Max(m_max.x, posx);
218 m_min.y = Kaim::Min(m_min.y, posy);
219 m_max.y = Kaim::Max(m_max.y, posy);
222 void ExpandByVec3_MinMaxOnly(
const Vec3i& pos)
226 m_min.x = Kaim::Min(m_min.x, posx);
227 m_max.x = Kaim::Max(m_max.x, posx);
228 m_min.y = Kaim::Min(m_min.y, posy);
229 m_max.y = Kaim::Max(m_max.y, posy);
241 friend class GridUtils;
246 SwapEndianness(e,
self.m_min);
247 SwapEndianness(e,
self.m_max);
248 SwapEndianness(e,
self.m_countXY);
251 template <
class OSTREAM>
252 inline OSTREAM& operator<<(OSTREAM& os,
const Box2i&
self)
254 os <<
"{" <<
self.Min() <<
"," <<
self.Max() <<
"}";
void MakeZero()
set {{0,0},{0,0}}
Definition: box2i.h:40
#define KyInt32MINVAL
KyInt32 min value
Definition: types.h:61
static const CardinalDir CardinalDir_NORTH
Y positive axis.
Definition: cardinaldir.h:17
2d axis aligned box of 32bits integers. Very Important: CountX() returns m_max.x - m_min...
Definition: box2i.h:17
bool DoesContainNeighbor(const Vec2i &pos, CardinalDir dir) const
precondition: pos is inside
Definition: box2i.h:77
void SetSafe(const Vec2i &min_, const Vec2i &max_)
check if values max_ - min_ does overflow
Definition: box2i.h:45
void Set(KyInt32 _x, KyInt32 _y)
Sets x=_x and y=_y.
Definition: vec2i.h:29
Box2i()
Set { {+infinite, +infinite}, {-infinite, -infinite} }.
Definition: box2i.h:23
KyUInt32 CardinalDir
Defines a type that refers to one of the cardinal points on the compass:
Definition: cardinaldir.h:15
bool IntersectWith(const Box2i &box)
Sets itself as its intersection with box, return true if itself and box do intersect.
Definition: box2i.h:163
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
static const CardinalDir CardinalDir_EAST
X positive axis.
Definition: cardinaldir.h:16
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
KyInt32 GetRowMajorIndex(const Vec2i &pos) const
Compute index of position in box, where index is incremented in a outer-loop on Y and inner-loop on X...
Definition: box2i.h:101
std::int64_t KyInt64
int64_t
Definition: types.h:25
#define KyInt32MAXVAL
KyInt32 max value
Definition: types.h:60
bool SetAsIntersection(const Box2i &box_1, const Box2i &box_2)
Sets itself as the intersection of box_1 and box_2, return true if box_1 and box_2 do intersect...
Definition: box2i.h:175
static const CardinalDir CardinalDir_WEST
X negative axis.
Definition: cardinaldir.h:18
2d vector using KyInt32
Definition: vec2i.h:18
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
KyInt32 CountY() const
Return m_max.y - m_min.y + 1.
Definition: box2i.h:56
KyInt32 GetRowMajorIndexFromLocalPos(const Vec2i &localPos) const
Compute index of position in box, where index is incremented in a outer-loop on Y and inner-loop on X...
Definition: box2i.h:105
std::int32_t KyInt32
int32_t
Definition: types.h:24
const Vec2i & CountXY() const
Return { m_max.x - m_min.x + 1, m_max.y - m_min.y + 1}.
Definition: box2i.h:53
KyInt32 CountX() const
Return m_max.x - m_min.x + 1.
Definition: box2i.h:55
void Clear()
Set { {+infinite, +infinite}, {-infinite, -infinite} }.
Definition: box2i.h:31