Skip to content

Commit

Permalink
Get rid of GeomBatch::unioned_polygon. All of the callers happened to be
Browse files Browse the repository at this point in the history
SVG icons that're circles, so just make a way to turn Bounds into a
Circle. #951
  • Loading branch information
dabreegster committed Aug 16, 2022
1 parent edcf855 commit c88baeb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/game/src/devtools/story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl StoryMapEditor {
.scale(0.5)
.centered_on(label_center),
);
let hitbox = draw_normal.unioned_polygon();
let hitbox = draw_normal.get_bounds().to_circle().to_polygon();
draw_hovered.append(
Text::from(&marker.label)
.bg(Color::CYAN)
Expand Down
8 changes: 7 additions & 1 deletion geom/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};

use aabb_quadtree::geom::{Point, Rect};

use crate::{Distance, LonLat, Polygon, Pt2D, Ring};
use crate::{Circle, Distance, LonLat, Polygon, Pt2D, Ring};

/// Represents a rectangular boundary of `Pt2D` points.
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -104,6 +104,12 @@ impl Bounds {
.into_polygon()
}

/// Creates a circle centered in the middle of this boundary. Always uses the half width as a
/// radius, so if the width and height don't match, this is pretty meaningless.
pub fn to_circle(&self) -> Circle {
Circle::new(self.center(), Distance::meters(self.width() / 2.0))
}

/// The width of this boundary.
// TODO Really should be Distance
pub fn width(&self) -> f64 {
Expand Down
4 changes: 2 additions & 2 deletions map_gui/src/render/turn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl DrawMovement {
let hitbox = if stage.protected_movements.contains(&movement.id) {
if movement.id.crosswalk {
batch = traffic_signal::walk_icon(movement, prerender);
batch.unioned_polygon()
batch.get_bounds().to_circle().to_polygon()
} else {
let arrow = movement
.geom
Expand Down Expand Up @@ -98,7 +98,7 @@ impl DrawMovement {
.make_arrow(BIG_ARROW_THICKNESS, ArrowCap::Triangle)
} else if movement.id.crosswalk {
batch = traffic_signal::dont_walk_icon(movement, prerender);
batch.unioned_polygon()
batch.get_bounds().to_circle().to_polygon()
} else {
// Use circular icons for banned turns
let offset = movement
Expand Down
9 changes: 0 additions & 9 deletions widgetry/src/geom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,6 @@ impl GeomBatch {
self
}

/// Builds a single polygon covering everything in this batch. Use to create a hitbox.
pub fn unioned_polygon(&self) -> Polygon {
let mut result = self.list[0].1.clone();
for (_, p, _) in &self.list[1..] {
result = result.union(p.clone());
}
result
}

/// True when the batch is empty.
pub fn is_empty(&self) -> bool {
self.list.is_empty()
Expand Down

0 comments on commit c88baeb

Please sign in to comment.