Skip to content

Commit

Permalink
Update to 2024-11-01 google3 version
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jmr authored Dec 6, 2024
2 parents 71e596b + bb82206 commit b95b824
Show file tree
Hide file tree
Showing 204 changed files with 4,592 additions and 1,118 deletions.
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ endif()
include_directories(src)

add_library(s2
src/s2/base/malloc_extension.cc
src/s2/encoded_s2cell_id_vector.cc
src/s2/encoded_s2point_vector.cc
src/s2/encoded_s2shape_index.cc
src/s2/encoded_string_vector.cc
src/s2/id_set_lexicon.cc
src/s2/internal/s2incident_edge_tracker.cc
src/s2/internal/s2index_cell_data.cc
src/s2/mutable_s2shape_index.cc
src/s2/r2rect.cc
src/s2/s1angle.cc
Expand Down Expand Up @@ -154,7 +157,6 @@ add_library(s2
src/s2/s2fractal.cc
src/s2/s2furthest_edge_query.cc
src/s2/s2hausdorff_distance_query.cc
src/s2/s2index_cell_data.cc
src/s2/s2latlng.cc
src/s2/s2latlng_rect.cc
src/s2/s2latlng_rect_bounder.cc
Expand Down Expand Up @@ -334,6 +336,7 @@ install(FILES src/s2/_fp_contract_off.h
src/s2/s2crossing_edge_query.h
src/s2/s2debug.h
src/s2/s2density_tree.h
src/s2/s2density_tree_internal.h
src/s2/s2distance_target.h
src/s2/s2earth.h
src/s2/s2edge_clipping.h
Expand All @@ -347,7 +350,6 @@ install(FILES src/s2/_fp_contract_off.h
src/s2/s2fractal.h
src/s2/s2furthest_edge_query.h
src/s2/s2hausdorff_distance_query.h
src/s2/s2index_cell_data.h
src/s2/s2latlng.h
src/s2/s2latlng_rect.h
src/s2/s2latlng_rect_bounder.h
Expand Down Expand Up @@ -407,19 +409,24 @@ install(FILES src/s2/_fp_contract_off.h
src/s2/s2shapeutil_visit_crossing_edge_pairs.h
src/s2/s2testing.h
src/s2/s2text_format.h
src/s2/s2validation_query.h
src/s2/s2wedge_relations.h
src/s2/s2winding_operation.h
src/s2/s2wrapped_shape.h
src/s2/sequence_lexicon.h
src/s2/thread_testing.h
src/s2/value_lexicon.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2")
install(FILES src/s2/internal/s2meta.h
DESTINATION include/s2)
install(FILES src/s2/internal/s2disjoint_set.h
src/s2/internal/s2incident_edge_tracker.h
src/s2/internal/s2index_cell_data.h
src/s2/internal/s2meta.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/internal")
install(FILES src/s2/base/casts.h
src/s2/base/commandlineflags.h
src/s2/base/commandlineflags_declare.h
src/s2/base/log_severity.h
src/s2/base/malloc_extension.h
src/s2/base/port.h
src/s2/base/spinlock.h
src/s2/base/types.h
Expand Down Expand Up @@ -493,6 +500,8 @@ if (BUILD_TESTS)
src/s2/encoded_uint_vector_test.cc
src/s2/gmock_matchers_test.cc
src/s2/id_set_lexicon_test.cc
src/s2/internal/s2disjoint_set_test.cc
src/s2/internal/s2index_cell_data_test.cc
src/s2/mutable_s2shape_index_test.cc
src/s2/r1interval_test.cc
src/s2/r2rect_test.cc
Expand Down Expand Up @@ -547,7 +556,6 @@ if (BUILD_TESTS)
src/s2/s2fractal_test.cc
src/s2/s2furthest_edge_query_test.cc
src/s2/s2hausdorff_distance_query_test.cc
src/s2/s2index_cell_data_test.cc
src/s2/s2latlng_rect_bounder_test.cc
src/s2/s2latlng_rect_test.cc
src/s2/s2latlng_test.cc
Expand Down Expand Up @@ -600,6 +608,7 @@ if (BUILD_TESTS)
src/s2/s2shapeutil_shape_edge_id_test.cc
src/s2/s2shapeutil_visit_crossing_edge_pairs_test.cc
src/s2/s2text_format_test.cc
src/s2/s2validation_query_test.cc
src/s2/s2wedge_relations_test.cc
src/s2/s2winding_operation_test.cc
src/s2/s2wrapped_shape_test.cc
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ This issue may require revision of boringssl or exactfloat.

## Requirements for End Users using CMake

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

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

Expand Down
52 changes: 49 additions & 3 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ cc_library(
"//s2:encoded_s2shape_index.cc",
"//s2:encoded_string_vector.cc",
"//s2:id_set_lexicon.cc",
"//s2:internal/s2index_cell_data.cc",
"//s2:internal/s2incident_edge_tracker.cc",
"//s2:mutable_s2shape_index.cc",
"//s2:r2rect.cc",
"//s2:s1angle.cc",
Expand Down Expand Up @@ -90,6 +92,7 @@ cc_library(
"//s2:s2shapeutil_contains_brute_force.cc",
"//s2:s2shapeutil_conversion.cc",
"//s2:s2shapeutil_edge_iterator.cc",
"//s2:s2shapeutil_edge_wrap.cc",
"//s2:s2shapeutil_get_reference_point.cc",
"//s2:s2shapeutil_visit_crossing_edge_pairs.cc",
"//s2:s2text_format.cc",
Expand All @@ -104,6 +107,10 @@ cc_library(
"//s2:encoded_string_vector.h",
"//s2:encoded_uint_vector.h",
"//s2:id_set_lexicon.h",
"//s2:internal/s2disjoint_set.h",
"//s2:internal/s2incident_edge_tracker.h",
"//s2:internal/s2index_cell_data.h",
"//s2:internal/s2meta.h",
"//s2:mutable_s2shape_index.h",
"//s2:r1interval.h",
"//s2:r2.h",
Expand Down Expand Up @@ -213,12 +220,14 @@ cc_library(
"//s2:s2shapeutil_conversion.h",
"//s2:s2shapeutil_count_edges.h",
"//s2:s2shapeutil_edge_iterator.h",
"//s2:s2shapeutil_edge_wrap.h",
"//s2:s2shapeutil_get_reference_point.h",
"//s2:s2shapeutil_shape_edge.h",
"//s2:s2shapeutil_shape_edge_id.h",
"//s2:s2shapeutil_testing.h",
"//s2:s2shapeutil_visit_crossing_edge_pairs.h",
"//s2:s2text_format.h",
"//s2:s2validation_query.h",
"//s2:s2wedge_relations.h",
"//s2:s2winding_operation.h",
"//s2:s2wrapped_shape.h",
Expand All @@ -232,7 +241,6 @@ cc_library(
"//s2/base:logging",
"//s2/base:port",
"//s2/base:spinlock",
"//s2/internal",
"//s2/testing",
"//s2/util/bitmap",
"//s2/util/bits",
Expand Down Expand Up @@ -395,6 +403,16 @@ cc_library(
],
)

cc_test(
name = "s2disjoint_set_test",
srcs = ["//s2:internal/s2disjoint_set_test.cc"],
deps = [
":s2",
":s2_testing_headers",
"@googletest//:gtest_main",
],
)

cc_test(
name = "s2fractal_test",
srcs = ["//s2:s2fractal_test.cc"],
Expand Down Expand Up @@ -975,6 +993,16 @@ cc_test(
],
)

cc_test(
name = "s2index_cell_data_test",
srcs = ["//s2:internal/s2index_cell_data_test.cc"],
deps = [
":s2",
":s2_testing_headers",
"@googletest//:gtest_main",
],
)

cc_test(
name = "s2latlng_test",
srcs = ["//s2:s2latlng_test.cc"],
Expand Down Expand Up @@ -1415,6 +1443,16 @@ cc_test(
],
)

cc_test(
name = "s2shapeutil_edge_wrap_test",
srcs = ["//s2:s2shapeutil_edge_wrap_test.cc"],
deps = [
":s2",
":s2_testing_headers",
"@googletest//:gtest_main",
],
)

cc_test(
name = "s2shapeutil_get_reference_point_test",
srcs = ["//s2:s2shapeutil_get_reference_point_test.cc"],
Expand Down Expand Up @@ -1455,6 +1493,16 @@ cc_test(
],
)

cc_test(
name = "s2validation_query_test",
srcs = ["//s2:s2validation_query_test.cc"],
deps = [
":s2",
":s2_testing_headers",
"@googletest//:gtest_main",
],
)

cc_test(
name = "s2wedge_relations_test",
srcs = ["//s2:s2wedge_relations_test.cc"],
Expand Down Expand Up @@ -1504,5 +1552,3 @@ cc_test(
"@googletest//:gtest_main",
],
)


1 change: 1 addition & 0 deletions src/s2/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package(default_visibility = ["//visibility:public"])
exports_files(glob(
include = [
"internal/*.h", "internal/*.cc",
"r1*.h","r1*.cc",
"r2*.h","r2*.cc",
"s1*.h","s1*.cc",
Expand Down
9 changes: 9 additions & 0 deletions src/s2/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ cc_library(
],
)

cc_library(
name = "malloc_extension",
hdrs = ["malloc_extension.h"],
srcs = ["malloc_extension.cc"],
deps = [
"@abseil-cpp//absl/base:core_headers",
],
)

cc_library(
name = "types",
hdrs = ["types.h"],
Expand Down
31 changes: 31 additions & 0 deletions src/s2/base/malloc_extension.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "s2/base/malloc_extension.h"

#include <cstddef>
#include <new>

#include "absl/base/attributes.h"

ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE size_t nallocx(size_t size,
int) noexcept {
return size;
}

ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE __sized_ptr_t
__size_returning_new(size_t size) {
return {::operator new(size), size};
}
47 changes: 47 additions & 0 deletions src/s2/base/malloc_extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef S2_BASE_MALLOC_EXTENSION_H_
#define S2_BASE_MALLOC_EXTENSION_H_

// Some s2geometry functions use TCMalloc extensions. Here, we provide
// default implementations so s2geometry can be used with other allocators.
//
// See
// https://github.com/google/tcmalloc/blob/master/tcmalloc/malloc_extension.h

#include <cstddef>

extern "C" {

// `nallocx` performs the same size computation that `malloc` would perform.
// The default weak implementation just returns the `size` argument.
// See https://jemalloc.net/jemalloc.3.html
size_t nallocx(size_t size, int flags) noexcept;

// `__size_returning_new` returns a pointer to the allocated memory along
// with the (possibly rounded up) actual allocation size used. The default
// weak implementation just returns the requested size.
// This is a TCMalloc prototype of P0901R5 "Size feedback in operator new".
// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0901r5.html
struct __sized_ptr_t {
void* p;
size_t n;
};
__sized_ptr_t __size_returning_new(size_t size);

} // extern "C"

#endif // S2_BASE_MALLOC_EXTENSION_H_
16 changes: 16 additions & 0 deletions src/s2/base/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,28 @@

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

#include <cstdint>
#include <cstring>

// -----------------------------------------------------------------------------
// Utility Functions
// -----------------------------------------------------------------------------

// C++14 sized deallocation
namespace base {
inline void sized_delete(void *ptr, size_t size) {
::operator delete(ptr, size);
}

inline void sized_delete_array(void *ptr, size_t size) {
::operator delete[](ptr, size);
}
} // namespace base

// -----------------------------------------------------------------------------
// Endianness
// -----------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions src/s2/encoded_s2cell_id_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "absl/log/absl_check.h"
#include "absl/numeric/bits.h"
#include "absl/types/span.h"
#include "s2/util/bits/bits.h"
#include "s2/util/coding/coder.h"
#include "s2/encoded_uint_vector.h"
#include "s2/s2cell_id.h"
Expand Down Expand Up @@ -107,7 +106,7 @@ void EncodeS2CellIdVector(Span<const S2CellId> v, Encoder* encoder) {
// which case the shift is odd and the preceding bit is implicitly on).
// There is no point in allowing shifts > 56 since deltas are encoded in
// at least 1 byte each.
e_shift = min(56, Bits::FindLSBSetNonZero64(v_or) & ~1);
e_shift = min(56, absl::countr_zero(v_or) & ~1);
if (v_and & (1ULL << e_shift)) ++e_shift; // All S2CellIds same level.

// "base" consists of the "base_len" most significant bytes of the minimum
Expand Down
1 change: 0 additions & 1 deletion src/s2/encoded_s2cell_id_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define S2_ENCODED_S2CELL_ID_VECTOR_H_

#include <cstddef>

#include <cstdint>
#include <vector>

Expand Down
Loading

0 comments on commit b95b824

Please sign in to comment.