1 | // Copyright 2005 Google Inc. All Rights Reserved. |
---|---|
2 | |
3 | #include <math.h> |
4 | #include <stdio.h> |
5 | #include <iostream> |
6 | using std::ostream; |
7 | using std::cout; |
8 | using std::endl; |
9 | |
10 | #include "s1angle.h" |
11 | #include "s2latlng.h" |
12 | |
13 | S1Angle::S1Angle(S2Point const& x, S2Point const& y) |
14 | : radians_(x.Angle(y)) { |
15 | } |
16 | |
17 | S1Angle::S1Angle(S2LatLng const& x, S2LatLng const& y) |
18 | : radians_(x.GetDistance(y).radians()) { |
19 | } |
20 | |
21 | S1Angle S1Angle::Normalized() const { |
22 | S1Angle a(radians_); |
23 | a.Normalize(); |
24 | return a; |
25 | } |
26 | |
27 | void S1Angle::Normalize() { |
28 | radians_ = drem(radians_, 2.0 * M_PI); |
29 | if (radians_ <= -M_PI) radians_ = M_PI; |
30 | } |
31 | |
32 | ostream& operator<<(ostream& os, S1Angle const& a) { |
33 | double degrees = a.degrees(); |
34 | char buffer[13]; |
35 | int sz = snprintf(buffer, sizeof(buffer), "%.7f", degrees); |
36 | if (sz >= 0 && sz < sizeof(buffer)) { |
37 | return os << buffer; |
38 | } else { |
39 | return os << degrees; |
40 | } |
41 | } |
42 |