Skip to content

Commit 9ffa372

Browse files
committed
WIP trying to bump aabb-quadtree
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
1 parent 9191261 commit 9ffa372

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ epoll = { version = "4.3.1", optional = true }
3333
fxhash = { version = "0.2.1", optional = true }
3434

3535
# appctx
36-
aabb-quadtree = { version = "0.1.0", optional = true }
36+
# aabb-quadtree = { git = "https://github.com/avl/aabb-quadtree.git", rev = "ef2c835", optional = true } # https://github.com/TyOverby/aabb-quadtree/pull/1 # aabb-quadtree = { version = "0.2.0", optional = true }
37+
aabb-quadtree = { version = "0.2.0", optional = true }
38+
euclid = { version = "0.19.9", optional = true } # Identical version as aabb-quadtree's
39+
smallvec = { version = "0.6.14", optional = true } # Identical version as aabb-quadtree's
3740

3841
# hlua
3942
hlua = { version = "0.4.1", optional = true }
@@ -53,7 +56,7 @@ framebuffer-text-drawing = ["framebuffer-drawing", "rusttype"]
5356
input-types = []
5457
input = ["scan", "input-types", "evdev", "epoll", "fxhash"]
5558
battery = []
56-
appctx = ["framebuffer-text-drawing", "input", "aabb-quadtree"]
59+
appctx = ["framebuffer-text-drawing", "input", "aabb-quadtree", "euclid", "smallvec"]
5760

5861
enable-runtime-benchmarking = ["stopwatch"]
5962

src/appctx.rs

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#[cfg(feature = "hlua")]
22
use std::cell::UnsafeCell;
33
use std::collections::HashMap;
4-
#[cfg(not(feature = "hlua"))]
5-
use std::marker::PhantomData;
64
use std::ops::DerefMut;
75
use std::sync::atomic::{AtomicBool, Ordering};
86
use std::sync::RwLock;
97

10-
use aabb_quadtree::{geom, ItemId, QuadTree};
11-
#[cfg(feature = "hlua")]
12-
use log::warn;
8+
use aabb_quadtree::{ItemId, QuadTree};
9+
use euclid::{Rect, TypedPoint2D, TypedRect, UnknownUnit};
10+
use smallvec::Array;
1311

1412
use crate::framebuffer::cgmath;
1513
use crate::framebuffer::common::*;
@@ -44,7 +42,7 @@ pub struct ApplicationContext<'a> {
4442
#[cfg(feature = "hlua")]
4543
lua: UnsafeCell<Lua<'a>>,
4644
#[cfg(not(feature = "hlua"))]
47-
lua: PhantomData<&'a ()>,
45+
lua: std::marker::PhantomData<&'a ()>,
4846

4947
input_tx: std::sync::mpsc::Sender<InputEvent>,
5048
input_rx: std::sync::mpsc::Receiver<InputEvent>,
@@ -53,7 +51,7 @@ pub struct ApplicationContext<'a> {
5351
wacom_ctx: RwLock<Option<ev::EvDevContext>>,
5452
touch_ctx: RwLock<Option<ev::EvDevContext>>,
5553

56-
active_regions: QuadTree<ActiveRegionHandler>,
54+
active_regions: QuadTree<ActiveRegionHandler, f32, Array<Item = (ItemId, TypedRect<f32>)>>,
5755
ui_elements: HashMap<String, UIElementHandle>,
5856
}
5957

@@ -80,13 +78,13 @@ impl Default for ApplicationContext<'static> {
8078
input_rx,
8179
input_tx,
8280
ui_elements: HashMap::new(),
83-
active_regions: QuadTree::default(geom::Rect::from_points(
84-
&geom::Point { x: 0.0, y: 0.0 },
85-
&geom::Point {
86-
x: xres as f32,
87-
y: yres as f32,
88-
},
89-
)),
81+
active_regions: QuadTree::default(
82+
TypedRect::from_points([
83+
TypedPoint2D::new(0.0, 0.0),
84+
TypedPoint2D::new(xres as f32, yres as f32),
85+
]),
86+
10, // size hint for underlying HashMap::with_capacity_and_hasher
87+
),
9088
};
9189

9290
// Enable all std lib
@@ -149,7 +147,7 @@ impl<'a> ApplicationContext<'a> {
149147
pub fn execute_lua(&mut self, code: &str) {
150148
let lua = self.get_lua_ref();
151149
if let Err(e) = lua.execute::<hlua::AnyLuaValue>(code) {
152-
warn!("Error in Lua Context: {:?}", e);
150+
log::warn!("Error in Lua Context: {:?}", e);
153151
}
154152
}
155153

@@ -534,14 +532,14 @@ impl<'a> ApplicationContext<'a> {
534532
}
535533

536534
pub fn find_active_region(&self, y: u16, x: u16) -> Option<(&ActiveRegionHandler, ItemId)> {
537-
let matches = self.active_regions.query(geom::Rect::centered_with_radius(
538-
&geom::Point {
539-
y: f32::from(y),
540-
x: f32::from(x),
541-
},
542-
2.0,
543-
));
544-
matches.first().map(|res| (res.0, res.2))
535+
let matches = self.active_regions.query({
536+
let radius = 2.0;
537+
let v = euclid::TypedVector2D::new(radius, radius);
538+
let p = euclid::TypedPoint2D::new(f32::from(x), f32::from(y));
539+
// A rect centered on (x,y) with radius 2
540+
TypedRect::from_points([(p - v), (p + v)])
541+
});
542+
matches.first().map(|(region, _, item)| (region, item))
545543
}
546544

547545
pub fn remove_active_region_at_point(&mut self, y: u16, x: u16) -> bool {
@@ -562,16 +560,10 @@ impl<'a> ApplicationContext<'a> {
562560
) {
563561
self.active_regions.insert_with_box(
564562
ActiveRegionHandler { handler, element },
565-
geom::Rect::from_points(
566-
&geom::Point {
567-
x: f32::from(x),
568-
y: f32::from(y),
569-
},
570-
&geom::Point {
571-
x: f32::from(x + width),
572-
y: f32::from(y + height),
573-
},
574-
),
563+
TypedRect::from_points([
564+
TypedPoint2D::new(f32::from(x), f32::from(y)),
565+
TypedPoint2D::new(f32::from(x + width), f32::from(y + height)),
566+
]),
575567
);
576568
}
577569
}

0 commit comments

Comments
 (0)