Skip to content

Commit

Permalink
get_within_dist bad behavior, using simpler solution
Browse files Browse the repository at this point in the history
  • Loading branch information
DavJCosby committed Feb 7, 2024
1 parent 4f10aa5 commit 7d64426
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/sled/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl Filter {

pub fn and(&self, other: &Self) -> Self {
let mut filtered = self.led_indices.clone();

for led in &self.led_indices {
if !other.led_indices.contains(led) {
filtered.remove(led);
Expand Down
15 changes: 5 additions & 10 deletions src/sled/positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,11 @@ impl Sled {
pub fn get_within_dist_from(&self, dist: f32, pos: Vec2) -> Filter {
let mut all_within_distance = HashSet::new();

for (segment_index, segment) in self.line_segments.iter().enumerate() {
let intersections = segment.intersects_solid_circle(pos, dist);
let first = intersections.first();
let second = intersections.get(1);

if first.is_some() && second.is_some() {
let first = self.alpha_to_index(*first.unwrap(), segment_index);
let second = self.alpha_to_index(*second.unwrap(), segment_index);
let range = first.min(second)..first.max(second);
all_within_distance.extend(range);
let target_sq = dist.powi(2);

for led in &self.leds {
if led.position().distance_squared(pos) < target_sq {
all_within_distance.insert(led.index());
}
}

Expand Down

0 comments on commit 7d64426

Please sign in to comment.