LCOV - code coverage report
Current view: top level - alg/marching_squares - point.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 11 14 78.6 %
Date: 2024-11-21 22:18:42 Functions: 5 6 83.3 %

          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             : 
      13             : #ifndef MARCHING_SQUARE_POINT_H
      14             : #define MARCHING_SQUARE_POINT_H
      15             : 
      16             : #include "utility.h"
      17             : #include <ostream>
      18             : #include <algorithm>
      19             : #include <cmath>
      20             : #include <list>
      21             : 
      22             : namespace marching_squares
      23             : {
      24             : 
      25             : // regular point
      26             : struct Point
      27             : {
      28      429366 :     Point() : x(NaN), y(NaN)
      29             :     {
      30      429366 :     }  // just to be able to make an uninitialized list
      31             : 
      32      179890 :     Point(double x_, double y_) : x(x_), y(y_)
      33             :     {
      34      179890 :     }
      35             : 
      36             :     double x;
      37             :     double y;
      38             : };
      39             : 
      40     1211208 : inline bool operator==(const Point &lhs, const Point &rhs)
      41             : {
      42     1211208 :     return (lhs.x == rhs.x) && (lhs.y == rhs.y);
      43             : }
      44             : 
      45           0 : inline std::ostream &operator<<(std::ostream &o, const Point &p)
      46             : {
      47           0 :     o << p.x << " " << p.y;
      48           0 :     return o;
      49             : }
      50             : 
      51             : // Test if a point is to the left or right of an infinite line.
      52             : // Returns true if it is to the left and right otherwise
      53             : // 0 if p2 is on the line and less than if p2 is to the right of the line
      54        2136 : inline bool isLeft(const Point &p0, const Point &p1, const Point &p2)
      55             : {
      56        2136 :     return ((p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y)) > 0;
      57             : }
      58             : 
      59             : // LineString type
      60             : typedef std::list<Point> LineString;
      61             : 
      62             : inline std::ostream &operator<<(std::ostream &o, const LineString &ls)
      63             : {
      64             :     o << "{";
      65             :     for (const auto &p : ls)
      66             :     {
      67             :         o << p << ", ";
      68             :     }
      69             :     o << "}";
      70             :     return o;
      71             : }
      72             : 
      73             : // Point with a value
      74             : struct ValuedPoint
      75             : {
      76     2499953 :     ValuedPoint(double x_, double y_, double value_)
      77     2499953 :         : x(x_), y(y_), value(value_)
      78             :     {
      79     2499953 :     }
      80             : 
      81             :     const double x;
      82             :     const double y;
      83             :     const double value;
      84             : };
      85             : 
      86             : }  // namespace marching_squares
      87             : 
      88             : #endif

Generated by: LCOV version 1.14