Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP trying to bump aabb-quadtree #126

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ epoll = { version = "4.3.1", optional = true }
fxhash = { version = "0.2.1", optional = true }

# appctx
aabb-quadtree = { version = "0.1.0", optional = true }
# 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 }
aabb-quadtree = { version = "0.2.0", optional = true }
euclid = { version = "0.19.9", optional = true } # Identical version as aabb-quadtree's
smallvec = { version = "0.6.14", optional = true } # Identical version as aabb-quadtree's

# hlua
hlua = { git = "https://github.com/fenollp/hlua.git", rev = "f327e79", optional = true } # hlua = { version = "0.4.1", optional = true } TODO: https://github.com/tomaka/hlua/pull/223
Expand All @@ -53,7 +56,7 @@ framebuffer-text-drawing = ["framebuffer-drawing", "rusttype"]
input-types = []
input = ["scan", "input-types", "evdev", "epoll", "fxhash"]
battery = []
appctx = ["framebuffer-text-drawing", "input", "aabb-quadtree"]
appctx = ["framebuffer-text-drawing", "input", "aabb-quadtree", "euclid", "smallvec"]

enable-runtime-benchmarking = ["stopwatch"]

Expand Down
58 changes: 25 additions & 33 deletions src/appctx.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#[cfg(feature = "hlua")]
use std::cell::UnsafeCell;
use std::collections::HashMap;
#[cfg(not(feature = "hlua"))]
use std::marker::PhantomData;
use std::ops::DerefMut;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::RwLock;

use aabb_quadtree::{geom, ItemId, QuadTree};
#[cfg(feature = "hlua")]
use log::warn;
use aabb_quadtree::{ItemId, QuadTree};
use euclid::{Rect, TypedPoint2D, TypedRect, UnknownUnit};

Check warning on line 9 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused imports: `Rect` and `UnknownUnit`

Check warning on line 9 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

unused imports: `Rect` and `UnknownUnit`

Check warning on line 9 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

unused imports: `Rect` and `UnknownUnit`

Check failure on line 9 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `Rect` and `UnknownUnit`

Check warning on line 9 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

unused imports: `Rect` and `UnknownUnit`

Check warning on line 9 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

unused imports: `Rect` and `UnknownUnit`
use smallvec::Array;

use crate::framebuffer::cgmath;
use crate::framebuffer::common::*;
Expand Down Expand Up @@ -44,7 +42,7 @@
#[cfg(feature = "hlua")]
lua: UnsafeCell<Lua<'a>>,
#[cfg(not(feature = "hlua"))]
lua: PhantomData<&'a ()>,
lua: std::marker::PhantomData<&'a ()>,

input_tx: std::sync::mpsc::Sender<InputEvent>,
input_rx: std::sync::mpsc::Receiver<InputEvent>,
Expand All @@ -53,7 +51,7 @@
wacom_ctx: RwLock<Option<ev::EvDevContext>>,
touch_ctx: RwLock<Option<ev::EvDevContext>>,

active_regions: QuadTree<ActiveRegionHandler>,
active_regions: QuadTree<ActiveRegionHandler, f32, Array<Item = (ItemId, TypedRect<f32>)>>,

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the trait `smallvec::Array` cannot be made into an object

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

the trait `smallvec::Array` cannot be made into an object

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

the trait `smallvec::Array` cannot be made into an object

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

the trait `smallvec::Array` cannot be made into an object

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

