OverlayLabel.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
*
* 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 <cstdint>
#include <geos/geom/Location.h>
#include <geos/geom/Position.h>
#include <geos/export.h>
namespace geos { // geos.
namespace operation { // geos.operation
namespace overlayng { // geos.operation.overlayng
class GEOS_DLL OverlayLabel {
using Location = geos::geom::Location;
using Position = geos::geom::Position;
private:
// Members
int aDim = DIM_NOT_PART;
bool aIsHole = false;
Location aLocLeft = LOC_UNKNOWN;
Location aLocRight = LOC_UNKNOWN;
Location aLocLine = LOC_UNKNOWN;
int bDim = DIM_NOT_PART;
bool bIsHole = false;
Location bLocLeft = LOC_UNKNOWN;
Location bLocRight = LOC_UNKNOWN;
Location bLocLine = LOC_UNKNOWN;
std::string dimensionSymbol(int dim) const;
void locationString(uint8_t index, bool isForward, std::ostream& os) const;
public:
static constexpr Location LOC_UNKNOWN = Location::NONE;
enum {
DIM_UNKNOWN = -1,
DIM_NOT_PART = -1,
DIM_LINE = 1,
DIM_BOUNDARY = 2,
DIM_COLLAPSE = 3
};
OverlayLabel()
: aDim(DIM_NOT_PART)
, aIsHole(false)
, aLocLeft(LOC_UNKNOWN)
, aLocRight(LOC_UNKNOWN)
, aLocLine(LOC_UNKNOWN)
, bDim(DIM_NOT_PART)
, bIsHole(false)
, bLocLeft(LOC_UNKNOWN)
, bLocRight(LOC_UNKNOWN)
, bLocLine(LOC_UNKNOWN) {};
explicit OverlayLabel(uint8_t p_index)
: OverlayLabel()
{
initLine(p_index);
};
OverlayLabel(uint8_t p_index, Location p_locLeft, Location p_locRight, bool p_isHole)
: OverlayLabel()
{
initBoundary(p_index, p_locLeft, p_locRight, p_isHole);
};
int dimension(uint8_t index) const { return index == 0 ? aDim : bDim; };
void initBoundary(uint8_t index, Location locLeft, Location locRight, bool p_isHole);
void initCollapse(uint8_t index, bool p_isHole);
void initLine(uint8_t index);
void initNotPart(uint8_t index);
void setLocationLine(uint8_t index, Location loc);
void setLocationAll(uint8_t index, Location loc);
void setLocationCollapse(uint8_t index);
/*
* Tests whether at least one of the sources is a Line.
*
* @return true if at least one source is a line
*/
bool isLine() const
{
return aDim == DIM_LINE || bDim == DIM_LINE;
};
bool isLine(uint8_t index) const
{
return index == 0 ? aDim == DIM_LINE : bDim == DIM_LINE;
};
bool isLinear(uint8_t index) const
{
if (index == 0) {
return aDim == DIM_LINE || aDim == DIM_COLLAPSE;
}
return bDim == DIM_LINE || bDim == DIM_COLLAPSE;
};
bool isKnown(uint8_t index) const
{
if (index == 0) {
return aDim != DIM_UNKNOWN;
}
return bDim != DIM_UNKNOWN;
};
bool isNotPart(uint8_t index) const
{
if (index == 0) {
return aDim == DIM_NOT_PART;
}
return bDim == DIM_NOT_PART;
};
bool isBoundaryEither() const
{
return aDim == DIM_BOUNDARY || bDim == DIM_BOUNDARY;
};
bool isBoundaryBoth() const
{
return aDim == DIM_BOUNDARY && bDim == DIM_BOUNDARY;
};
bool isBoundaryCollapse() const
{
if (isLine()) return false;
return ! isBoundaryBoth();
};
bool isBoundaryTouch() const
{
return isBoundaryBoth() &&
getLocation(0, Position::RIGHT, true) != getLocation(1, Position::RIGHT, true);
};
bool isBoundary(uint8_t index) const
{
if (index == 0) {
return aDim == DIM_BOUNDARY;
}
return bDim == DIM_BOUNDARY;
};
bool isLineLocationUnknown(int index) const
{
if (index == 0) {
return aLocLine == LOC_UNKNOWN;
}
else {
return bLocLine == LOC_UNKNOWN;
}
};
bool isBoundarySingleton() const
{
if (aDim == DIM_BOUNDARY && bDim == DIM_NOT_PART) {
return true;
}
if (bDim == DIM_BOUNDARY && aDim == DIM_NOT_PART) {
return true;
}
return false;
};
bool isLineInArea(int8_t index) const
{
if (index == 0) {
return aLocLine == Location::INTERIOR;
}
return bLocLine == Location::INTERIOR;
};
bool isHole(uint8_t index) const
{
if (index == 0) {
return aIsHole;
}
else {
return bIsHole;
}
};
bool isCollapse(uint8_t index) const
{
return dimension(index) == DIM_COLLAPSE;
};
Location getLineLocation(uint8_t index) const
{
if (index == 0) {
return aLocLine;
}
else {
return bLocLine;
}
};
bool isInteriorCollapse() const
{
if (aDim == DIM_COLLAPSE && aLocLine == Location::INTERIOR)
return true;
if (bDim == DIM_COLLAPSE && bLocLine == Location::INTERIOR)
return true;
return false;
};
bool isCollapseAndNotPartInterior() const;
bool isLineInterior(uint8_t index) const
{
if (index == 0) {
return aLocLine == Location::INTERIOR;
}
return bLocLine == Location::INTERIOR;
};
Location getLocationBoundaryOrLine(
uint8_t index,
int position,
bool isForward) const
{
if (isBoundary(index)) {
return getLocation(index, position, isForward);
}
return getLineLocation(index);
};
Location getLocation(uint8_t index) const {
if (index == 0) {
return aLocLine;
}
return bLocLine;
};
Location getLocation(uint8_t index, int position, bool isForward) const;
bool hasSides(uint8_t index) const {
if (index == 0) {
return aLocLeft != LOC_UNKNOWN
|| aLocRight != LOC_UNKNOWN;
}
return bLocLeft != LOC_UNKNOWN
|| bLocRight != LOC_UNKNOWN;
};
OverlayLabel copy() const
{
OverlayLabel lbl = *this;
return lbl;
};
friend std::ostream& operator<<(std::ostream& os, const OverlayLabel& ol);
void toString(bool isForward, std::ostream& os) const;
};
} // namespace geos.operation.overlayng
} // namespace geos.operation
} // namespace geos
geos::geom::Position
A Position indicates the position of a Location relative to a graph component (Node,...
Definition Position.h:37
geos::geom::Position::RIGHT
@ RIGHT
An indicator that a Location is to the right of a GraphComponent.
Definition Position.h:56
geos::operation::overlayng::OverlayLabel::setLocationLine
void setLocationLine(uint8_t index, Location loc)
geos::operation::overlayng::OverlayLabel::getLocation
Location getLocation(uint8_t index) const
Definition OverlayLabel.h:370
geos::operation::overlayng::OverlayLabel::isLineInterior
bool isLineInterior(uint8_t index) const
Definition OverlayLabel.h:334
geos::operation::overlayng::OverlayLabel::isBoundaryCollapse
bool isBoundaryCollapse() const
Definition OverlayLabel.h:219
geos::operation::overlayng::OverlayLabel::isInteriorCollapse
bool isInteriorCollapse() const
Definition OverlayLabel.h:312
geos::operation::overlayng::OverlayLabel::isCollapseAndNotPartInterior
bool isCollapseAndNotPartInterior() const
geos::operation::overlayng::OverlayLabel::getLocationBoundaryOrLine
Location getLocationBoundaryOrLine(uint8_t index, int position, bool isForward) const
Definition OverlayLabel.h:353
geos::operation::overlayng::OverlayLabel::isBoundaryTouch
bool isBoundaryTouch() const
Definition OverlayLabel.h:229
geos::operation::overlayng::OverlayLabel::isLineInArea
bool isLineInArea(int8_t index) const
Definition OverlayLabel.h:275
geos::operation::overlayng::OverlayLabel::isBoundarySingleton
bool isBoundarySingleton() const
Definition OverlayLabel.h:257
geos::geom::Location
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
geos::index
Provides classes for various kinds of spatial indexes.
Definition CleanCoverage.h:39
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38