@@ -151,19 +151,33 @@ $Radius = 10,
151151$Angle = 60
152152)
153153
154-
155- # Determine the absolute angle, for this
154+ # Determine the absolute angle, for this operation
156155$absAngle = [Math]::Abs($angle)
157- $circumferenceStep = ([Math]::PI * 2 * $Radius) / $absAngle
158156
159- $iteration = $angle / [Math]::Floor($absAngle)
160- $angleDelta = 0
161- $null = while ([Math]::Abs($angleDelta) -lt $absAngle) {
162- $this.Forward($circumferenceStep)
163- $this.Rotate($iteration)
157+ if ($absAngle -eq 0) { return $this }
158+
159+ # Determine the circumference of a circle of this radius
160+ $Circumference = ((2 * $Radius) * [Math]::PI)
161+
162+ # Clamp the angle, as arcs beyond 360 just continue to circle
163+ $ClampedAngle =
164+ if ($absAngle -gt 360) { 360 }
165+ elseif ($absAngle -lt -360) { -360}
166+ else { $absAngle }
167+ # The circumference step is the circumference divided by our clamped angle
168+ $CircumferenceStep = $Circumference / [Math]::Floor($ClampedAngle)
169+ # The iteration is as close to one or negative one as possible
170+ $iteration = $angle / [Math]::Floor($absAngle)
171+ # Start off at iteration 1
172+ $angleDelta = $iteration
173+ # while we have not reached the angle
174+ while ([Math]::Abs($angleDelta) -le $absAngle) {
175+ # Rotate and move forward
176+ $null = $this.Rotate($iteration).Forward($CircumferenceStep)
164177 $angleDelta+=$iteration
165178}
166179
180+ # Return this so we can keep the chain.
167181return $this
168182 </Script >
169183 </ScriptMethod >
0 commit comments