the size for values of type `(dyn smallvec::Array<Item = (aabb_quadtree::ItemId, euclid::TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

the trait `smallvec::Array` cannot be made into an object

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

the trait `smallvec::Array` cannot be made into an object

Check failure on line 54 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time
ui_elements: HashMap<String, UIElementHandle>,
}

Expand All @@ -80,13 +78,13 @@
input_rx,
input_tx,
ui_elements: HashMap::new(),
active_regions: QuadTree::default(geom::Rect::from_points(
&geom::Point { x: 0.0, y: 0.0 },
&geom::Point {
x: xres as f32,
y: yres as f32,
},
)),
active_regions: QuadTree::default(

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the trait `smallvec::Array` cannot be made into an object

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

the trait `smallvec::Array` cannot be made into an object

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

the trait `smallvec::Array` cannot be made into an object

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

the trait `smallvec::Array` cannot be made into an object

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

the size for values of type `(dyn smallvec::Array<Item = (aabb_quadtree::ItemId, euclid::TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

the size for values of type `(dyn smallvec::Array<Item = (aabb_quadtree::ItemId, euclid::TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

the trait `smallvec::Array` cannot be made into an object

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

type mismatch resolving `<dyn Array<Item = (ItemId, TypedRect<f32>)> as Array>::Item == (ItemId, TypedRect<f32, f32>)`

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

the trait `smallvec::Array` cannot be made into an object

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time

Check failure on line 81 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

the size for values of type `(dyn smallvec::Array<Item = (ItemId, TypedRect<f32>)> + 'static)` cannot be known at compilation time
TypedRect::from_points([
TypedPoint2D::new(0.0, 0.0),
TypedPoint2D::new(xres as f32, yres as f32),
]),
10, // size hint for underlying HashMap::with_capacity_and_hasher
),
};

// Enable all std lib
Expand Down Expand Up @@ -149,7 +147,7 @@
pub fn execute_lua(&mut self, code: &str) {
let lua = self.get_lua_ref();
if let Err(e) = lua.execute::<hlua::AnyLuaValue>(code) {
warn!("Error in Lua Context: {:?}", e);
log::warn!("Error in Lua Context: {:?}", e);
}
}

Expand Down Expand Up @@ -534,19 +532,19 @@
}

pub fn find_active_region(&self, y: u16, x: u16) -> Option<(&ActiveRegionHandler, ItemId)> {
let matches = self.active_regions.query(geom::Rect::centered_with_radius(
&geom::Point {
y: f32::from(y),
x: f32::from(x),
},
2.0,
));
matches.first().map(|res| (res.0, res.2))
let matches = self.active_regions.query({

Check failure on line 535 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the method `query` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 535 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

the method `query` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 535 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

the method `query` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 535 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Clippy

the method `query` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 535 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

the method `query` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 535 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

the method `query` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied
let radius = 2.0;
let v = euclid::TypedVector2D::new(radius, radius);
let p = euclid::TypedPoint2D::new(f32::from(x), f32::from(y));
// A rect centered on (x,y) with radius 2
TypedRect::from_points([(p - v), (p + v)])
});
matches.first().map(|(region, _, item)| (region, item))
}

pub fn remove_active_region_at_point(&mut self, y: u16, x: u16) -> bool {
match self.find_active_region(y, x) {
Some((_, itemid)) => self.active_regions.remove(itemid).is_some(),

Check failure on line 547 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite

the method `remove` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 547 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Check

the method `remove` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 547 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Test Suite on gnueabihf

the method `remove` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 547 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with gnueabihf

the method `remove` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied

Check failure on line 547 in src/appctx.rs

View workflow job for this annotation

GitHub Actions / Demo with musl

the method `remove` exists for struct `QuadTree<ActiveRegionHandler, f32, dyn Array<Item = (ItemId, TypedRect<f32>)>>`, but its trait bounds were not satisfied
_ => false,
}
}
Expand All @@ -562,16 +560,10 @@
) {
self.active_regions.insert_with_box(
ActiveRegionHandler { handler, element },
geom::Rect::from_points(
&geom::Point {
x: f32::from(x),
y: f32::from(y),
},
&geom::Point {
x: f32::from(x + width),
y: f32::from(y + height),
},
),
TypedRect::from_points([
TypedPoint2D::new(f32::from(x), f32::from(y)),
TypedPoint2D::new(f32::from(x + width), f32::from(y + height)),
]),
);
}
}
Loading