X-Git-Url: http://nitlanguage.org diff --git a/lib/geometry/boxes.nit b/lib/geometry/boxes.nit index 1596c1e..dc87cb5 100644 --- a/lib/geometry/boxes.nit +++ b/lib/geometry/boxes.nit @@ -75,14 +75,16 @@ interface Boxed[N: Numeric] self.top >= other.bottom and other.top >= self.bottom end - # Create a bounding box that englobes the actual bounding box. + # Create a bounding box that encloses the actual bounding box. # `dist` is the distance between the inner boundaries and the outer boundaries. # ~~~ # var p = new Point[Int](5,10) # var b = p.padded(3) - # assert b.top == 2 and b.bot = 8 and b.left == 7 and b.right == 13 + # assert b.left == 2 and b.right == 8 and b.top == 13 and b.bottom == 7 # ~~~ fun padded(dist: N): Box[N] do return new Box[N].lrtb(left - dist, right + dist, top + dist, bottom - dist) + + redef fun to_s do return "<{class_name} left: {left}, right: {right}, top: {top}, bottom: {bottom}>" end # A 2d bounded object and an implementation of `Boxed` @@ -120,51 +122,32 @@ class Box[N: Numeric] assert left != null and right != null and top != null and bottom != null - self.left = left - self.right = right - self.top = top - self.bottom = bottom + init(left, right, top, bottom) end # Create a `Box` using left, right, bottom and top init lrbt(left, right, bottom, top: N) do - self.left = left - self.right = right - self.top = top - self.bottom = bottom + init(left, right, top, bottom) end # Create a `Box` using left, right, top and bottom init lrtb(left, right, top, bottom: N) do - self.left = left - self.right = right - self.top = top - self.bottom = bottom + init(left, right, top, bottom) end # Create a `Box` using left, bottom, width and height init lbwh(left, bottom, width, height: N) do - self.left = left - self.bottom = bottom - - self.right = left + width - self.top = bottom + height + 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 - self.left = left - self.top = top - - self.right = left + width - self.bottom = top - height + init(left, left+width, top, top - height) end - - redef fun to_s do return "" end # An 3d abstract bounded object @@ -211,7 +194,9 @@ interface Boxed3d[N: Numeric] (self.back <= other.front and other.back <= self.front)) end - redef fun padded(dist: N): Box3d[N] do return new Box3d[N].lrtbfb(left - dist, right + dist, top + dist, bottom - dist, front + dist, back - dist) + redef fun padded(dist): Box3d[N] do return new Box3d[N].lrtbfb(left - dist, right + dist, top + dist, bottom - dist, front + dist, back - dist) + + redef fun to_s do return "<{class_name} left: {left}, right: {right}, top: {top}, bottom: {bottom}, front: {front}, back: {back}>" end # A 3d bounded object and an implementation of Boxed @@ -232,6 +217,8 @@ class Box3d[N: Numeric] # assert box.right == 4 and box.top == 4 init around(boxed: Boxed3d[N]...) do + super + assert not boxed.is_empty var left: nullable N = null @@ -293,8 +280,6 @@ class Box3d[N: Numeric] self.front = front self.back = front - depth end - - redef fun to_s do return "