Commit 35ec5d3614fc67cb13acb1bf1b1d9556cf8c32ab
1 parent
28eea9b4
Fix sin and cos handling for negative degrees
Showing
1 changed file
with
9 additions
and
3 deletions
@@ -45,7 +45,9 @@ pub trait Trig { | @@ -45,7 +45,9 @@ pub trait Trig { | ||
45 | 91 ..=180 => Self::sintab()[180 - d as usize], | 45 | 91 ..=180 => Self::sintab()[180 - d as usize], |
46 | 181..=270 => -Self::sintab()[d as usize - 180], | 46 | 181..=270 => -Self::sintab()[d as usize - 180], |
47 | 271..=359 => -Self::sintab()[360 - d as usize], | 47 | 271..=359 => -Self::sintab()[360 - d as usize], |
48 | - _ => Self::sin(d % 360), | 48 | + _ => { |
49 | + Self::sin(if d < 0 { d % 360 + 360 } else { d % 360 }) | ||
50 | + }, | ||
49 | } | 51 | } |
50 | } | 52 | } |
51 | 53 | ||
@@ -56,7 +58,9 @@ pub trait Trig { | @@ -56,7 +58,9 @@ pub trait Trig { | ||
56 | 91 ..=180 => -Self::sintab()[90 - (180 - d as usize)], | 58 | 91 ..=180 => -Self::sintab()[90 - (180 - d as usize)], |
57 | 181..=270 => -Self::sintab()[90 - (d as usize - 180)], | 59 | 181..=270 => -Self::sintab()[90 - (d as usize - 180)], |
58 | 271..=359 => Self::sintab()[90 - (360 - d as usize)], | 60 | 271..=359 => Self::sintab()[90 - (360 - d as usize)], |
59 | - _ => Self::cos(d % 360), | 61 | + _ => { |
62 | + Self::cos(if d < 0 { d % 360 + 360 } else { d % 360 }) | ||
63 | + }, | ||
60 | } | 64 | } |
61 | } | 65 | } |
62 | 66 | ||
@@ -64,7 +68,9 @@ pub trait Trig { | @@ -64,7 +68,9 @@ pub trait Trig { | ||
64 | match d { | 68 | match d { |
65 | 0 ..=179 => Self::tantab()[d as usize], | 69 | 0 ..=179 => Self::tantab()[d as usize], |
66 | 180..=359 => Self::tantab()[d as usize - 180], | 70 | 180..=359 => Self::tantab()[d as usize - 180], |
67 | - _ => Self::tan(d % 360), | 71 | + _ => { |
72 | + Self::tan(if d < 0 { d % 360 + 360 } else { d % 360 }) | ||
73 | + }, | ||
68 | } | 74 | } |
69 | } | 75 | } |
70 | } | 76 | } |
Please
register
or
login
to post a comment