geometry :: Box :: defaultinit
# A 2d bounded object and an implementation of `Boxed`
#
# This class offers many constructors specialized for different usage. They are
# named according to the order of their arguments.
class Box[N: Numeric]
super Boxed[N]
redef var left: N
redef var right: N
redef var top: N
redef var bottom: N
# Create a `Box` covering all of the `boxed`
#
# var box = new Box[Int].around(new Point[Int](-4,-4), new Point[Int](4,4))
# assert box.left == -4 and box.bottom == -4
# assert box.right == 4 and box.top == 4
init around(boxed: Boxed[N]...)
do
assert not boxed.is_empty
var left: nullable N = null
var right: nullable N = null
var top: nullable N = null
var bottom: nullable N = null
for box in boxed do
if left == null or box.left < left then left = box.left
if right == null or box.right > right then right = box.right
if top == null or box.top > top then top = box.top
if bottom == null or box.bottom < bottom then bottom = box.bottom
end
assert left != null and right != null and top != null and bottom != null
init(left, right, top, bottom)
end
# Create a `Box` using left, right, bottom and top
init lrbt(left, right, bottom, top: N)
do
init(left, right, top, bottom)
end
# Create a `Box` using left, right, top and bottom
init lrtb(left, right, top, bottom: N)
do
init(left, right, top, bottom)
end
# Create a `Box` using left, bottom, width and height
init lbwh(left, bottom, width, height: N)
do
init(left, left + width, bottom + height, bottom)
end
# Create a `Box` using left, top, width and height
init ltwh(left, top, width, height: N)
do
init(left, left+width, top, top - height)
end
end
lib/geometry/boxes.nit:90,1--151,3