Skip to content

Commit d184302

Browse files
authored
Update to latest google3 version
* Use absl::flags and absl::log instead of gflags/glog * Use ABSL_UNREACHABLE, requires abseil/abseil-cpp@6a87605 * New edge/circle intersection ordering predicates * New functions `GetUVCoordOfEdge` and `GetIJCoordOfEdge` * S2PolylineAlignment: Use Norm instead of Norm2 * S2Polygon::DestructiveUnion: Use priority_queue internally * Update CONTRIBUTING.md with more detailed instructions * Replace `const char *` with `absl::string_view` * Replace most `gtl::dense_hash_set` uses with `absl::flat_hash_set` * Replace most `std::set` and `std::map` with `absl::flat_hash_set` and `flat_hash_map`
2 parents efb4eb8 + e818b11 commit d184302

File tree

151 files changed

+2608
-1786
lines changed

Some content is hidden

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

151 files changed

+2608
-1786
lines changed

CMakeLists.txt

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
2727

2828
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/third_party/cmake")
2929

30-
option(WITH_GFLAGS "Use gflags to change command line flags." OFF)
31-
add_feature_info(GFLAGS WITH_GFLAGS
32-
"allows changing command line flags.")
33-
34-
# glog option can only be turned on if gflags is on.
35-
cmake_dependent_option(WITH_GLOG "Use glog for logging." ON
36-
"WITH_GFLAGS" OFF)
37-
add_feature_info(GLOG WITH_GLOG "provides logging configurability.")
38-
3930
option(BUILD_SHARED_LIBS "Build shared libraries instead of static." ON)
4031
add_feature_info(SHARED_LIBS BUILD_SHARED_LIBS
4132
"builds shared libraries instead of static.")
@@ -52,26 +43,8 @@ add_feature_info(S2_USE_SYSTEM_INCLUDES S2_USE_SYSTEM_INCLUDES
5243

5344
feature_summary(WHAT ALL)
5445

55-
if (WITH_GLOG)
56-
find_package(Glog REQUIRED)
57-
# FindGFlags.cmake and FindGlog.cmake do not seem to implement REQUIRED;
58-
# check manually.
59-
if (NOT ${GLOG_FOUND})
60-
message(FATAL_ERROR "Glog requested but not found")
61-
endif()
62-
add_definitions(-DS2_USE_GLOG)
63-
else()
64-
# Don't output anything for LOG(INFO).
65-
add_definitions(-DABSL_MIN_LOG_LEVEL=1)
66-
endif()
67-
68-
if (WITH_GFLAGS)
69-
find_package(GFlags REQUIRED)
70-
if (NOT ${GFLAGS_FOUND})
71-
message(FATAL_ERROR "GFlags requested but not found")
72-
endif()
73-
add_definitions(-DS2_USE_GFLAGS)
74-
endif()
46+
# Don't output anything for LOG(INFO).
47+
add_definitions(-DABSL_MIN_LOG_LEVEL=1)
7548

7649
# If we already have abseil we don't need to find it, for an example:
7750
# add_subdirectory(absl-submbodule)
@@ -111,8 +84,7 @@ endif()
11184
# If OpenSSL is installed in a non-standard location, configure with
11285
# something like:
11386
# OPENSSL_ROOT_DIR=/usr/local/opt/openssl cmake ..
114-
include_directories(
115-
${GFLAGS_INCLUDE_DIRS} ${GLOG_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})
87+
include_directories(${OPENSSL_INCLUDE_DIR})
11688

11789
if (WITH_PYTHON)
11890
include_directories(${Python3_INCLUDE_DIRS})
@@ -213,7 +185,6 @@ add_library(s2
213185
src/s2/s2text_format.cc
214186
src/s2/s2wedge_relations.cc
215187
src/s2/s2winding_operation.cc
216-
src/s2/strings/serialize.cc
217188
src/s2/util/bits/bit-interleave.cc
218189
src/s2/util/coding/coder.cc
219190
src/s2/util/coding/varint.cc
@@ -231,19 +202,22 @@ endif()
231202

232203
target_link_libraries(
233204
s2
234-
${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES} ${OPENSSL_LIBRARIES}
205+
${OPENSSL_LIBRARIES}
235206
absl::base
236207
absl::btree
208+
absl::check
237209
absl::config
238210
absl::core_headers
239211
absl::dynamic_annotations
240212
absl::endian
241213
absl::fixed_array
214+
absl::flags
242215
absl::flat_hash_map
243216
absl::flat_hash_set
244217
absl::hash
245218
absl::inlined_vector
246219
absl::int128
220+
absl::log
247221
absl::log_severity
248222
absl::memory
249223
absl::span
@@ -257,7 +231,9 @@ target_link_libraries(
257231
if (GOOGLETEST_ROOT)
258232
target_link_libraries(
259233
s2testing
260-
${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES}
234+
absl::check
235+
absl::flags
236+
absl::log
261237
absl::memory
262238
absl::strings)
263239
endif()
@@ -415,6 +391,8 @@ install(FILES src/s2/base/casts.h
415391
src/s2/base/port.h
416392
src/s2/base/spinlock.h
417393
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/base")
394+
install(FILES src/s2/testing/gtest_prod.h
395+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/testing")
418396
install(FILES src/s2/util/bitmap/bitmap.h
419397
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/util/bitmap")
420398
install(FILES src/s2/util/bits/bits.h
@@ -581,8 +559,11 @@ if (GOOGLETEST_ROOT)
581559
s2testing s2
582560
absl::base
583561
absl::btree
562+
absl::check
584563
absl::core_headers
564+
absl::flags
585565
absl::flags_reflection
566+
absl::log
586567
absl::memory
587568
absl::span
588569
absl::status

CONTRIBUTING.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,28 @@ of your first [pull request][].
4747
separate branches in order to ensure that a pull request only includes the
4848
commits related to that bug or feature.
4949

50-
1. Do your best to have [well-formed commit messages][] for each change.
51-
This provides consistency throughout the project, and ensures that commit
52-
messages are able to be formatted properly by various git tools.
50+
1. Do your best to have [well-formed commit messages][] with a [good
51+
description][] for each change. This provides consistency throughout
52+
the project, and ensures that commit messages are able to be formatted
53+
properly by various git tools.
54+
55+
1. Keep PRs [small and focused][] on a single issue. Do not make unrelated
56+
changes in the same PR "because you're there"; this includes reformatting
57+
of code, whether automatically or manually.
5358

5459
1. Finally, push the commits to your fork and submit a [pull request][].
5560

5661
[forking]: https://help.github.com/articles/fork-a-repo
5762
[well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
63+
[good description]: https://google.github.io/eng-practices/review/developer/cl-descriptions.html
5864
[pull request]: https://help.github.com/articles/creating-a-pull-request
65+
[small and focused]: https://google.github.io/eng-practices/review/developer/small-cls.html
5966

6067

6168
## Style ##
6269

63-
Contributions should follow the [Google C++ Style Guide].
70+
Contributions should follow the [Google C++ Style Guide]. Code may be
71+
[formatted] with `git clang-format`.
6472

6573
[Google C++ Style Guide]: http://google.github.io/styleguide/cppguide.html
74+
[formatted]: http://google.github.io/styleguide/cppguide.html#Formatting

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# S2 Geometry Library
22

3-
[![Build Status](https://travis-ci.org/google/s2geometry.svg?branch=master)](https://travis-ci.org/google/s2geometry)
4-
53
## Overview
64

75
This is a package for manipulating geometric shapes. Unlike many geometry
@@ -33,15 +31,13 @@ complete functionality.
3331
* A C++ compiler with C++14 support, such as [g++ >= 5](https://gcc.gnu.org/)
3432
* [Abseil](https://github.com/abseil/abseil-cpp) (standard library extensions)
3533
* [OpenSSL](https://github.com/openssl/openssl) (for its bignum library)
36-
* [gflags command line flags](https://github.com/gflags/gflags), optional
37-
* [glog logging module](https://github.com/google/glog), optional
3834
* [googletest testing framework >= 1.10](https://github.com/google/googletest)
3935
(to build tests and example programs, optional)
4036

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

4339
```
44-
sudo apt-get install cmake libgflags-dev libgoogle-glog-dev googletest libssl-dev
40+
sudo apt-get install cmake googletest libssl-dev
4541
```
4642

4743
Otherwise, you may need to install some from source.
@@ -54,7 +50,7 @@ On macOS, use [MacPorts](http://www.macports.org/) or
5450
[Homebrew](http://brew.sh/). For MacPorts:
5551

5652
```
57-
sudo port install cmake gflags google-glog openssl
53+
sudo port install cmake openssl
5854
```
5955

6056
Do not install `gtest` from MacPorts; instead download [release
@@ -116,8 +112,6 @@ sudo make install
116112

117113
On macOS, `sysctl -n hw.logicalcpu` is the equivalent of `nproc`.
118114

119-
Enable gflags and glog with `cmake -DWITH_GFLAGS=ON -DWITH_GLOG=ON ...`.
120-
121115
Disable building of shared libraries with `-DBUILD_SHARED_LIBS=OFF`.
122116

123117
Enable the python interface with `-DWITH_PYTHON=ON`.

src/s2/base/casts.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <type_traits>
3131

3232
#include "absl/base/casts.h" // IWYU pragma: keep
33+
#include "absl/base/config.h"
34+
#include "absl/log/log.h"
3335

3436
#include "s2/base/logging.h"
3537

@@ -63,8 +65,8 @@ inline To down_cast(From* f) { // so we only accept pointers
6365
static_assert((std::is_base_of<From, std::remove_pointer_t<To>>::value),
6466
"target type not derived from source type");
6567

66-
// We skip the assert and hence the dynamic_cast if RTTI is disabled.
67-
#if !defined(__GNUC__) || defined(__GXX_RTTI)
68+
// We skip the assert and hence the dynamic_cast if RTTI is disabled.
69+
#if ABSL_INTERNAL_HAS_RTTI
6870
// Uses RTTI in dbg and fastbuild. asserts are disabled in opt builds.
6971
assert(f == nullptr || dynamic_cast<To>(f) != nullptr);
7072
#endif // !defined(__GNUC__) || defined(__GXX_RTTI)
@@ -88,7 +90,7 @@ inline To down_cast(From& f) {
8890
"target type not derived from source type");
8991

9092
// We skip the assert and hence the dynamic_cast if RTTI is disabled.
91-
#if !defined(__GNUC__) || defined(__GXX_RTTI)
93+
#if ABSL_INTERNAL_HAS_RTTI
9294
// RTTI: debug mode only
9395
assert(dynamic_cast<std::remove_reference_t<To>*>(&f) != nullptr);
9496
#endif // !defined(__GNUC__) || defined(__GXX_RTTI)
@@ -289,15 +291,15 @@ inline bool tight_enum_test_cast(int e_val, Enum* e_var) {
289291
template <typename Enum>
290292
inline Enum loose_enum_cast(int e_val) {
291293
if (!loose_enum_test<Enum>(e_val)) {
292-
S2_LOG(DFATAL) << "enum_cast error for value " << e_val;
294+
S2_LOG(ERROR) << "enum_cast error for value " << e_val;
293295
}
294296
return static_cast<Enum>(e_val);
295297
}
296298

297299
template <typename Enum>
298300
inline Enum tight_enum_cast(int e_val) {
299301
if (!tight_enum_test<Enum>(e_val)) {
300-
S2_LOG(DFATAL) << "enum_cast error for value " << e_val;
302+
S2_LOG(ERROR) << "enum_cast error for value " << e_val;
301303
}
302304
return static_cast<Enum>(e_val);
303305
}

src/s2/base/commandlineflags.h

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,74 +18,24 @@
1818

1919
#include <string>
2020

21+
#include "absl/flags/flag.h"
22+
2123
#include "s2/base/commandlineflags_declare.h"
2224
#include "s2/base/integral_types.h"
23-
#include "absl/strings/string_view.h"
24-
25-
#ifdef S2_USE_GFLAGS
26-
27-
#include <gflags/gflags.h>
28-
29-
// If the GFlags library is available, map the local macro names to
30-
// GFlags macros.
31-
#define S2_DEFINE_bool DEFINE_bool
32-
#define S2_DEFINE_double DEFINE_double
33-
#define S2_DEFINE_int32 DEFINE_int32
34-
#define S2_DEFINE_int64 DEFINE_int64
35-
#define S2_DEFINE_string DEFINE_string
36-
37-
// gflags has its own int32 definitions.
38-
namespace absl {
39-
inline int32 GetFlag(google::int32 flag) { return flag; }
40-
inline int64 GetFlag(google::int64 flag) { return flag; }
41-
inline void SetFlag(google::int32* f, google::int32 v) { *f = v; }
42-
inline void SetFlag(google::int64* f, google::int64 v) { *f = v; }
43-
} // namespace absl
44-
45-
#else // !defined(S2_USE_GFLAGS)
46-
47-
48-
// Create a set of gflags-like macros for declaring/defining flags. Use
49-
// a library-specific name to potential minimize clashes with GFlags.
5025

5126
#define S2_DEFINE_bool(name, default_value, description) \
52-
bool FLAGS_##name = default_value
27+
ABSL_FLAG(bool, name, default_value, description)
5328

5429
#define S2_DEFINE_double(name, default_value, description) \
55-
double FLAGS_##name = default_value
30+
ABSL_FLAG(double, name, default_value, description)
5631

5732
#define S2_DEFINE_int32(name, default_value, description) \
58-
int32 FLAGS_##name = default_value
33+
ABSL_FLAG(int32, name, default_value, description)
5934

6035
#define S2_DEFINE_int64(name, default_value, description) \
61-
int64 FLAGS_##name = default_value
36+
ABSL_FLAG(int64, name, default_value, description)
6237

6338
#define S2_DEFINE_string(name, default_value, description) \
64-
std::string FLAGS_##name = default_value
65-
66-
namespace absl {
67-
inline int32 GetFlag(int32 flag) { return flag; }
68-
inline int64 GetFlag(int64 flag) { return flag; }
69-
inline void SetFlag(int32* f, int32 v) { *f = v; }
70-
inline void SetFlag(int64* f, int64 v) { *f = v; }
71-
} // namespace absl
72-
73-
#endif // !defined(S2_USE_GFLAGS)
74-
75-
// Flags are declared with v1 flags, but accessed via absl::GetFlag/SetFlag.
76-
// TODO(user,b/205817426): Convert everything to absl flags and remove gflags.
77-
namespace absl {
78-
79-
inline bool GetFlag(bool flag) { return flag; }
80-
inline double GetFlag(double flag) { return flag; }
81-
inline std::string GetFlag(const std::string& flag) { return flag; }
82-
83-
inline void SetFlag(bool* f, bool v) { *f = v; }
84-
inline void SetFlag(double* f, double v) { *f = v; }
85-
inline void SetFlag(std::string* f, absl::string_view v) {
86-
*f = std::string(v);
87-
}
88-
89-
} // namespace absl
39+
ABSL_FLAG(std::string, name, default_value, description)
9040

9141
#endif // S2_BASE_COMMANDLINEFLAGS_H_

src/s2/base/commandlineflags_declare.h

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,18 @@
1818

1919
#include <string>
2020

21-
#include "s2/base/integral_types.h"
22-
23-
#ifdef S2_USE_GFLAGS
24-
25-
#include <gflags/gflags.h>
21+
#include "absl/flags/declare.h"
2622

27-
#define S2_DECLARE_bool(name) DECLARE_bool(name)
28-
#define S2_DECLARE_double(name) DECLARE_double(name)
29-
#define S2_DECLARE_int32(name) DECLARE_int32(name)
30-
#define S2_DECLARE_int64(name) DECLARE_int64(name)
31-
#define S2_DECLARE_string(name) DECLARE_string(name)
32-
33-
#else // !defined(S2_USE_GFLAGS)
34-
35-
#define S2_DECLARE_bool(name) \
36-
extern bool FLAGS_##name
23+
#include "s2/base/integral_types.h"
3724

38-
#define S2_DECLARE_double(name) \
39-
extern double FLAGS_##name
25+
#define S2_DECLARE_bool(name) ABSL_DECLARE_FLAG(bool, name)
4026

41-
#define S2_DECLARE_int32(name) \
42-
extern int32 FLAGS_##name
27+
#define S2_DECLARE_double(name) ABSL_DECLARE_FLAG(double, name)
4328

44-
#define S2_DECLARE_int64(name) \
45-
extern int64 FLAGS_##name
29+
#define S2_DECLARE_int32(name) ABSL_DECLARE_FLAG(int32, name)
4630

47-
#define S2_DECLARE_string(name) \
48-
extern std::string FLAGS_##name
31+
#define S2_DECLARE_int64(name) ABSL_DECLARE_FLAG(int64, name)
4932

50-
#endif // !defined(S2_USE_GFLAGS)
33+
#define S2_DECLARE_string(name) ABSL_DECLARE_FLAG(std::string, name)
5134

5235
#endif // S2_BASE_COMMANDLINEFLAGS_DECLARE_H_

src/s2/base/log_severity.h

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

19-
#ifdef S2_USE_GLOG
20-
21-
// Including <glog/log_severity.h> directly will give errors.
22-
#include <glog/logging.h>
23-
24-
#else // !defined(S2_USE_GLOG)
25-
2619
#include "absl/base/log_severity.h"
2720

2821
// Stay compatible with glog.
@@ -36,6 +29,4 @@ constexpr bool DEBUG_MODE = true;
3629

3730
} // namespace google
3831

39-
#endif // !defined(S2_USE_GLOG)
40-
4132
#endif // S2_BASE_LOG_SEVERITY_H_

0 commit comments

Comments
 (0)