9 #include <aliceVision/numeric/numeric.hpp>
39 int getRight()
const {
return left + width - 1; }
41 int getBottom()
const {
return top + height - 1; }
43 bool isEmpty()
const {
return (width <= 0 || height <= 0); }
45 int area()
const {
return width * height; }
47 void snapToGrid(uint32_t gridSize)
49 int right = getRight();
50 int bottom = getBottom();
52 int leftBounded = int(std::floor(
double(left) /
double(gridSize))) * int(gridSize);
53 int topBounded = int(std::floor(
double(top) /
double(gridSize))) * int(gridSize);
54 int widthBounded = divideRoundUp<int>(right - leftBounded + 1, gridSize) * int(gridSize);
55 int heightBounded = divideRoundUp<int>(bottom - topBounded + 1, gridSize) * int(gridSize);
60 height = heightBounded;
67 if (left < 0 && top < 0)
69 ret.left = other.left;
71 ret.width = other.width;
72 ret.height = other.height;
77 int ro = other.getRight();
79 int bo = other.getBottom();
81 ret.left = std::min(left, other.left);
82 ret.top = std::min(top, other.top);
84 int maxr = std::max(rt, ro);
85 int maxb = std::max(bt, bo);
87 ret.width = maxr - ret.left + 1;
88 ret.height = maxb - ret.top + 1;
97 intersection.left = std::max(left, other.left);
98 intersection.top = std::max(top, other.top);
100 int right = std::min(getRight(), other.getRight());
101 int bottom = std::min(getBottom(), other.getBottom());
103 intersection.width = std::max(0, right - intersection.left + 1);
104 intersection.height = std::max(0, bottom - intersection.top + 1);
111 if (other.left > left)
116 if (other.getRight() < getRight())
118 if (other.getBottom() < getBottom())
128 b.left = left - units;
130 b.width = width + units * 2;
131 b.height = height + units * 2;
145 void clampRight(
int maxRight)
147 if (getRight() > maxRight)
149 int removal = getRight() - maxRight;
163 void clampBottom(
int maxBottom)
165 if (getBottom() > maxBottom)
167 int removal = getBottom() - maxBottom;
179 b.height = height * 2;
188 int factor = pow(2, scale);
190 b.left = left * factor;
191 b.top = top * factor;
192 b.width = width * factor;
193 b.height = height * factor;
202 int factor = pow(2, scale);
204 b.left = int(floor(
double(left) /
double(factor)));
205 b.top = int(floor(
double(top) /
double(factor)));
207 int sleft = b.left * factor;
208 int stop = b.top * factor;
210 int nwidth = getRight() - sleft;
211 int nheight = getBottom() - stop;
213 b.width = int(ceil(
double(nwidth) /
double(factor)));
214 b.height = int(ceil(
double(nheight) /
double(factor)));
224 if (b.left < other.left)
230 if (b.top < other.top)
235 int nright = getRight();
236 if (nright > other.getRight())
238 nright = other.getRight();
241 int nbottom = getBottom();
242 if (nbottom > other.getBottom())
244 nbottom = other.getBottom();
247 b.width = nright - b.left + 1;
248 b.height = nbottom - b.top + 1;
254 std::ostream& operator<<(std::ostream& os,
const BoundingBox& in);