Label.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* 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.
*
**********************************************************************
*
* Last port: geomgraph/Label.java r428 (JTS-1.12+)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Location.h>
#include <geos/geomgraph/TopologyLocation.h>
#include <iosfwd> // for operator<<
#include <cassert>
namespace geos {
namespace geomgraph { // geos.geomgraph
class GEOS_DLL Label final {
using Position = geos::geom::Position;
public:
friend std::ostream& operator<< (std::ostream&, const Label&);
static Label toLineLabel(const Label& label)
{
Label lineLabel(geom::Location::NONE);
for(uint32_t i = 0; i < 2; i++) {
lineLabel.setLocation(i, label.getLocation(i));
}
return lineLabel;
};
Label(geom::Location onLoc)
: elt{TopologyLocation(onLoc)
, TopologyLocation(onLoc)}
{};
Label(uint32_t geomIndex, geom::Location onLoc)
: elt{TopologyLocation(geom::Location::NONE)
, TopologyLocation(geom::Location::NONE)}
{
assert(geomIndex < 2);
elt[geomIndex].setLocation(onLoc);
};
Label(geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
: elt {TopologyLocation(onLoc, leftLoc, rightLoc)
, TopologyLocation(onLoc, leftLoc, rightLoc)}
{};
Label(const Label& l)
: elt{TopologyLocation(l.elt[0])
, TopologyLocation(l.elt[1])}
{};
Label()
: elt{TopologyLocation(geom::Location::NONE)
, TopologyLocation(geom::Location::NONE)}
{};
Label(uint32_t geomIndex, geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
{
elt[0] = TopologyLocation(geom::Location::NONE, geom::Location::NONE, geom::Location::NONE);
elt[1] = TopologyLocation(geom::Location::NONE, geom::Location::NONE, geom::Location::NONE);
elt[geomIndex].setLocations(onLoc, leftLoc, rightLoc);
};
Label&
operator=(const Label& l)
{
elt[0] = TopologyLocation(l.elt[0]);
elt[1] = TopologyLocation(l.elt[1]);
return *this;
};
void flip()
{
elt[0].flip();
elt[1].flip();
};
void merge(const Label& lbl)
{
for(int i = 0; i < 2; i++) {
elt[i].merge(lbl.elt[i]);
}
};
int getGeometryCount() const
{
int count = 0;
if(!elt[0].isNull()) {
count++;
}
if(!elt[1].isNull()) {
count++;
}
return count;
};
geom::Location getLocation(uint32_t geomIndex, uint32_t posIndex) const
{
assert(geomIndex < 2);
return elt[geomIndex].get(posIndex);
};
geom::Location getLocation(uint32_t geomIndex) const
{
assert(geomIndex < 2);
return elt[geomIndex].get(Position::ON);
};
void setLocation(uint32_t geomIndex, uint32_t posIndex, geom::Location location)
{
assert(geomIndex < 2);
elt[geomIndex].setLocation(posIndex, location);
};
void setLocation(uint32_t geomIndex, geom::Location location)
{
assert(geomIndex < 2);
elt[geomIndex].setLocation(Position::ON, location);
};
void setAllLocations(uint32_t geomIndex, geom::Location location)
{
assert(geomIndex < 2);
elt[geomIndex].setAllLocations(location);
};
void setAllLocationsIfNull(uint32_t geomIndex, geom::Location location)
{
assert(geomIndex < 2);
elt[geomIndex].setAllLocationsIfNull(location);
};
void setAllLocationsIfNull(geom::Location location)
{
setAllLocationsIfNull(0, location);
setAllLocationsIfNull(1, location);
};
bool isNull(uint32_t geomIndex) const
{
assert(geomIndex < 2);
return elt[geomIndex].isNull();
};
bool isNull() const
{
return elt[0].isNull() && elt[1].isNull();
};
bool isAnyNull(uint32_t geomIndex) const
{
assert(geomIndex < 2);
return elt[geomIndex].isAnyNull();
};
bool isArea() const
{
return elt[0].isArea() || elt[1].isArea();
};
bool isArea(uint32_t geomIndex) const
{
assert(geomIndex < 2);
return elt[geomIndex].isArea();
};
bool isLine(uint32_t geomIndex) const
{
assert(geomIndex < 2);
return elt[geomIndex].isLine();
};
bool isEqualOnSide(const Label& lbl, uint32_t side) const
{
return elt[0].isEqualOnSide(lbl.elt[0], side)
&& elt[1].isEqualOnSide(lbl.elt[1], side);
};
bool allPositionsEqual(uint32_t geomIndex, geom::Location loc) const
{
assert(geomIndex < 2);
return elt[geomIndex].allPositionsEqual(loc);
};
void toLine(uint32_t geomIndex)
{
assert(geomIndex < 2);
if(elt[geomIndex].isArea()) {
elt[geomIndex] = TopologyLocation(elt[geomIndex].getLocations()[0]);
}
};
std::string toString() const;
private:
TopologyLocation elt[2];
};
std::ostream& operator<< (std::ostream&, const Label&);
} // namespace geos.geomgraph
} // namespace geos
geos::geom::Position
A Position indicates the position of a Location relative to a graph component (Node,...
Definition Position.h:37
geos::geomgraph::Label
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition Label.h:57
geos::geomgraph::Label::Label
Label(geom::Location onLoc)
Construct a Label with a single location for both Geometries.
Definition Label.h:81
geos::geomgraph::Label::Label
Label(geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
Construct a Label with On, Left and Right locations for both Geometries.
Definition Label.h:106
geos::geomgraph::Label::merge
void merge(const Label &lbl)
Merge this label with another one.
Definition Label.h:160
geos::geomgraph::Label::Label
Label(uint32_t geomIndex, geom::Location onLoc)
Construct a Label with the location specified for the given Geometry.
Definition Label.h:93
geos::geomgraph::Label::Label
Label()
Initialize both locations to Location::NONE.
Definition Label.h:122
geos::geomgraph::Label::toLineLabel
static Label toLineLabel(const Label &label)
Converts a Label to a Line label (that is, one with no side Locations).
Definition Label.h:69
geos::geomgraph::Label::Label
Label(const Label &l)
Copy ctor.
Definition Label.h:112
geos::geomgraph::Label::Label
Label(uint32_t geomIndex, geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
Construct a Label with On, Left and Right locations for the given Geometries. Initialize the location...
Definition Label.h:133
geos::geomgraph::Label::toLine
void toLine(uint32_t geomIndex)
Converts one GeometryLocation to a Line location.
Definition Label.h:270
geos::geomgraph::TopologyLocation
A TopologyLocation is the labelling of a GraphComponent's topological relationship to a single Geomet...
Definition TopologyLocation.h:60
geos::geom
Definition Angle.h:26
geos::geom::Location
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
geos::geom::Location::NONE
@ NONE
Definition Location.h:36
geos::geomgraph
Contains classes that implement topology graphs.
Definition Depth.h:31
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38