Skip to content

Commit

Permalink
Merge pull request #230 from jmr/update-2022-02-17
Browse files Browse the repository at this point in the history
Update to latest google3 version

* Remove deprecated s2textformat functions (where ...OrDie should be
  used instead)
* Use absl::make_unique instead of raw new in some places
* Add missing includes
* Deprecate many functions taking const pointers; change to const
  references
* Deprecate InterpolateAtDistance (use GetPointOnLine instead)
  • Loading branch information
jmr authored Feb 17, 2022
2 parents e8ae290 + ac89113 commit 0e7b146
Show file tree
Hide file tree
Showing 117 changed files with 903 additions and 730 deletions.
1 change: 1 addition & 0 deletions doc/examples/term_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cstdint>
#include <cstdio>
#include <set>
#include <string>
#include <vector>

#include "s2/base/commandlineflags.h"
Expand Down
2 changes: 1 addition & 1 deletion src/python/s2_common.i
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ class S2Point {
%unignore S2Polygon::GetCentroid;
%unignore S2Polygon::GetDistance;
%unignore S2Polygon::GetLastDescendant(int) const;
%unignore S2Polygon::GetOverlapFractions(const S2Polygon*, const S2Polygon*);
%unignore S2Polygon::GetOverlapFractions(const S2Polygon&, const S2Polygon&);
%unignore S2Polygon::GetRectBound;
%unignore S2Polygon::Init;
%unignore S2Polygon::InitNested;
Expand Down
2 changes: 2 additions & 0 deletions src/s2/encoded_s2cell_id_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "s2/encoded_s2cell_id_vector.h"

#include <algorithm>

#include "s2/util/bits/bits.h"

using absl::Span;
Expand Down
2 changes: 2 additions & 0 deletions src/s2/encoded_s2point_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "s2/encoded_s2point_vector.h"

#include <algorithm>

#include "absl/base/internal/unaligned_access.h"
#include "s2/util/bits/bits.h"
#include "s2/s2cell_id.h"
Expand Down
1 change: 1 addition & 0 deletions src/s2/encoded_s2point_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define S2_ENCODED_S2POINT_VECTOR_H_

#include <atomic>

#include "absl/types/span.h"
#include "s2/encoded_string_vector.h"
#include "s2/encoded_uint_vector.h"
Expand Down
5 changes: 4 additions & 1 deletion src/s2/encoded_s2shape_index_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

#include "s2/encoded_s2shape_index.h"

#include <algorithm>
#include <map>
#include <utility>
#include <vector>

#include <gtest/gtest.h>
#include "absl/base/call_once.h"
#include "absl/flags/flag.h"
#include "absl/memory/memory.h"
#include "absl/strings/escaping.h"
Expand Down Expand Up @@ -162,7 +165,7 @@ TEST(EncodedS2ShapeIndex, OverlappingPolylines) {
vector<S2Point> vertices;
int n = test_case.num_shape_edges;
for (int j = 0; j <= n; ++j) {
vertices.push_back(S2::InterpolateAtDistance(j * edge_len, a, b));
vertices.push_back(S2::GetPointOnLine(a, b, j * edge_len));
}
index.Add(make_unique<S2LaxPolylineShape>(vertices));
}
Expand Down
1 change: 1 addition & 0 deletions src/s2/encoded_string_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <memory>
#include <string>

#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "s2/encoded_uint_vector.h"
Expand Down
1 change: 1 addition & 0 deletions src/s2/encoded_string_vector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "s2/encoded_string_vector.h"

#include <vector>

#include <gtest/gtest.h>
#include "absl/strings/string_view.h"

Expand Down
1 change: 1 addition & 0 deletions src/s2/encoded_uint_vector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "s2/encoded_uint_vector.h"

#include <vector>

#include <gtest/gtest.h>

using std::vector;
Expand Down
1 change: 1 addition & 0 deletions src/s2/id_set_lexicon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "s2/id_set_lexicon.h"

#include <algorithm>
#include <utility>
#include <vector>

#include "s2/base/logging.h"
Expand Down
1 change: 1 addition & 0 deletions src/s2/mutable_s2shape_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <algorithm>
#include <atomic>
#include <cmath>
#include <utility>

#include "s2/base/casts.h"
#include "s2/base/commandlineflags.h"
Expand Down
5 changes: 4 additions & 1 deletion src/s2/mutable_s2shape_index_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

#include "s2/mutable_s2shape_index.h"

#include <algorithm>
#include <functional>
#include <memory>
#include <numeric>
#include <thread>
#include <string>
#include <utility>
#include <vector>

#include <gtest/gtest.h>
Expand Down Expand Up @@ -720,7 +723,7 @@ TEST_F(MutableS2ShapeIndexTest, LinearSpace) {
}
// Create the clusters of short edges.
for (int k = 0; k < num_clusters; ++k) {
S2Point p = S2::Interpolate(k / (num_clusters - 1.0), a, b);
S2Point p = S2::Interpolate(a, b, k / (num_clusters - 1.0));
vector<S2Point> points(edges_per_cluster, p);
index_.Add(make_unique<S2PointVectorShape>(points));
}
Expand Down
1 change: 1 addition & 0 deletions src/s2/r1interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ostream>

#include "s2/base/logging.h"
#include "s2/_fp_contract_off.h"
Expand Down
1 change: 1 addition & 0 deletions src/s2/r2rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define S2_R2RECT_H_

#include <iosfwd>
#include <ostream>

#include "s2/base/logging.h"
#include "s2/_fp_contract_off.h"
Expand Down
6 changes: 3 additions & 3 deletions src/s2/s1angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ class S1Angle {
// Normalize this angle to the range (-180, 180] degrees.
void Normalize();

// When S1Angle is used as a key in one of the btree container types
// (util/btree), indicate that linear rather than binary search should be
// used. This is much faster when the comparison function is cheap.
// When S1Angle is used as a key in one of the absl::btree container types,
// indicate that linear rather than binary search should be used. This is
// much faster when the comparison function is cheap.
typedef std::true_type absl_btree_prefer_linear_node_search;

private:
Expand Down
1 change: 1 addition & 0 deletions src/s2/s1chord_angle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "s2/s1chord_angle.h"

#include <algorithm>
#include <cfloat>
#include <cmath>

Expand Down
7 changes: 4 additions & 3 deletions src/s2/s1chord_angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef S2_S1CHORD_ANGLE_H_
#define S2_S1CHORD_ANGLE_H_

#include <algorithm>
#include <cmath>
#include <limits>
#include <ostream>
Expand Down Expand Up @@ -286,9 +287,9 @@ class S1ChordAngle {
// Infinity() are both considered valid.
bool is_valid() const;

// When S1ChordAngle is used as a key in one of the btree container types
// (util/btree), indicate that linear rather than binary search should be
// used. This is much faster when the comparison function is cheap.
// When S1ChordAngle is used as a key in one of the absl::btree container
// types, indicate that linear rather than binary search should be used.
// This is much faster when the comparison function is cheap.
typedef std::true_type absl_btree_prefer_linear_node_search;

private:
Expand Down
2 changes: 1 addition & 1 deletion src/s2/s1chord_angle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ TEST(S1ChordAngle, GetS2PointConstructorMaxError) {
if (rnd.OneIn(10)) {
// Occasionally test a point pair that is nearly identical or antipodal.
S1Angle r = S1Angle::Radians(1e-15 * rnd.RandDouble());
y = S2::InterpolateAtDistance(r, x, y);
y = S2::GetPointOnLine(x, y, r);
if (rnd.OneIn(2)) y = -y;
}
S1ChordAngle dist = S1ChordAngle(x, y);
Expand Down
35 changes: 18 additions & 17 deletions src/s2/s2boolean_operation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ TEST(S2BooleanOperation, PointSemiOpenPolygonVertex) {
// not the other under PolygonModel::SEMI_OPEN. (The same vertices are used
// for all three PolygonModel options.)
auto polygon = s2textformat::MakePolygonOrDie("0:0, 0:1, 1:0");
ASSERT_TRUE(polygon->Contains(s2textformat::MakePoint("0:1")));
ASSERT_FALSE(polygon->Contains(s2textformat::MakePoint("1:0")));
ASSERT_TRUE(polygon->Contains(s2textformat::MakePointOrDie("0:1")));
ASSERT_FALSE(polygon->Contains(s2textformat::MakePointOrDie("1:0")));
auto a = "0:1 | 1:0 # #";
auto b = "# # 0:0, 0:1, 1:0";
ExpectResult(OpType::UNION, options, a, b,
Expand Down Expand Up @@ -519,14 +519,14 @@ TEST(S2BooleanOperation, TestSemiOpenPolygonVerticesContained) {
// Verify whether certain vertices of the test polygon are contained under
// the semi-open boundary model (for use in the tests below).
auto polygon = s2textformat::MakePolygonOrDie(kVertexTestPolygonStr());
EXPECT_TRUE(polygon->Contains(s2textformat::MakePoint("0:1")));
EXPECT_TRUE(polygon->Contains(s2textformat::MakePoint("0:2")));
EXPECT_TRUE(polygon->Contains(s2textformat::MakePoint("0:3")));
EXPECT_TRUE(polygon->Contains(s2textformat::MakePoint("0:4")));
EXPECT_FALSE(polygon->Contains(s2textformat::MakePoint("5:1")));
EXPECT_FALSE(polygon->Contains(s2textformat::MakePoint("5:2")));
EXPECT_FALSE(polygon->Contains(s2textformat::MakePoint("5:3")));
EXPECT_FALSE(polygon->Contains(s2textformat::MakePoint("5:4")));
EXPECT_TRUE(polygon->Contains(s2textformat::MakePointOrDie("0:1")));
EXPECT_TRUE(polygon->Contains(s2textformat::MakePointOrDie("0:2")));
EXPECT_TRUE(polygon->Contains(s2textformat::MakePointOrDie("0:3")));
EXPECT_TRUE(polygon->Contains(s2textformat::MakePointOrDie("0:4")));
EXPECT_FALSE(polygon->Contains(s2textformat::MakePointOrDie("5:1")));
EXPECT_FALSE(polygon->Contains(s2textformat::MakePointOrDie("5:2")));
EXPECT_FALSE(polygon->Contains(s2textformat::MakePointOrDie("5:3")));
EXPECT_FALSE(polygon->Contains(s2textformat::MakePointOrDie("5:4")));
}

// Don't bother testing every PolylineModel with every PolygonModel for vertex
Expand Down Expand Up @@ -777,10 +777,10 @@ TEST(S2BooleanOperation, PolylineEdgeOpenPolygonEdgeOverlap) {

TEST(S2BooleanOperation, PolylineEdgeSemiOpenPolygonEdgeOverlap) {
auto polygon = s2textformat::MakePolygonOrDie("1:1, 1:3, 3:3, 3:1");
ASSERT_FALSE(polygon->Contains(s2textformat::MakePoint("1:1")));
ASSERT_TRUE(polygon->Contains(s2textformat::MakePoint("1:3")));
ASSERT_FALSE(polygon->Contains(s2textformat::MakePoint("3:3")));
ASSERT_FALSE(polygon->Contains(s2textformat::MakePoint("3:1")));
ASSERT_FALSE(polygon->Contains(s2textformat::MakePointOrDie("1:1")));
ASSERT_TRUE(polygon->Contains(s2textformat::MakePointOrDie("1:3")));
ASSERT_FALSE(polygon->Contains(s2textformat::MakePointOrDie("3:3")));
ASSERT_FALSE(polygon->Contains(s2textformat::MakePointOrDie("3:1")));
S2BooleanOperation::Options options;
options.set_polygon_model(PolygonModel::SEMI_OPEN);
auto a = "# 1:1, 1:3, 3:3 | 3:3, 1:3 # ";
Expand Down Expand Up @@ -1695,7 +1695,7 @@ TEST(S2BooleanOperation, SelfIntersectingPolylines) {

// Subtracts a degenerate loop along the 180 degree meridian from the given
// input geometry, and compares the result to "expected_str". The inputs should
// be in the format expected by s2textformat::MakeIndex().
// be in the format expected by s2textformat::MakeIndexOrDie().
void TestMeridianSplitting(const char* input_str, const char* expected_str) {
auto input = s2textformat::MakeIndexOrDie(input_str);
MutableS2ShapeIndex meridian;
Expand Down Expand Up @@ -2053,7 +2053,7 @@ TEST(S2BooleanOperation, GetCrossedVertexIndexBug6) {
}

// Performs the given operation and compares the result to "expected_str". All
// arguments are in s2textformat::MakeLaxPolygon() format.
// arguments are in s2textformat::MakeLaxPolygonOrDie() format.
void ExpectPolygon(S2BooleanOperation::OpType op_type, const string& a_str,
const string& b_str, const string& expected_str) {
auto a = s2textformat::MakeIndexOrDie(string("# # ") + a_str);
Expand All @@ -2072,7 +2072,8 @@ void ExpectPolygon(S2BooleanOperation::OpType op_type, const string& a_str,
}

TEST(S2BooleanOperation, FullAndEmptyResults) {
// The following constants are all in s2textformat::MakeLaxPolygon() format.
// The following constants are all in s2textformat::MakeLaxPolygonOrDie()
// format.
string kEmpty = "";
string kFull = "full";

Expand Down
22 changes: 11 additions & 11 deletions src/s2/s2builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ TEST(S2Builder, MaxEdgeDeviation) {
EXPECT_EQ(a, output.vertex(0));
EXPECT_EQ(b, output.vertex(n - 1));
for (int i = 0; i + 1 < n; ++i) {
EXPECT_TRUE(S2::IsEdgeBNearEdgeA(
a, b, output.vertex(i), output.vertex(i + 1), max_deviation))
<< "Iteration " << iter << ": (" << s2textformat::ToString(a)
<< ", " << s2textformat::ToString(S2::Interpolate(0.5, a, b))
<< "), " << s2textformat::ToString(output);
EXPECT_TRUE(S2::IsEdgeBNearEdgeA(a, b, output.vertex(i),
output.vertex(i + 1), max_deviation))
<< "Iteration " << iter << ": (" << s2textformat::ToString(a) << ", "
<< s2textformat::ToString(S2::Interpolate(a, b, 0.5)) << "), "
<< s2textformat::ToString(output);
}
if (n > 2) ++num_effective;
}
Expand Down Expand Up @@ -1343,9 +1343,9 @@ TEST(S2Builder, HighPrecisionStressTest) {
// v2 is located along (v0,v1) but is perturbed by up to 2 * snap_radius.
S2Point v1 = ChoosePoint(), v0_dir = ChoosePoint();
double d0 = pow(1e-16, rnd.RandDouble());
S2Point v0 = S2::InterpolateAtDistance(S1Angle::Radians(d0), v1, v0_dir);
S2Point v0 = S2::GetPointOnLine(v1, v0_dir, S1Angle::Radians(d0));
double d2 = 0.5 * d0 * pow(1e-16, pow(rnd.RandDouble(), 2));
S2Point v2 = S2::InterpolateAtDistance(S1Angle::Radians(d2), v1, v0_dir);
S2Point v2 = S2::GetPointOnLine(v1, v0_dir, S1Angle::Radians(d2));
v2 = S2Testing::SamplePoint(S2Cap(v2, 2 * snap_radius));
// Vary the edge directions by randomly swapping v0 and v2.
if (rnd.OneIn(2)) std::swap(v0, v2);
Expand All @@ -1358,10 +1358,10 @@ TEST(S2Builder, HighPrecisionStressTest) {
S2Point v3;
if (rnd.OneIn(5)) {
v3 = rnd.OneIn(2) ? v1 : v2;
v3 = S2::InterpolateAtDistance(d3, v3, ChoosePoint());
v3 = S2::GetPointOnLine(v3, ChoosePoint(), d3);
} else {
v3 = S2::Interpolate(pow(1e-16, rnd.RandDouble()), v1, v2);
v3 = S2::InterpolateAtDistance(d3, v3, v1.CrossProd(v2).Normalize());
v3 = S2::Interpolate(v1, v2, pow(1e-16, rnd.RandDouble()));
v3 = S2::GetPointOnLine(v3, v1.CrossProd(v2).Normalize(), d3);
}
S2Builder::Options options((IdentitySnapFunction(snap_radius)));
options.set_idempotent(false);
Expand Down Expand Up @@ -1488,7 +1488,7 @@ void TestSnappingWithForcedVertices(const char* input_str,
const char* vertices_str,
const char* expected_str) {
S2Builder builder{S2Builder::Options{IdentitySnapFunction(snap_radius)}};
vector<S2Point> vertices = s2textformat::ParsePoints(vertices_str);
vector<S2Point> vertices = s2textformat::ParsePointsOrDie(vertices_str);
for (const auto& vertex : vertices) {
builder.ForceVertex(vertex);
}
Expand Down
1 change: 1 addition & 0 deletions src/s2/s2builderutil_closed_set_normalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define S2_S2BUILDERUTIL_CLOSED_SET_NORMALIZER_H_

#include <vector>

#include "s2/id_set_lexicon.h"
#include "s2/s2builder_graph.h"
#include "s2/s2builderutil_find_polygon_degeneracies.h"
Expand Down
8 changes: 5 additions & 3 deletions src/s2/s2builderutil_closed_set_normalizer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "s2/s2builderutil_closed_set_normalizer.h"

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include <gtest/gtest.h>
Expand Down Expand Up @@ -114,7 +116,7 @@ void NormalizeTest::Run(const string& input_str,
void NormalizeTest::AddLayers(absl::string_view str,
const vector<GraphOptions>& graph_options,
vector<Graph>* graphs_out, S2Builder* builder) {
auto index = s2textformat::MakeIndex(str);
auto index = s2textformat::MakeIndexOrDie(str);
for (int dim = 0; dim < 3; ++dim) {
builder->StartLayer(make_unique<GraphAppendingLayer>(
graph_options[dim], graphs_out, &graph_clones_));
Expand Down Expand Up @@ -246,11 +248,11 @@ TEST(ComputeUnion, MixedGeometry) {
// - Degenerate polygon holes are removed
// - Points coincident with polyline or polygon edges are removed
// - Polyline edges coincident with polygon edges are removed
auto a = s2textformat::MakeIndex(
auto a = s2textformat::MakeIndexOrDie(
"0:0 | 10:10 | 20:20 # "
"0:0, 0:10 | 0:0, 10:0 | 15:15, 16:16 # "
"0:0, 0:10, 10:10, 10:0; 0:0, 1:1; 2:2; 10:10, 11:11; 12:12");
auto b = s2textformat::MakeIndex(
auto b = s2textformat::MakeIndexOrDie(
"0:10 | 10:0 | 3:3 | 16:16 # "
"10:10, 0:10 | 10:10, 10:0 | 5:5, 6:6 # "
"19:19, 19:21, 21:21, 21:19");
Expand Down
1 change: 1 addition & 0 deletions src/s2/s2builderutil_find_polygon_degeneracies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "s2/s2builderutil_find_polygon_degeneracies.h"

#include <algorithm>
#include <cstdlib>
#include <utility>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion src/s2/s2builderutil_lax_polygon_layer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ TEST(IndexedLaxPolygonLayer, AddsShape) {
MutableS2ShapeIndex index;
builder.StartLayer(make_unique<IndexedLaxPolygonLayer>(&index));
const string& polygon_str = "0:0, 0:10, 10:0";
builder.AddPolygon(*s2textformat::MakePolygon(polygon_str));
builder.AddPolygon(*s2textformat::MakePolygonOrDie(polygon_str));
S2Error error;
ASSERT_TRUE(builder.Build(&error));
EXPECT_EQ(1, index.num_shape_ids());
Expand Down
2 changes: 1 addition & 1 deletion src/s2/s2builderutil_s2point_vector_layer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void VerifyS2PointVectorLayerResults(
absl::string_view str_expected_points,
const vector<vector<int32>>& expected_labels) {
vector<S2Point> expected_points =
s2textformat::ParsePoints(str_expected_points);
s2textformat::ParsePointsOrDie(str_expected_points);

ASSERT_EQ(expected_labels.size(), label_set_ids.size());
for (int i = 0; i < output.size(); ++i) {
Expand Down
Loading

0 comments on commit 0e7b146

Please sign in to comment.