Skip to content

Commit

Permalink
Add classes for curved geometry types
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Feb 9, 2024
1 parent 8d87edc commit 459018d
Show file tree
Hide file tree
Showing 30 changed files with 2,684 additions and 1,014 deletions.
54 changes: 54 additions & 0 deletions include/geos/geom/CircularString.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2024 ISciences, LLC
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/

#pragma once

#include <geos/geom/SimpleCurve.h>

namespace geos {
namespace geom {

class GEOS_DLL CircularString : public SimpleCurve {

public:
using SimpleCurve::SimpleCurve;

friend class GeometryFactory;

~CircularString() override;

std::unique_ptr<CircularString> clone() const;

std::string getGeometryType() const override;

GeometryTypeId getGeometryTypeId() const override;

CircularString* cloneImpl() const override
{
return new CircularString(*this);
}

CircularString* reverseImpl() const override;

int
getSortIndex() const override
{
return SORTINDEX_LINESTRING;
};

};


}
}
120 changes: 120 additions & 0 deletions include/geos/geom/CompoundCurve.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2024 ISciences, LLC
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/

#pragma once

#include <geos/geom/SimpleCurve.h>
#include <vector>

namespace geos {
namespace geom {

class GEOS_DLL CompoundCurve : public Curve {
friend class GeometryFactory;


public:

CompoundCurve(const CompoundCurve&);

CompoundCurve& operator=(const CompoundCurve&);

std::unique_ptr<CoordinateSequence> getCoordinates() const override;

const CoordinateXY* getCoordinate() const override;

uint8_t getCoordinateDimension() const override;

bool hasZ() const override;

bool hasM() const override;

bool isEmpty() const override;

bool isClosed() const override;

std::size_t getNumGeometries() const override;

const Geometry* getGeometryN(std::size_t) const override;

std::size_t getNumPoints() const override;

std::unique_ptr<Geometry> getBoundary() const override;

std::string getGeometryType() const override;

GeometryTypeId getGeometryTypeId() const override;

bool equalsExact(const Geometry* other, double tolerance = 0)
const override;

bool equalsIdentical(const Geometry* other) const override;

const Envelope* getEnvelopeInternal() const override
{
return &envelope;
}

std::unique_ptr<CompoundCurve> clone() const;

CompoundCurve* cloneImpl() const override;

std::unique_ptr<CompoundCurve> reverse() const;

CompoundCurve* reverseImpl() const override;

void apply_rw(const CoordinateFilter* filter) override;

void apply_ro(CoordinateFilter* filter) const override;

void apply_rw(GeometryFilter* filter) override;

void apply_ro(GeometryFilter* filter) const override;

void apply_rw(GeometryComponentFilter* filter) override;

void apply_ro(GeometryComponentFilter* filter) const override;

void apply_rw(CoordinateSequenceFilter& filter) override;

void apply_ro(CoordinateSequenceFilter& filter) const override;

void normalize() override;

int compareToSameClass(const Geometry* geom) const override;


protected:
CompoundCurve(std::vector<std::unique_ptr<SimpleCurve>>&&,
const GeometryFactory&);

int getSortIndex() const override
{
return SORTINDEX_COMPOUNDCURVE;
}

void geometryChangedAction() override
{
envelope = computeEnvelopeInternal();
}

Envelope computeEnvelopeInternal();

private:
std::vector<std::unique_ptr<SimpleCurve>> curves;
Envelope envelope;
};

}
}
46 changes: 46 additions & 0 deletions include/geos/geom/Curve.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2024 ISciences, LLC
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/

#pragma once

#include <geos/geom/Geometry.h>

namespace geos {
namespace geom {

class GEOS_DLL Curve : public Geometry {

public:
/// Returns line dimension (1)
Dimension::DimensionType getDimension() const override
{
return Dimension::L; // line
}

int
getBoundaryDimension() const override
{
return isClosed() ? Dimension::False : 0;
}

virtual bool isClosed() const = 0;

protected:

Curve(const GeometryFactory& factory) : Geometry(&factory) {}

};

}
}
54 changes: 54 additions & 0 deletions include/geos/geom/CurvePolygon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2024 ISciences, LLC
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/

#pragma once

#include <geos/geom/SurfaceImpl.h>

namespace geos {
namespace geom {

class GEOS_DLL CurvePolygon : public SurfaceImpl<Curve> {
friend class GeometryFactory;

public:
~CurvePolygon() override = default;

std::unique_ptr<CoordinateSequence> getCoordinates() const override;

int
getSortIndex() const override
{
return SORTINDEX_CURVEPOLYGON;
}

std::string getGeometryType() const override;

GeometryTypeId getGeometryTypeId() const override;

std::unique_ptr<Geometry> getBoundary() const override;

void normalize() override;

protected:
using SurfaceImpl::SurfaceImpl;

Geometry* cloneImpl() const override;

Geometry* reverseImpl() const override;
};


}
}
41 changes: 35 additions & 6 deletions include/geos/geom/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ enum GeometryTypeId {
/// a collection of polygons
GEOS_MULTIPOLYGON,
/// a collection of heterogeneus geometries
GEOS_GEOMETRYCOLLECTION
GEOS_GEOMETRYCOLLECTION,
GEOS_CIRCULARSTRING,
GEOS_COMPOUNDCURVE,
GEOS_CURVEPOLYGON,
GEOS_MULTICURVE,
GEOS_MULTISURFACE,
};

enum GeometrySortIndex {
Expand All @@ -97,7 +102,12 @@ enum GeometrySortIndex {
SORTINDEX_MULTILINESTRING = 4,
SORTINDEX_POLYGON = 5,
SORTINDEX_MULTIPOLYGON = 6,
SORTINDEX_GEOMETRYCOLLECTION = 7
SORTINDEX_GEOMETRYCOLLECTION = 7,
SORTINDEX_CIRCULARSTRING = 8,
SORTINDEX_COMPOUNDCURVE = 9,
SORTINDEX_CURVEPOLYGON = 10,
SORTINDEX_MULTICURVE = 11,
SORTINDEX_MULTISURFACE = 12,
};

/**
Expand Down Expand Up @@ -919,11 +929,30 @@ class GEOS_DLL Geometry {

virtual int compareToSameClass(const Geometry* geom) const = 0; //Abstract

int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;

int compare(std::vector<Geometry*> a, std::vector<Geometry*> b) const;
template<typename T>
static int compare(const T& a, const T& b)
{
std::size_t i = 0;
std::size_t j = 0;
while(i < a.size() && j < b.size()) {
const auto& aGeom = *a[i];
const auto& bGeom = *b[j];
int comparison = aGeom.compareTo(&bGeom);
if(comparison != 0) {
return comparison;
}
i++;
j++;
}
if(i < a.size()) {
return 1;
}
if(j < b.size()) {
return -1;
}
return 0;

int compare(const std::vector<std::unique_ptr<Geometry>> & a, const std::vector<std::unique_ptr<Geometry>> & b) const;
}

bool equal(const CoordinateXY& a, const CoordinateXY& b,
double tolerance) const;
Expand Down
Loading

0 comments on commit 459018d

Please sign in to comment.