LCOV - code coverage report
Current view: top level - alg/marching_squares - utility.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 3 3 100.0 %
Date: 2025-12-13 23:48:27 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  Marching square algorithm
       4             :  * Purpose:  Core algorithm implementation for contour line generation.
       5             :  * Author:   Oslandia <infos at oslandia dot com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2018, Oslandia <infos at oslandia dot com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : #ifndef MARCHING_SQUARE_UTILITY_H
      13             : #define MARCHING_SQUARE_UTILITY_H
      14             : 
      15             : #include <limits>
      16             : #include <cmath>
      17             : 
      18             : namespace marching_squares
      19             : {
      20             : 
      21             : // This is used to determine the maximum level value for polygons,
      22             : // the one that spans all the remaining plane
      23             : constexpr double Inf = std::numeric_limits<double>::infinity();
      24             : 
      25             : constexpr double NaN = std::numeric_limits<double>::quiet_NaN();
      26             : 
      27             : #define debug(format, ...) CPLDebug("MarchingSquare", format, ##__VA_ARGS__)
      28             : 
      29             : // Perturb a value if it is too close to a level value
      30     3459607 : inline double fudge(double value, double level)
      31             : {
      32             :     // FIXME
      33             :     // This is too "hard coded". The perturbation to apply really depend on
      34             :     // values between which we have to interpolate, so that the result of
      35             :     // interpolation should give coordinates that are "numerically" stable for
      36             :     // classical algorithms to work (on polygons for instance).
      37             :     //
      38             :     // Ideally we should probably use snap rounding to ensure no contour lines
      39             :     // are within a user-provided minimum distance.
      40             : 
      41     3459607 :     constexpr double absTol = 1e-6;
      42     3459607 :     return std::abs(level - value) < absTol ? value + absTol : value;
      43             : }
      44             : 
      45             : }  // namespace marching_squares
      46             : #endif

Generated by: LCOV version 1.14