|
1 | | -local position = require("__flib__/position") |
| 1 | +if ... ~= "__flib__.bounding-box" then |
| 2 | + return require("__flib__.bounding-box") |
| 3 | +end |
| 4 | + |
| 5 | +local position = require("__flib__.position") |
2 | 6 |
|
3 | 7 | --- Utilities for manipulating bounding boxes. All functions support both the shorthand and explicit syntaxes for boxes |
4 | 8 | --- and positions, and will preserve the syntax that was passed in. Boxes are considered immutable; all functions will |
5 | 9 | --- return new boxes. |
6 | 10 | --- ```lua |
7 | | ---- local flib_bounding_box = require("__flib__/bounding-box") |
| 11 | +--- local flib_bounding_box = require("__flib__.bounding-box") |
8 | 12 | --- ``` |
9 | 13 | --- @class flib_bounding_box |
10 | 14 | local flib_bounding_box = {} |
|
64 | 68 | function flib_bounding_box.contains_position(box, pos) |
65 | 69 | local box = flib_bounding_box.ensure_explicit(box) |
66 | 70 | local pos = position.ensure_explicit(pos) |
67 | | - return |
68 | | - box.left_top.x <= pos.x and box.left_top.y <= pos.y and box.right_bottom.x >= pos.x and box.right_bottom.y >= pos.y |
| 71 | + return box.left_top.x <= pos.x |
| 72 | + and box.left_top.y <= pos.y |
| 73 | + and box.right_bottom.x >= pos.x |
| 74 | + and box.right_bottom.y >= pos.y |
69 | 75 | end |
70 | 76 |
|
71 | 77 | --- Return the box in explicit form. |
@@ -219,11 +225,10 @@ end |
219 | 225 | function flib_bounding_box.intersects_box(box1, box2) |
220 | 226 | local box1 = flib_bounding_box.ensure_explicit(box1) |
221 | 227 | local box2 = flib_bounding_box.ensure_explicit(box2) |
222 | | - return |
223 | | - box1.left_top.x < box2.right_bottom.x |
224 | | - and box2.left_top.x < box1.right_bottom.x |
225 | | - and box1.left_top.y < box2.right_bottom.y |
226 | | - and box2.left_top.y < box1.right_bottom.y |
| 228 | + return box1.left_top.x < box2.right_bottom.x |
| 229 | + and box2.left_top.x < box1.right_bottom.x |
| 230 | + and box1.left_top.y < box2.right_bottom.y |
| 231 | + and box2.left_top.y < box1.right_bottom.y |
227 | 232 | end |
228 | 233 |
|
229 | 234 | --- Return a new box with the same dimensions, moved by the given delta. |
|
0 commit comments