9 #ifndef GwNavGen_SquarePartitionUtils_H
10 #define GwNavGen_SquarePartitionUtils_H
31 KyInt32 is_strict_pos = -(-coord >> 31);
32 return (coord - is_strict_pos) / squareSize - 1 + is_strict_pos;
37 KyInt32 is_strict_neg = -(coord >> 31);
38 return (coord + is_strict_neg) / squareSize - is_strict_neg;
43 KyInt64 is_strict_neg = -(coord >> 63);
44 return (coord + is_strict_neg) / squareSize - is_strict_neg;
47 static void LowSquare(
KyInt32 squareSize,
const Vec2i& pos, Vec2i& squarePos)
49 squarePos.x = LowSquare(squareSize, pos.x);
50 squarePos.y = LowSquare(squareSize, pos.y);
53 static void HighSquare(
KyInt32 squareSize,
const Vec2i& pos, Vec2i& squarePos)
55 squarePos.x = HighSquare(squareSize, pos.x);
56 squarePos.y = HighSquare(squareSize, pos.y);
59 static void LowSquare(
KyInt32 squareSize,
const Vec3i& pos, Vec2i& squarePos)
61 squarePos.x = LowSquare(squareSize, pos.x);
62 squarePos.y = LowSquare(squareSize, pos.y);
65 static void HighSquare(
KyInt32 squareSize,
const Vec3i& pos, Vec2i& squarePos)
67 squarePos.x = HighSquare(squareSize, pos.x);
68 squarePos.y = HighSquare(squareSize, pos.y);
72 static void SquareBox(
KyInt32 squareSize,
const Box2i& coordBox, Box2i& squareBox)
74 LowSquare(squareSize, coordBox.m_min, squareBox.m_min);
75 HighSquare(squareSize, coordBox.m_max, squareBox.m_max);
76 squareBox.UpdateCountXY();
80 static void SquareBoxStrict(
KyInt32 squareSize,
const Box2i& coordBox, Box2i& squareBox)
82 HighSquare(squareSize, coordBox.m_min, squareBox.m_min);
83 LowSquare(squareSize, coordBox.m_max, squareBox.m_max);
84 squareBox.UpdateCountXY();
91 return squareCoord * squareSize;
96 return (squareCoord + 1) * squareSize;
99 static void MinCoordPos(
KyInt32 squareSize,
const Vec2i& squarePos, Vec2i& coordPos)
101 coordPos.x = MinCoord(squareSize, squarePos.x);
102 coordPos.y = MinCoord(squareSize, squarePos.y);
105 static void MaxCoordPos(
KyInt32 squareSize,
const Vec2i& squarePos, Vec2i& coordPos)
107 coordPos.x = MaxCoord(squareSize, squarePos.x);
108 coordPos.y = MaxCoord(squareSize, squarePos.y);
111 static void GetCoordBox(
KyInt32 squareSize,
const Box2i& squareBox, Box2i& coordBox)
113 MinCoordPos(squareSize, squareBox.m_min, coordBox.m_min);
114 MaxCoordPos(squareSize, squareBox.m_max, coordBox.m_max);
115 coordBox.UpdateCountXY();
125 return bigCoord * nbSmallsOnBigSide;
130 return (bigCoord + 1) * nbSmallsOnBigSide - 1;
133 static void MinSmallSquarePos(
KyInt32 nbSmallsOnBigSide,
const Vec2i& bigPos, Vec2i& smallPos)
135 smallPos.x = MinSmallSquareCoord(nbSmallsOnBigSide, bigPos.x);
136 smallPos.y = MinSmallSquareCoord(nbSmallsOnBigSide, bigPos.y);
139 static void MaxSmallSquarePos(
KyInt32 nbSmallsOnBigSide,
const Vec2i& bigPos, Vec2i& smallPos)
141 smallPos.x = MaxSmallSquareCoord(nbSmallsOnBigSide, bigPos.x);
142 smallPos.y = MaxSmallSquareCoord(nbSmallsOnBigSide, bigPos.y);
145 static void SmallSquareBox(
KyInt32 nbSmallsOnBigSide,
const Box2i& bigBox, Box2i& smallBox)
147 MinSmallSquarePos(nbSmallsOnBigSide, bigBox.m_min, smallBox.m_min);
148 MaxSmallSquarePos(nbSmallsOnBigSide, bigBox.m_max, smallBox.m_max);
149 smallBox.UpdateCountXY();
152 static void SmallSquareBox(
KyInt32 nbSmallsOnBigSide,
const Vec2i& bigPos, Box2i& smallBox)
154 MinSmallSquarePos(nbSmallsOnBigSide, bigPos, smallBox.m_min);
155 MaxSmallSquarePos(nbSmallsOnBigSide, bigPos, smallBox.m_max);
156 smallBox.UpdateCountXY();
166 KyInt32 is_strict_neg = -(smallCoord >> 31);
167 return (smallCoord + is_strict_neg) / nbSmallsOnBigSide - is_strict_neg;
174 static void BigSquarePos(
KyInt32 nbSmallsOnBigSide,
const Vec2i& smallPos, Vec2i& bigPos)
176 bigPos.x = BigSquareCoord(nbSmallsOnBigSide, smallPos.x);
177 bigPos.y = BigSquareCoord(nbSmallsOnBigSide, smallPos.y);
180 static void BigSquareBox(
KyInt32 nbSmallsOnBigSide,
const Box2i& smallBox, Box2i& bigBox)
182 BigSquarePos(nbSmallsOnBigSide, smallBox.m_min, bigBox.m_min);
183 BigSquarePos(nbSmallsOnBigSide, smallBox.m_max, bigBox.m_max);
184 bigBox.UpdateCountXY();
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Definition: gamekitcrowddispersion.h:20
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37