1 // Copyright 2005 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 // Author: ericv@google.com (Eric Veach) 17 // 18 // The S2 library defines extra validity checks throughout the code that can 19 // optionally be enabled or disabled. By default, these validity checks are 20 // enabled in debug-mode builds (including fastbuild) and disabled in 21 // optimized builds. 22 // 23 // There are two ways to change the default behavior: 24 // 25 // - The command line --s2debug flag, which changes the global default. 26 // 27 // - The S2Debug enum, which allows validity checks to be enabled or disabled 28 // for specific objects (e.g., an S2Polygon). 29 // 30 // If you want to intentionally create invalid geometry (e.g., in a test), the 31 // S2Debug enum is preferable. For example, to create an invalid S2Polygon, 32 // you can do this: 33 // 34 // S2Polygon invalid; 35 // invalid.set_s2debug_override(S2Debug::DISABLE); 36 // 37 // There is also a convenience constructor: 38 // 39 // vector<unique_ptr<S2Loop>> loops = ...; 40 // S2Polygon invalid(loops, S2Debug::DISABLE); 41 // 42 // There are a few checks that cannot be disabled this way (e.g., internal 43 // functions that require S2Points to be unit length). If you absolutely need 44 // to disable these checks, you can set FLAGS_s2debug for the duration of a 45 // specific test like this: 46 // 47 // TEST(MyClass, InvalidGeometry) { 48 // FLAGS_s2debug = false; // Automatically restored between tests 49 // ... 50 // } 51 52 #ifndef S2_S2DEBUG_H_ 53 #define S2_S2DEBUG_H_ 54 55 #include "s2/base/commandlineflags.h" 56 #include "s2/base/integral_types.h" 57 58 // Command line flag that enables extra validity checking throughout the S2 59 // code. It is turned on by default in debug-mode builds. 60 DECLARE_bool(s2debug); 61 62 // Class that allows the --s2debug validity checks to be enabled or disabled 63 // for specific objects (e.g., see S2Polygon). 64 enum class S2Debug : uint8 { 65 ALLOW, // Validity checks are controlled by --s2debug 66 DISABLE // No validity checks even when --s2debug is true 67 }; 68 69 #endif // S2_S2DEBUG_H_ 70