From 1400e65ae2d3d6cf3c260b1fc8047dfceea5f259 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sat, 20 May 2017 10:44:03 -0700 Subject: [PATCH] geometry: make `BoxedArray` a subclass of `Array` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/geometry/boxes.nit | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/geometry/boxes.nit b/lib/geometry/boxes.nit index 314cde3..dc87cb5 100644 --- a/lib/geometry/boxes.nit +++ b/lib/geometry/boxes.nit @@ -322,22 +322,19 @@ interface BoxedCollection[E: Boxed[Numeric]] 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] + super Array[E] - private var data: Array[E] = new Array[E] - - redef fun add(item) do data.add(item) redef fun items_overlapping(item) 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 - - redef fun iterator do return data.iterator end -- 1.7.9.5