Skip to content

Commit bb82206

Browse files
committed
Update to latest google3 version
* Now requires abseil-cpp LTS 20240722 * S2Shape derived classes: Add decoding interface with S2Error * S2Error: Interface is now similar to absl::Status, just with a different error code type. In the future, this will probably be replaced by absl::Status. * S2CellId: Made some functions constexpr * S2DensityTree: Improved documentation of weight function * s2edge_crossings: Fix CompareEdges for a case that never happens * Optimize some functions using sincos() when available. * S2Projection: Fix numerical issue * S2Polygon uses new S2LegacyValidQuery to validate geometry. * S2ValidationQuery: New class
2 parents 3f901b9 + c9b89e2 commit bb82206

File tree

204 files changed

+4592
-1118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+4592
-1118
lines changed

CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ endif()
104104
include_directories(src)
105105

106106
add_library(s2
107+
src/s2/base/malloc_extension.cc
107108
src/s2/encoded_s2cell_id_vector.cc
108109
src/s2/encoded_s2point_vector.cc
109110
src/s2/encoded_s2shape_index.cc
110111
src/s2/encoded_string_vector.cc
111112
src/s2/id_set_lexicon.cc
113+
src/s2/internal/s2incident_edge_tracker.cc
114+
src/s2/internal/s2index_cell_data.cc
112115
src/s2/mutable_s2shape_index.cc
113116
src/s2/r2rect.cc
114117
src/s2/s1angle.cc
@@ -154,7 +157,6 @@ add_library(s2
154157
src/s2/s2fractal.cc
155158
src/s2/s2furthest_edge_query.cc
156159
src/s2/s2hausdorff_distance_query.cc
157-
src/s2/s2index_cell_data.cc
158160
src/s2/s2latlng.cc
159161
src/s2/s2latlng_rect.cc
160162
src/s2/s2latlng_rect_bounder.cc
@@ -334,6 +336,7 @@ install(FILES src/s2/_fp_contract_off.h
334336
src/s2/s2crossing_edge_query.h
335337
src/s2/s2debug.h
336338
src/s2/s2density_tree.h
339+
src/s2/s2density_tree_internal.h
337340
src/s2/s2distance_target.h
338341
src/s2/s2earth.h
339342
src/s2/s2edge_clipping.h
@@ -347,7 +350,6 @@ install(FILES src/s2/_fp_contract_off.h
347350
src/s2/s2fractal.h
348351
src/s2/s2furthest_edge_query.h
349352
src/s2/s2hausdorff_distance_query.h
350-
src/s2/s2index_cell_data.h
351353
src/s2/s2latlng.h
352354
src/s2/s2latlng_rect.h
353355
src/s2/s2latlng_rect_bounder.h
@@ -407,19 +409,24 @@ install(FILES src/s2/_fp_contract_off.h
407409
src/s2/s2shapeutil_visit_crossing_edge_pairs.h
408410
src/s2/s2testing.h
409411
src/s2/s2text_format.h
412+
src/s2/s2validation_query.h
410413
src/s2/s2wedge_relations.h
411414
src/s2/s2winding_operation.h
412415
src/s2/s2wrapped_shape.h
413416
src/s2/sequence_lexicon.h
414417
src/s2/thread_testing.h
415418
src/s2/value_lexicon.h
416-
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2")
417-
install(FILES src/s2/internal/s2meta.h
419+
DESTINATION include/s2)
420+
install(FILES src/s2/internal/s2disjoint_set.h
421+
src/s2/internal/s2incident_edge_tracker.h
422+
src/s2/internal/s2index_cell_data.h
423+
src/s2/internal/s2meta.h
418424
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/internal")
419425
install(FILES src/s2/base/casts.h
420426
src/s2/base/commandlineflags.h
421427
src/s2/base/commandlineflags_declare.h
422428
src/s2/base/log_severity.h
429+
src/s2/base/malloc_extension.h
423430
src/s2/base/port.h
424431
src/s2/base/spinlock.h
425432
src/s2/base/types.h
@@ -493,6 +500,8 @@ if (BUILD_TESTS)
493500
src/s2/encoded_uint_vector_test.cc
494501
src/s2/gmock_matchers_test.cc
495502
src/s2/id_set_lexicon_test.cc
503+
src/s2/internal/s2disjoint_set_test.cc
504+
src/s2/internal/s2index_cell_data_test.cc
496505
src/s2/mutable_s2shape_index_test.cc
497506
src/s2/r1interval_test.cc
498507
src/s2/r2rect_test.cc
@@ -547,7 +556,6 @@ if (BUILD_TESTS)
547556
src/s2/s2fractal_test.cc
548557
src/s2/s2furthest_edge_query_test.cc
549558
src/s2/s2hausdorff_distance_query_test.cc
550-
src/s2/s2index_cell_data_test.cc
551559
src/s2/s2latlng_rect_bounder_test.cc
552560
src/s2/s2latlng_rect_test.cc
553561
src/s2/s2latlng_test.cc
@@ -600,6 +608,7 @@ if (BUILD_TESTS)
600608
src/s2/s2shapeutil_shape_edge_id_test.cc
601609
src/s2/s2shapeutil_visit_crossing_edge_pairs_test.cc
602610
src/s2/s2text_format_test.cc
611+
src/s2/s2validation_query_test.cc
603612
src/s2/s2wedge_relations_test.cc
604613
src/s2/s2winding_operation_test.cc
605614
src/s2/s2wrapped_shape_test.cc

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ This issue may require revision of boringssl or exactfloat.
4949

5050
## Requirements for End Users using CMake
5151

52-
* [CMake](http://www.cmake.org/)
53-
* A C++ compiler with C++14 support, such as [g++ >= 5](https://gcc.gnu.org/)
54-
* [Abseil](https://github.com/abseil/abseil-cpp) >= LTS
55-
[`20240116`](https://github.com/abseil/abseil-cpp/releases/tag/20240116.1)
56-
(standard library extensions)
57-
* [OpenSSL](https://github.com/openssl/openssl) (for its bignum library)
58-
* [googletest testing framework >= 1.10](https://github.com/google/googletest)
59-
(to build tests and example programs, optional)
52+
* [CMake](http://www.cmake.org/) >= 3.5
53+
* A C++ compiler with C++14 support, such as [g++ >= 5](https://gcc.gnu.org/)
54+
* [Abseil](https://github.com/abseil/abseil-cpp) >= LTS
55+
[`20240722`](https://github.com/abseil/abseil-cpp/releases/tag/20240722.0)
56+
(standard library extensions)
57+
* [OpenSSL](https://github.com/openssl/openssl) (for its bignum library)
58+
* [googletest testing framework >= 1.10](https://github.com/google/googletest)
59+
(to build tests and example programs, optional)
6060

6161
On Ubuntu, all of these other than abseil can be installed via apt-get:
6262

src/BUILD.bazel

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ cc_library(
88
"//s2:encoded_s2shape_index.cc",
99
"//s2:encoded_string_vector.cc",
1010
"//s2:id_set_lexicon.cc",
11+
"//s2:internal/s2index_cell_data.cc",
12+
"//s2:internal/s2incident_edge_tracker.cc",
1113
"//s2:mutable_s2shape_index.cc",
1214
"//s2:r2rect.cc",
1315
"//s2:s1angle.cc",
@@ -90,6 +92,7 @@ cc_library(
9092
"//s2:s2shapeutil_contains_brute_force.cc",
9193
"//s2:s2shapeutil_conversion.cc",
9294
"//s2:s2shapeutil_edge_iterator.cc",
95+
"//s2:s2shapeutil_edge_wrap.cc",
9396
"//s2:s2shapeutil_get_reference_point.cc",
9497
"//s2:s2shapeutil_visit_crossing_edge_pairs.cc",
9598
"//s2:s2text_format.cc",
@@ -104,6 +107,10 @@ cc_library(
104107
"//s2:encoded_string_vector.h",
105108
"//s2:encoded_uint_vector.h",
106109
"//s2:id_set_lexicon.h",
110+
"//s2:internal/s2disjoint_set.h",
111+
"//s2:internal/s2incident_edge_tracker.h",
112+
"//s2:internal/s2index_cell_data.h",
113+
"//s2:internal/s2meta.h",
107114
"//s2:mutable_s2shape_index.h",
108115
"//s2:r1interval.h",
109116
"//s2:r2.h",
@@ -213,12 +220,14 @@ cc_library(
213220
"//s2:s2shapeutil_conversion.h",
214221
"//s2:s2shapeutil_count_edges.h",
215222
"//s2:s2shapeutil_edge_iterator.h",
223+
"//s2:s2shapeutil_edge_wrap.h",
216224
"//s2:s2shapeutil_get_reference_point.h",
217225
"//s2:s2shapeutil_shape_edge.h",
218226
"//s2:s2shapeutil_shape_edge_id.h",
219227
"//s2:s2shapeutil_testing.h",
220228
"//s2:s2shapeutil_visit_crossing_edge_pairs.h",
221229
"//s2:s2text_format.h",
230+
"//s2:s2validation_query.h",
222231
"//s2:s2wedge_relations.h",
223232
"//s2:s2winding_operation.h",
224233
"//s2:s2wrapped_shape.h",
@@ -232,7 +241,6 @@ cc_library(
232241
"//s2/base:logging",
233242
"//s2/base:port",
234243
"//s2/base:spinlock",
235-
"//s2/internal",
236244
"//s2/testing",
237245
"//s2/util/bitmap",
238246
"//s2/util/bits",
@@ -395,6 +403,16 @@ cc_library(
395403
],
396404
)
397405

406+
cc_test(
407+
name = "s2disjoint_set_test",
408+
srcs = ["//s2:internal/s2disjoint_set_test.cc"],
409+
deps = [
410+
":s2",
411+
":s2_testing_headers",
412+
"@googletest//:gtest_main",
413+
],
414+
)
415+
398416
cc_test(
399417
name = "s2fractal_test",
400418
srcs = ["//s2:s2fractal_test.cc"],
@@ -975,6 +993,16 @@ cc_test(
975993
],
976994
)
977995

996+
cc_test(
997+
name = "s2index_cell_data_test",
998+
srcs = ["//s2:internal/s2index_cell_data_test.cc"],
999+
deps = [
1000+
":s2",
1001+
":s2_testing_headers",
1002+
"@googletest//:gtest_main",
1003+
],
1004+
)
1005+
9781006
cc_test(
9791007
name = "s2latlng_test",
9801008
srcs = ["//s2:s2latlng_test.cc"],
@@ -1415,6 +1443,16 @@ cc_test(
14151443
],
14161444
)
14171445

1446+
cc_test(
1447+
name = "s2shapeutil_edge_wrap_test",
1448+
srcs = ["//s2:s2shapeutil_edge_wrap_test.cc"],
1449+
deps = [
1450+
":s2",
1451+
":s2_testing_headers",
1452+
"@googletest//:gtest_main",
1453+
],
1454+
)
1455+
14181456
cc_test(
14191457
name = "s2shapeutil_get_reference_point_test",
14201458
srcs = ["//s2:s2shapeutil_get_reference_point_test.cc"],
@@ -1455,6 +1493,16 @@ cc_test(
14551493
],
14561494
)
14571495

1496+
cc_test(
1497+
name = "s2validation_query_test",
1498+
srcs = ["//s2:s2validation_query_test.cc"],
1499+
deps = [
1500+
":s2",
1501+
":s2_testing_headers",
1502+
"@googletest//:gtest_main",
1503+
],
1504+
)
1505+
14581506
cc_test(
14591507
name = "s2wedge_relations_test",
14601508
srcs = ["//s2:s2wedge_relations_test.cc"],
@@ -1504,5 +1552,3 @@ cc_test(
15041552
"@googletest//:gtest_main",
15051553
],
15061554
)
1507-
1508-

src/s2/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22
exports_files(glob(
33
include = [
4+
"internal/*.h", "internal/*.cc",
45
"r1*.h","r1*.cc",
56
"r2*.h","r2*.cc",
67
"s1*.h","s1*.cc",

src/s2/base/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ cc_library(
1212
],
1313
)
1414

15+
cc_library(
16+
name = "malloc_extension",
17+
hdrs = ["malloc_extension.h"],
18+
srcs = ["malloc_extension.cc"],
19+
deps = [
20+
"@abseil-cpp//absl/base:core_headers",
21+
],
22+
)
23+
1524
cc_library(
1625
name = "types",
1726
hdrs = ["types.h"],

src/s2/base/malloc_extension.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 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+
#include "s2/base/malloc_extension.h"
17+
18+
#include <cstddef>
19+
#include <new>
20+
21+
#include "absl/base/attributes.h"
22+
23+
ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE size_t nallocx(size_t size,
24+
int) noexcept {
25+
return size;
26+
}
27+
28+
ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE __sized_ptr_t
29+
__size_returning_new(size_t size) {
30+
return {::operator new(size), size};
31+
}

src/s2/base/malloc_extension.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 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+
#ifndef S2_BASE_MALLOC_EXTENSION_H_
17+
#define S2_BASE_MALLOC_EXTENSION_H_
18+
19+
// Some s2geometry functions use TCMalloc extensions. Here, we provide
20+
// default implementations so s2geometry can be used with other allocators.
21+
//
22+
// See
23+
// https://github.com/google/tcmalloc/blob/master/tcmalloc/malloc_extension.h
24+
25+
#include <cstddef>
26+
27+
extern "C" {
28+
29+
// `nallocx` performs the same size computation that `malloc` would perform.
30+
// The default weak implementation just returns the `size` argument.
31+
// See https://jemalloc.net/jemalloc.3.html
32+
size_t nallocx(size_t size, int flags) noexcept;
33+
34+
// `__size_returning_new` returns a pointer to the allocated memory along
35+
// with the (possibly rounded up) actual allocation size used. The default
36+
// weak implementation just returns the requested size.
37+
// This is a TCMalloc prototype of P0901R5 "Size feedback in operator new".
38+
// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0901r5.html
39+
struct __sized_ptr_t {
40+
void* p;
41+
size_t n;
42+
};
43+
__sized_ptr_t __size_returning_new(size_t size);
44+
45+
} // extern "C"
46+
47+
#endif // S2_BASE_MALLOC_EXTENSION_H_

src/s2/base/port.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,28 @@
1818

1919
// This file contains things that are not used in third_party/absl but needed by
2020
// s2geometry. It is structured into the following high-level categories:
21+
// - Utility functions
2122
// - Endianness
2223
// - Performance optimization (alignment)
2324

2425
#include <cstdint>
2526
#include <cstring>
2627

28+
// -----------------------------------------------------------------------------
29+
// Utility Functions
30+
// -----------------------------------------------------------------------------
31+
32+
// C++14 sized deallocation
33+
namespace base {
34+
inline void sized_delete(void *ptr, size_t size) {
35+
::operator delete(ptr, size);
36+
}
37+
38+
inline void sized_delete_array(void *ptr, size_t size) {
39+
::operator delete[](ptr, size);
40+
}
41+
} // namespace base
42+
2743
// -----------------------------------------------------------------------------
2844
// Endianness
2945
// -----------------------------------------------------------------------------

src/s2/encoded_s2cell_id_vector.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "absl/log/absl_check.h"
2525
#include "absl/numeric/bits.h"
2626
#include "absl/types/span.h"
27-
#include "s2/util/bits/bits.h"
2827
#include "s2/util/coding/coder.h"
2928
#include "s2/encoded_uint_vector.h"
3029
#include "s2/s2cell_id.h"
@@ -107,7 +106,7 @@ void EncodeS2CellIdVector(Span<const S2CellId> v, Encoder* encoder) {
107106
// which case the shift is odd and the preceding bit is implicitly on).
108107
// There is no point in allowing shifts > 56 since deltas are encoded in
109108
// at least 1 byte each.
110-
e_shift = min(56, Bits::FindLSBSetNonZero64(v_or) & ~1);
109+
e_shift = min(56, absl::countr_zero(v_or) & ~1);
111110
if (v_and & (1ULL << e_shift)) ++e_shift; // All S2CellIds same level.
112111

113112
// "base" consists of the "base_len" most significant bytes of the minimum

src/s2/encoded_s2cell_id_vector.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define S2_ENCODED_S2CELL_ID_VECTOR_H_
2020

2121
#include <cstddef>
22-
2322
#include <cstdint>
2423
#include <vector>
2524

0 commit comments

Comments
 (0)