GEOS  3.14.0dev
CoordinateSequences.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2023 ISciences, LLC
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************/
14 
15 #pragma once
16 
17 #include <geos/geom/Coordinate.h>
18 #include <geos/geom/CoordinateSequence.h>
19 
20 namespace geos {
21 namespace geom {
22 
29 
30 private:
31  template<typename CoordinateType>
32  static constexpr int
33  type_pair(const CoordinateType& typ1, const CoordinateType& typ2) {
34  return (static_cast<int>(typ1) << 4) | static_cast<int>(typ2);
35  }
36 
37 public:
42  template<typename F, class... Args>
43  static void binaryDispatch(const CoordinateSequence& seq1, const CoordinateSequence& seq2, F& fun, Args... args)
44  {
45  using CoordinateXYZ = Coordinate;
46 
47  auto typ1 = seq1.getCoordinateType();
48  auto typ2 = seq2.getCoordinateType();
49 
50  switch(type_pair(typ1, typ2)) {
51  case type_pair(CoordinateType::XY, CoordinateType::XY): fun.template operator()<CoordinateXY, CoordinateXY>(args...); break;
52  case type_pair(CoordinateType::XY, CoordinateType::XYZ): fun.template operator()<CoordinateXY, CoordinateXYZ>(args...); break;
53  case type_pair(CoordinateType::XY, CoordinateType::XYM): fun.template operator()<CoordinateXY, CoordinateXYM>(args...); break;
54  case type_pair(CoordinateType::XY, CoordinateType::XYZM): fun.template operator()<CoordinateXY, CoordinateXYZM>(args...); break;
55 
56  case type_pair(CoordinateType::XYZ, CoordinateType::XY): fun.template operator()<CoordinateXYZ, CoordinateXY>(args...); break;
57  case type_pair(CoordinateType::XYZ, CoordinateType::XYZ): fun.template operator()<CoordinateXYZ, CoordinateXYZ>(args...); break;
58  case type_pair(CoordinateType::XYZ, CoordinateType::XYM): fun.template operator()<CoordinateXYZ, CoordinateXYM>(args...); break;
59  case type_pair(CoordinateType::XYZ, CoordinateType::XYZM): fun.template operator()<CoordinateXYZ, CoordinateXYZM>(args...); break;
60 
61  case type_pair(CoordinateType::XYM, CoordinateType::XY): fun.template operator()<CoordinateXYM, CoordinateXY>(args...); break;
62  case type_pair(CoordinateType::XYM, CoordinateType::XYZ): fun.template operator()<CoordinateXYM, CoordinateXYZ>(args...); break;
63  case type_pair(CoordinateType::XYM, CoordinateType::XYM): fun.template operator()<CoordinateXYM, CoordinateXYM>(args...); break;
64  case type_pair(CoordinateType::XYM, CoordinateType::XYZM): fun.template operator()<CoordinateXYM, CoordinateXYZM>(args...); break;
65 
66  case type_pair(CoordinateType::XYZM, CoordinateType::XY): fun.template operator()<CoordinateXYZM, CoordinateXY>(args...); break;
67  case type_pair(CoordinateType::XYZM, CoordinateType::XYZ): fun.template operator()<CoordinateXYZM, CoordinateXYZ>(args...); break;
68  case type_pair(CoordinateType::XYZM, CoordinateType::XYM): fun.template operator()<CoordinateXYZM, CoordinateXYM>(args...); break;
69  case type_pair(CoordinateType::XYZM, CoordinateType::XYZM): fun.template operator()<CoordinateXYZM, CoordinateXYZM>(args...); break;
70  }
71  }
72 
73 };
74 
75 }
76 }
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:56
The CoordinateSequences class provides utility methods to operate on CoordinateSequences....
Definition: CoordinateSequences.h:28
static void binaryDispatch(const CoordinateSequence &seq1, const CoordinateSequence &seq2, F &fun, Args... args)
binaryDispatch calls a functor template, explicitly providing the backing types of two CoordinateSequ...
Definition: CoordinateSequences.h:43
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:217
CoordinateType getCoordinateType() const
Definition: CoordinateSequence.h:233
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25