@@ -240,8 +240,9 @@ impl<ManipulatorGroupId: crate::Identifier> Subpath<ManipulatorGroupId> {
240
240
241
241
/// Constructs a regular polygon (ngon). Based on `sides` and `radius`, which is the distance from the center to any vertex.
242
242
pub fn new_regular_polygon ( center : DVec2 , sides : u64 , radius : f64 ) -> Self {
243
+ let angle_increment = std:: f64:: consts:: TAU / ( sides as f64 ) ;
243
244
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 ;
245
246
let center = center + DVec2 :: ONE * radius;
246
247
DVec2 :: new ( center. x + radius * f64:: cos ( angle) , center. y + radius * f64:: sin ( angle) ) * 0.5
247
248
} ) ;
@@ -250,8 +251,9 @@ impl<ManipulatorGroupId: crate::Identifier> Subpath<ManipulatorGroupId> {
250
251
251
252
/// Constructs a star polygon (n-star). See [new_regular_polygon], but with interspersed vertices at an `inner_radius`.
252
253
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 ) ;
253
255
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 ;
255
257
let center = center + DVec2 :: ONE * radius;
256
258
let r = if i % 2 == 0 { radius } else { inner_radius } ;
257
259
DVec2 :: new ( center. x + r * f64:: cos ( angle) , center. y + r * f64:: sin ( angle) ) * 0.5
0 commit comments