Skip to content

Commit

Permalink
Give up on trying to make a Ring for drawing partial Circles. #951
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Sep 5, 2022
1 parent 274f1ef commit b2740f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ abstutil = { path = "abstutil" }
polylabel = { git = "https://github.com/urschrei/polylabel-rs", rev = "b919b8587b491b9a952a6d4c0670558bfd38e034" }

# To temporarily work on dependencies locally, uncomment this
# TODO Do not commit. Update each repo
[patch."https://github.com/a-b-street/osm2streets"]
import_streets = { path = "/home/dabreegster/osm2streets/import_streets" }
street_network = { path = "/home/dabreegster/osm2streets/street_network" }
16 changes: 7 additions & 9 deletions apps/santa/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,13 @@ impl Game {
// TODO I couldn't quite work out how to get the partial outline from Figma working
let center = Pt2D::new(0.0, 0.0);
let outer = Distance::meters(30.0);
let draw = GeomBatch::from(vec![
(Color::WHITE, Circle::new(center, outer).to_polygon()),
(
Color::hex("#5D92C2"),
Circle::new(center, outer).to_partial_polygon(pct),
),
])
.autocrop()
.into_widget(ctx);
let mut batch = GeomBatch::new();
batch.push(Color::WHITE, Circle::new(center, outer).to_polygon());
batch.push(
Color::hex("#5D92C2"),
Circle::new(center, outer).to_partial_tessellation(pct),
);
let draw = batch.autocrop().into_widget(ctx);
self.time_panel.replace(ctx, "time circle", draw);
}

Expand Down
11 changes: 3 additions & 8 deletions geom/src/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ impl Circle {
self.to_ring().into_polygon()
}

/// Renders some percent, between [0, 1], of the circle as a polygon. The polygon starts from 0
/// degrees.
pub fn to_partial_polygon(&self, percent_full: f64) -> Polygon {
/// Renders some percent, between [0, 1], of the circle. The shape starts from 0 degrees.
pub fn to_partial_tessellation(&self, percent_full: f64) -> Tessellation {
#![allow(clippy::float_cmp)]
assert!((0. ..=1.).contains(&percent_full));
let mut pts = vec![self.center];
Expand All @@ -65,11 +64,7 @@ impl Circle {
indices.pop();
}
}
// TODO use to_ring? urgh
Polygon::pretessellated(
vec![Ring::must_new(pts.clone())],
Tessellation::new(pts, indices),
)
Tessellation::new(pts, indices)
}

/// Returns the ring around the circle.
Expand Down
2 changes: 1 addition & 1 deletion map_gui/src/render/traffic_signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn draw_time_left(
);
batch.push(
app.cs().signal_spinner,
Circle::new(center, radius).to_partial_polygon(percent),
Circle::new(center, radius).to_partial_tessellation(percent),
);
batch.append(
Text::from(format!("{}", idx + 1))
Expand Down

0 comments on commit b2740f4

Please sign in to comment.