GEOS 3.14.0dev
LinkedRing.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
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 <memory>
18
19#include <geos/geom/Coordinate.h>
20#include <geos/geom/CoordinateSequence.h>
21#include <geos/constants.h>
22
23namespace geos {
24namespace simplify { // geos::simplify
25
26
27
28class LinkedRing
29{
30 using Coordinate = geos::geom::Coordinate;
31 using CoordinateSequence = geos::geom::CoordinateSequence;
32
33 private:
34
35 const CoordinateSequence& m_coord;
36 std::size_t m_size;
37 std::vector<std::size_t> m_next;
38 std::vector<std::size_t> m_prev;
39
40 static std::vector<std::size_t> createNextLinks(std::size_t size);
41 static std::vector<std::size_t> createPrevLinks(std::size_t size);
42
43
44 public:
45
46 LinkedRing(const CoordinateSequence& cs)
47 : m_coord(cs)
48 , m_size(cs.size()-1)
49 , m_next(createNextLinks(m_size))
50 , m_prev(createPrevLinks(m_size))
51 {};
52
53 std::size_t size() const;
54 std::size_t next(std::size_t i) const;
55 std::size_t prev(std::size_t i) const;
56 const Coordinate& getCoordinate(std::size_t index) const;
57 const Coordinate& prevCoordinate(std::size_t index) const;
58 const Coordinate& nextCoordinate(std::size_t index) const;
59 bool hasCoordinate(std::size_t index) const;
60 void remove(std::size_t index);
61 std::unique_ptr<CoordinateSequence> getCoordinates() const;
62
63
64}; // LinkedRing
65
66
67} // geos::simplify
68} // geos
69
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
Basic namespace for all GEOS functionalities.
Definition geos.h:39