nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
android & benitlux: use NitObject in clients
[nit.git]
/
lib
/
geometry
/
boxes.nit
diff --git
a/lib/geometry/boxes.nit
b/lib/geometry/boxes.nit
index
5ec269d
..
dc87cb5
100644
(file)
--- a/
lib/geometry/boxes.nit
+++ b/
lib/geometry/boxes.nit
@@
-83,6
+83,8
@@
interface Boxed[N: Numeric]
# 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)
# 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`
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
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
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
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
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
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
end
-
- redef fun to_s do return "<left: {left}, right: {right}, top: {top}, bottom: {bottom}>"
end
# An 3d abstract bounded object
end
# An 3d abstract bounded object
@@
-212,6
+195,8
@@
interface Boxed3d[N: Numeric]
end
redef fun padded(dist): Box3d[N] do return new Box3d[N].lrtbfb(left - dist, right + dist, top + dist, bottom - dist, front + dist, back - dist)
end
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
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
# 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
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
self.front = front
self.back = front - depth
end
-
- redef fun to_s do return "<left: {left}, right: {right}, top: {top}, bottom: {bottom}, front: {front}, back: {back}"
end
redef class IPoint[N]
end
redef class IPoint[N]
@@
-318,8
+303,8
@@
redef class ILine[N]
redef fun left do return point_left.x
redef fun right do return point_right.x
redef fun left do return point_left.x
redef fun right do return point_right.x
- redef fun top do return point_left.y.min(point_right.y)
- redef fun bottom do return point_left.y.max(point_right.y)
+ redef fun top do return point_left.y.max(point_right.y)
+ redef fun bottom do return point_left.y.min(point_right.y)
end
redef class ILine3d[N]
end
redef class ILine3d[N]
@@
-337,22
+322,19
@@
interface BoxedCollection[E: Boxed[Numeric]]
fun items_overlapping(region :Boxed[Numeric]): SimpleCollection[E] is abstract
end
fun items_overlapping(region :Boxed[Numeric]): SimpleCollection[E] is abstract
end
-# A BoxedCollection implemented with an array, linear performances for searching but really
-# fast for creation and filling
+# `BoxedCollection` implemented by an array
+#
+# Linear performances for searching, but really fast creation and filling.
class BoxedArray[E: Boxed[Numeric]]
super BoxedCollection[E]
class BoxedArray[E: Boxed[Numeric]]
super BoxedCollection[E]
+ super Array[E]
- private var data: Array[E] = new Array[E]
-
- redef fun add(item) do data.add(item)
- redef fun items_overlapping(item): SimpleCollection[E]
+ redef fun items_overlapping(item)
do
var arr = new Array[E]
do
var arr = new Array[E]
- for i in data do
+ for i in self do
if i.intersects(item) then arr.add(i)
end
return arr
end
if i.intersects(item) then arr.add(i)
end
return arr
end
-
- redef fun iterator do return data.iterator
end
end