Coverage Report

Created: 2026-09-02 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/s2geometry/src/s2/s1angle.cc
Line
Count
Source
1
// Copyright 2005 Google Inc. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
16
// Author: ericv@google.com (Eric Veach)
17
18
#include "s2/s1angle.h"
19
20
#include <cmath>
21
#include <ostream>
22
23
#include "absl/strings/str_format.h"
24
25
#include "s2/util/coding/coder.h"
26
#include "s2/s2error.h"
27
#include "s2/s2latlng.h"
28
#include "s2/s2point.h"
29
30
S1Angle::S1Angle(const S2Point& x, const S2Point& y)
31
0
    : radians_(x.Angle(y)) {
32
0
}
33
34
S1Angle::S1Angle(const S2LatLng& x, const S2LatLng& y)
35
0
    : radians_(x.GetDistance(y).radians()) {
36
0
}
37
38
0
S1Angle S1Angle::Normalized() const {
39
0
  S1Angle a(radians_);
40
0
  a.Normalize();
41
0
  return a;
42
0
}
43
44
0
void S1Angle::Normalize() {
45
0
  radians_ = remainder(radians_, 2.0 * M_PI);
46
0
  if (radians_ <= -M_PI) radians_ = M_PI;
47
0
}
48
49
0
void S1Angle::Coder::Encode(Encoder& encoder, const S1Angle& angle) const {
50
0
  encoder.Ensure(sizeof(double));
51
0
  encoder.putdouble(angle.radians());
52
0
}
53
54
bool S1Angle::Coder::Decode(Decoder& decoder, S1Angle& angle,
55
0
                            S2Error& error) const {
56
0
  if (decoder.avail() < sizeof(double)) {
57
0
    error = S2Error::DataLoss("Could not decode S1Angle.");
58
0
    return false;
59
0
  }
60
0
  angle = Radians(decoder.getdouble());
61
0
  return true;
62
0
}
63
64
0
std::ostream& operator<<(std::ostream& os, S1Angle a) {
65
0
  return os << absl::StreamFormat("%.7f", a.degrees());
66
0
}