geometry :: QuadTree :: defaultinit
geometry :: QuadTree :: item_limit
Maximum number of items in this node before subdividinggeometry :: QuadTree :: item_limit=
Maximum number of items in this node before subdividinggeometry :: QuadTree :: parent_node
Parent node in the treegeometry :: QuadTree :: parent_node=
Parent node in the treegeometry :: QuadTree :: with_parent
Create a child node toparent
geometry $ QuadTree :: items_overlapping
returns all the items overlapping withregion
core :: Collection :: CONCURRENT
Type of the concurrent variant of this collectionserialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Collection :: combinations
Allr
-length combinations on self (in same order) without repeated elements.
core :: Collection :: combinations_with_replacement
Allr
-length combination on self (in same order) with repeated elements.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: SimpleCollection :: defaultinit
geometry :: QuadTree :: defaultinit
core :: Collection :: defaultinit
core :: Object :: defaultinit
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
core :: Collection :: has_all
Does the collection contain at least each element ofother
?
core :: Collection :: has_any
Does the collection contain at least one element ofother
?
core :: Collection :: has_exactly
Does the collection contain exactly all the elements ofother
?
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
geometry :: QuadTree :: item_limit
Maximum number of items in this node before subdividinggeometry :: QuadTree :: item_limit=
Maximum number of items in this node before subdividinggeometry :: BoxedCollection :: items_overlapping
returns all the items overlapping withregion
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: output_class_name
Display class name on stdout (debug only).geometry :: QuadTree :: parent_node
Parent node in the treegeometry :: QuadTree :: parent_node=
Parent node in the treecore :: Collection :: permutations
Allr
-length permutations on self (all possible ordering) without repeated elements.
core :: Collection :: product
Cartesian product, overr
times self
.
core :: RemovableCollection :: remove
Remove an occurrence ofitem
core :: RemovableCollection :: remove_all
Remove all occurrences ofitem
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
core :: Collection :: to_concurrent
Wrapsself
in a thread-safe collection
core :: Collection :: to_counter
Create and fill up a counter with the elements of `self.core :: Collection :: to_curlslist
Convert Collection[String] to CURLSListserialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
core :: Collection :: to_shuffle
Return a new array made of elements in a random order.geometry :: QuadTree :: with_parent
Create a child node toparent
Serializer::serialize
# Abstract QuadTree implementing the basic functions and data
abstract class QuadTree[E: Boxed[Numeric]]
super BoxedCollection[E]
# Center coordinate of the children
protected var center: nullable Point[Numeric] = null
# Items in this node
protected var data = new Array[E]
# Children nodes, if not `is_leaf`
#
# ~~~raw
# ________________
# | | |
# | 1 | 2 |
# |-------|-------|
# | 0 | 3 |
# |_______|_______|
# ~~~
protected var children = new Array[QuadTree[E]]
# Maximum number of items in this node before subdividing
protected var item_limit: Int
# Parent node in the tree
protected var parent_node: nullable QuadTree[E] = null
# Create a child node to `parent`
init with_parent(limit: Int, parent: QuadTree[E])
do
init(limit)
self.parent_node = parent
end
redef fun items_overlapping(region): SimpleCollection[E] do
var res = new Array[E]
items_overlapping_in(region,res)
return res
end
# Add `item` to the tree, create children if `item_limit` is reached
redef fun add(item) do if self.is_leaf then self.data.add(item) else add_to_children(item)
private fun add_to_children(item: Boxed[Numeric])
do
if children.not_empty then
var center = center
assert center != null
if center.x > item.right then
if center.y > item.top then
children[0].add(item)
else if center.y < item.bottom then
children[1].add(item)
else
self.data.add(item)
end
else if center.x < item.left then
if center.y > item.top then
children[3].add(item)
else if center.y < item.bottom then
children[2].add(item)
else
self.data.add(item)
end
else if center.y > item.top then
self.data.add(item)
else if center.y < item.bottom then
self.data.add(item)
else
self.data.add(item)
end
end
end
redef fun is_empty
do
if is_leaf then return data.is_empty
assert children.length >= 4
return data.is_empty and children[0].is_empty and children[1].is_empty and children[2].is_empty and children[3].is_empty
end
# Return whether or not the Node is a leaf of the tree
fun is_leaf: Bool do return children.is_empty
# var dquadtree = new DQuadTree[Point[Int]](2)
# var p1 = new Point[Int](0,0)
# var p2 = new Point[Int](0,9)
# var p3 = new Point[Int](9,0)
# dquadtree.add(p1)
# dquadtree.add(p2)
# dquadtree.add(p3)
# var result = dquadtree.items_overlapping(p3)
# assert result.length == 1
# result.clear
# var p4 = new Point[Int](9,9)
# result = dquadtree.items_overlapping(p4)
# assert result.length == 0
# result = dquadtree.items_overlapping(p4.padded(10))
# assert result.length == 3
private fun items_overlapping_in(region: Boxed[Numeric], mdata: SimpleCollection[E])
do
if self.is_leaf and data.length >= item_limit then
subdivide
var data_copy = data
data = new Array[E]
#add to the right Node
for d in data_copy do
add_to_children(d)
end
end
for i in data do if i.intersects(region) then mdata.add(i)
if children.not_empty then
var center = center
assert center != null
if center.x > region.right then
if center.y > region.top then
children[0].items_overlapping_in(region, mdata)
else if center.y < region.bottom then
children[1].items_overlapping_in(region, mdata)
else
children[0].items_overlapping_in(region,mdata)
children[1].items_overlapping_in(region, mdata)
end
else if center.x < region.left then
if center.y > region.top then
children[3].items_overlapping_in(region, mdata)
else if center.y < region.bottom then
children[2].items_overlapping_in(region, mdata)
else
children[3].items_overlapping_in(region, mdata)
children[2].items_overlapping_in(region, mdata)
end
else if center.y > region.top then
children[0].items_overlapping_in(region, mdata)
children[3].items_overlapping_in(region, mdata)
else if center.y < region.bottom then
children[1].items_overlapping_in(region, mdata)
children[2].items_overlapping_in(region, mdata)
else
children[0].items_overlapping_in(region, mdata)
children[1].items_overlapping_in(region, mdata)
children[2].items_overlapping_in(region, mdata)
children[3].items_overlapping_in(region, mdata)
end
end
end
# Create children nodes, depends on the concrete implementation
protected fun subdivide is abstract
redef fun iterator
do
if is_leaf then return data.iterator
assert children.length >= 4
return data.iterator + children[0].iterator + children[1].iterator + children[2].iterator + children[3].iterator
end
end
lib/geometry/quadtree.nit:28,1--188,3