Skip to content

Commit e9ba53e

Browse files
committed
Merge branch 'google3'
New functionality: * Add function S2ShapeIndex Dump function * Add Init to Graph nested classes * S2Polygon::InitToOperation: Propagate S2Error Bug fixes: * Fix S2BooleanOperation empty/full handling * Minor compilation fixes for nacl * Fix LaxPolygonLayer bug * Fix rare bug in S2BooleanOperation * Fix rare bug in VisitCrossingEdgePairs * Fix UB discovered by -D_GLIBCXX_DEBUG * S2Cap::Add: Fix bug with empty other cap * OwningShape: Fix potential memory leak * S2Builder: Clear layer_is_full_polygon_predicates_ * S2EdgeTesselator: Improve error estimation
2 parents e6ecb66 + 3345ca5 commit e9ba53e

File tree

103 files changed

+2831
-1509
lines changed

Some content is hidden

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

103 files changed

+2831
-1509
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ install(FILES src/s2/_fp_contract_off.h
233233
src/s2/s2builder_layer.h
234234
src/s2/s2builderutil_closed_set_normalizer.h
235235
src/s2/s2builderutil_find_polygon_degeneracies.h
236+
src/s2/s2builderutil_graph_shape.h
236237
src/s2/s2builderutil_lax_polygon_layer.h
237238
src/s2/s2builderutil_s2point_vector_layer.h
238239
src/s2/s2builderutil_s2polygon_layer.h

doc/examples/term_index.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int main(int argc, char **argv) {
3939
// region types include polygons, polylines, rectangles, discs, buffered
4040
// geometry, etc.)
4141
std::vector<S2Point> documents;
42+
documents.reserve(FLAGS_num_documents);
4243
for (int docid = 0; docid < FLAGS_num_documents; ++docid) {
4344
documents.push_back(S2Testing::RandomPoint());
4445
}

src/python/pywraps2_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,31 @@ def testS2PolygonGetAreaIsWrappedCorrectly(self):
138138
cell_union.Init([london_level_10.id()])
139139
self.assertAlmostEqual(cell_union.ExactArea(), polygon.GetArea(), places=10)
140140

141+
def testS2PolygonGetOverlapFractions(self):
142+
# Matches S2Polygon, OverlapFractions test from cs/s2polygon_test.cc
143+
a = s2.S2Polygon()
144+
b = s2.S2Polygon()
145+
r1, r2 = s2.S2Polygon.GetOverlapFractions(a, b)
146+
self.assertAlmostEqual(1.0, r1)
147+
self.assertAlmostEqual(1.0, r2)
148+
149+
def verts2loop(vs):
150+
loop = s2.S2Loop()
151+
loop.Init([s2.S2LatLng.FromDegrees(*v).ToPoint() for v in vs])
152+
return loop
153+
154+
loop1verts = [(-10, 10), (0, 10), (0, -10), (-10, -10), (-10, 0)]
155+
b = s2.S2Polygon(verts2loop(loop1verts))
156+
r1, r2 = s2.S2Polygon.GetOverlapFractions(a, b)
157+
self.assertAlmostEqual(1.0, r1)
158+
self.assertAlmostEqual(0.0, r2)
159+
160+
loop2verts = [(-10, 0), (10, 0), (10, -10), (-10, -10)]
161+
a = s2.S2Polygon(verts2loop(loop2verts))
162+
r1, r2 = s2.S2Polygon.GetOverlapFractions(a, b)
163+
self.assertAlmostEqual(0.5, r1)
164+
self.assertAlmostEqual(0.5, r2)
165+
141166
def testGetS2LatLngVertexIsWrappedCorrectly(self):
142167
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
143168
polygon = s2.S2Polygon(s2.S2Cell(s2.S2CellId(london)))

src/python/s2_common.i

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
$1 = temp;
3838
}
3939

40+
// For S2Polygon::GetOverlapFractions
41+
%typemap(out) std::pair<double, double> {
42+
$result = Py_BuildValue("dd", $1.first, $1.second);
43+
}
44+
4045
%typemap(argout) S2CellId *OUTPUT_ARRAY_4 {
4146
$result = PyList_New(4);
4247
if ($result == nullptr) return nullptr;
@@ -447,6 +452,7 @@ class S2Point {
447452
%unignore S2Polygon::GetCapBound() const;
448453
%unignore S2Polygon::GetCentroid;
449454
%unignore S2Polygon::GetDistance;
455+
%unignore S2Polygon::GetOverlapFractions(const S2Polygon*, const S2Polygon*);
450456
%unignore S2Polygon::GetRectBound;
451457
%unignore S2Polygon::Init;
452458
%unignore S2Polygon::InitNested;

src/s2/base/port.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#ifndef S2_BASE_PORT_H_
1717
#define S2_BASE_PORT_H_
1818

19-
// Users should still #include "base/port.h". Code in //third_party/absl/base
20-
// is not visible for general use.
21-
//
2219
// This file contains things that are not used in third_party/absl but needed by
2320
// - Platform specific requirement
2421
// - MSVC
@@ -39,7 +36,7 @@
3936

4037
#include "s2/base/integral_types.h"
4138
#include "s2/third_party/absl/base/config.h"
42-
#include "s2/third_party/absl/base/port.h" // IWYU pragma: export
39+
#include "s2/third_party/absl/base/port.h"
4340

4441
#ifdef SWIG
4542
%include "third_party/absl/base/port.h"
@@ -892,21 +889,20 @@ inline void UnalignedCopy64(const void *src, void *dst) {
892889
!defined(SWIG)) || \
893890
((__GNUC__ >= 3 || defined(__clang__)) && defined(__ANDROID__)) || \
894891
defined(__ASYLO__))
895-
inline void *aligned_malloc(size_t size, int minimum_alignment) {
892+
inline void *aligned_malloc(size_t size, size_t minimum_alignment) {
896893
#if defined(__ANDROID__) || defined(OS_ANDROID) || defined(__ASYLO__)
897894
return memalign(minimum_alignment, size);
898895
#else // !__ANDROID__ && !OS_ANDROID && !__ASYLO__
899-
void *ptr = nullptr;
900896
// posix_memalign requires that the requested alignment be at least
901897
// sizeof(void*). In this case, fall back on malloc which should return memory
902898
// aligned to at least the size of a pointer.
903-
const int required_alignment = sizeof(void*);
899+
const size_t required_alignment = sizeof(void*);
904900
if (minimum_alignment < required_alignment)
905901
return malloc(size);
906-
if (posix_memalign(&ptr, static_cast<size_t>(minimum_alignment), size) != 0)
907-
return nullptr;
908-
else
902+
void *ptr = nullptr;
903+
if (posix_memalign(&ptr, minimum_alignment, size) == 0)
909904
return ptr;
905+
return nullptr;
910906
#endif
911907
}
912908

@@ -916,7 +912,7 @@ inline void aligned_free(void *aligned_memory) {
916912

917913
#elif defined(_MSC_VER) // MSVC
918914

919-
inline void *aligned_malloc(size_t size, int minimum_alignment) {
915+
inline void *aligned_malloc(size_t size, size_t minimum_alignment) {
920916
return _aligned_malloc(size, minimum_alignment);
921917
}
922918

src/s2/encoded_string_vector.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ StringVectorEncoder::StringVectorEncoder() {
3030
void StringVectorEncoder::Encode(Encoder* encoder) {
3131
offsets_.push_back(data_.length());
3232
// We don't encode the first element of "offsets_", which is always zero.
33-
EncodeUintVector<uint64>(MakeSpan(offsets_.data() + 1, &*offsets_.end()),
34-
encoder);
33+
EncodeUintVector<uint64>(
34+
MakeSpan(offsets_.data() + 1, offsets_.data() + offsets_.size()),
35+
encoder);
3536
encoder->Ensure(data_.length());
3637
encoder->putn(data_.base(), data_.length());
3738
}

src/s2/mutable_s2shape_index.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ inline void MutableS2ShapeIndex::AddFaceEdge(
856856
// Otherwise we simply clip the edge to all six faces.
857857
for (int face = 0; face < 6; ++face) {
858858
if (S2::ClipToPaddedFace(edge->edge.v0, edge->edge.v1, face,
859-
kCellPadding, &edge->a, &edge->b)) {
859+
kCellPadding, &edge->a, &edge->b)) {
860860
all_edges[face].push_back(*edge);
861861
}
862862
}
@@ -1329,9 +1329,8 @@ void MutableS2ShapeIndex::AbsorbIndexCell(const S2PaddedCell& pcell,
13291329
edge.edge = shape->edge(e);
13301330
edge.max_level = GetEdgeMaxLevel(edge.edge);
13311331
if (edge.has_interior) tracker->TestEdge(shape_id, edge.edge);
1332-
if (!S2::ClipToPaddedFace(edge.edge.v0, edge.edge.v1,
1333-
pcell.id().face(), kCellPadding,
1334-
&edge.a, &edge.b)) {
1332+
if (!S2::ClipToPaddedFace(edge.edge.v0, edge.edge.v1, pcell.id().face(),
1333+
kCellPadding, &edge.a, &edge.b)) {
13351334
S2_LOG(DFATAL) << "Invariant failure in MutableS2ShapeIndex";
13361335
}
13371336
face_edges->push_back(edge);

src/s2/mutable_s2shape_index_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ void LazyUpdatesTest::ReaderThread() {
499499
lock_.Unlock();
500500
for (MutableS2ShapeIndex::Iterator it(&index_, S2ShapeIndex::BEGIN);
501501
!it.done(); it.Next()) {
502-
continue;
502+
continue; // NOLINT
503503
}
504504
lock_.Lock();
505505
if (--num_readers_left_ == 0) {

src/s2/s1angle.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class S1Angle {
111111
// Return the angle between two points, which is also equal to the distance
112112
// between these points on the unit sphere. The points do not need to be
113113
// normalized. This function has a maximum error of 3.25 * DBL_EPSILON (or
114-
// 2.5 * DBL_EPSILON for angles up to 1 radian).
114+
// 2.5 * DBL_EPSILON for angles up to 1 radian). If either point is
115+
// zero-length (e.g. an uninitialized S2Point), or almost zero-length, the
116+
// resulting angle will be zero.
115117
S1Angle(const S2Point& x, const S2Point& y);
116118

117119
// Like the constructor above, but return the angle (i.e., distance) between

0 commit comments

Comments
 (0)