quadtree: use new constructors
authorJean Privat <jean@pryen.org>
Thu, 9 Apr 2015 13:30:39 +0000 (20:30 +0700)
committerJean Privat <jean@pryen.org>
Thu, 9 Apr 2015 13:30:39 +0000 (20:30 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/geometry/quadtree.nit

index 97c0783..8c2df3c 100644 (file)
@@ -29,7 +29,7 @@ import pipeline
 abstract class QuadTree[E: Boxed[Numeric]]
        super BoxedCollection[E]
 
-       protected var center: nullable Point[Numeric]
+       protected var center: nullable Point[Numeric] = null
        var data: Array[E] = new Array[E]
 
        #  ________________
@@ -39,20 +39,14 @@ abstract class QuadTree[E: Boxed[Numeric]]
        #  |   0   |   3   |
        #  |_______|_______|
 
-       protected var child0: nullable QuadTree[E]
-       protected var child1: nullable QuadTree[E]
-       protected var child2: nullable QuadTree[E]
-       protected var child3: nullable QuadTree[E]
+       protected var child0: nullable QuadTree[E] = null
+       protected var child1: nullable QuadTree[E] = null
+       protected var child2: nullable QuadTree[E] = null
+       protected var child3: nullable QuadTree[E] = null
 
        # represent the threshold before subdividing the node
-       protected var item_limit = 4
-       protected var parent_node: nullable QuadTree[E]
-
-       # create the quadtree and set the item limit for each node
-       init(limit: Int)
-       do
-               self.item_limit = limit
-       end
+       protected var item_limit: Int
+       protected var parent_node: nullable QuadTree[E] = null
 
        # create a node, giving him self as a parent. Used to create children nodes
        init with_parent(limit: Int, parent: QuadTree[E])
@@ -221,17 +215,10 @@ class SQuadTree[E: Boxed[Numeric]]
        # the height of the current node of the QuadTree
        var height: Numeric
 
-       init(l: Int, c: Point[Numeric], w: Numeric, h: Numeric)
-       do
-               self.item_limit = l
-               self.center = c
-               self.width = w
-               self.height = h
-       end
-
        init with_parent(l: Int, c: Point[Numeric], w: Numeric, h: Numeric, p: QuadTree[E])
        do
-               init(l, c, w, h)
+               init(l, w, h)
+               center = c
                self.parent_node = p
        end