Skip to content

Commit 9090a0e

Browse files
haikalvidyaKeavon
andauthored
Update Polygon tool to draw stars/ngons so they're tilted upright (#1640)
* Update angel of new polygon and star tool * Math tidying up --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent a1f2a2b commit 9090a0e

File tree

1 file changed

+4
-2
lines changed
  • libraries/bezier-rs/src/subpath

1 file changed

+4
-2
lines changed

libraries/bezier-rs/src/subpath/core.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ impl<ManipulatorGroupId: crate::Identifier> Subpath<ManipulatorGroupId> {
240240

241241
/// Constructs a regular polygon (ngon). Based on `sides` and `radius`, which is the distance from the center to any vertex.
242242
pub fn new_regular_polygon(center: DVec2, sides: u64, radius: f64) -> Self {
243+
let angle_increment = std::f64::consts::TAU / (sides as f64);
243244
let anchor_positions = (0..sides).map(|i| {
244-
let angle = (i as f64) * std::f64::consts::TAU / (sides as f64);
245+
let angle = (i as f64) * angle_increment - std::f64::consts::FRAC_PI_2;
245246
let center = center + DVec2::ONE * radius;
246247
DVec2::new(center.x + radius * f64::cos(angle), center.y + radius * f64::sin(angle)) * 0.5
247248
});
@@ -250,8 +251,9 @@ impl<ManipulatorGroupId: crate::Identifier> Subpath<ManipulatorGroupId> {
250251

251252
/// Constructs a star polygon (n-star). See [new_regular_polygon], but with interspersed vertices at an `inner_radius`.
252253
pub fn new_star_polygon(center: DVec2, sides: u64, radius: f64, inner_radius: f64) -> Self {
254+
let angle_increment = 0.5 * std::f64::consts::TAU / (sides as f64);
253255
let anchor_positions = (0..sides * 2).map(|i| {
254-
let angle = (i as f64) * 0.5 * std::f64::consts::TAU / (sides as f64);
256+
let angle = (i as f64) * angle_increment - std::f64::consts::FRAC_PI_2;
255257
let center = center + DVec2::ONE * radius;
256258
let r = if i % 2 == 0 { radius } else { inner_radius };
257259
DVec2::new(center.x + r * f64::cos(angle), center.y + r * f64::sin(angle)) * 0.5

0 commit comments

Comments
 (0)