Instantly share code, notes, and snippets.

Embed
What would you like to do?
First attempt at snapping to angle intervals in Trgnmtry
public func snappedAngle(snappingAngle: Angle) -> Angle {
if snappingAngle.radians == 0 {
return self
}
let interval = Int(degrees / (snappingAngle.degrees / 2))
if interval == 0 {
return .zero
} else if interval == Int(360 / (snappingAngle.degrees / 2) - 1) {
return Angle(degrees: 360)
} else {
let factor = interval / 2
return Angle(radians: snappingAngle.radians * Radian(factor))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment