NodingIntersectionFinder.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2006 Refractions Research 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.
*
**********************************************************************/
#pragma once
#include <geos/noding/SegmentIntersector.h> // for inheritance
#include <geos/geom/Coordinate.h> // for composition
#include <geos/noding/SegmentString.h>
#include <vector>
// Forward declarations
namespace geos {
namespace algorithm {
class LineIntersector;
}
namespace noding {
class SegmentString;
}
}
namespace geos {
namespace noding { // geos.noding
class NodingIntersectionFinder: public SegmentIntersector {
public:
NodingIntersectionFinder(algorithm::LineIntersector& newLi)
:
li(newLi),
interiorIntersection(geom::Coordinate::getNull()),
intersectionCount(0),
isCheckEndSegmentsOnly(false),
findAllIntersections(false)
{
}
bool
hasIntersection() const
{
return !interiorIntersection.isNull();
}
const geom::Coordinate&
getInteriorIntersection() const
{
return interiorIntersection;
}
size_t
count() const
{
return intersectionCount;
}
void
setCheckEndSegmentsOnly(bool isCESO)
{
isCheckEndSegmentsOnly = isCESO;
}
void
setFindAllIntersections(bool fAI)
{
findAllIntersections = fAI;
}
const std::vector<geom::Coordinate>&
getIntersectionSegments() const
{
return intSegments;
}
void processIntersections(
SegmentString* e0, std::size_t segIndex0,
SegmentString* e1, std::size_t segIndex1) override;
bool
isDone() const override
{
return !interiorIntersection.isNull();
}
private:
algorithm::LineIntersector& li;
geom::Coordinate interiorIntersection;
std::size_t intersectionCount;
bool isCheckEndSegmentsOnly;
bool findAllIntersections;
std::vector<geom::Coordinate> intSegments;
// Declare type as noncopyable
NodingIntersectionFinder(const NodingIntersectionFinder& other) = delete;
NodingIntersectionFinder& operator=(const NodingIntersectionFinder& rhs) = delete;
static bool isInteriorVertexIntersection(
const geom::Coordinate& p0, const geom::Coordinate& p1,
bool isEnd0, bool isEnd1)
{
// Intersections between endpoints are valid nodes, so not reported
if (isEnd0 && isEnd1) {
return false;
}
if (p0.equals2D(p1)) {
return true;
}
return false;
};
static bool isInteriorVertexIntersection(
const geom::Coordinate& p00, const geom::Coordinate& p01,
const geom::Coordinate& p10, const geom::Coordinate& p11,
bool isEnd00, bool isEnd01, bool isEnd10, bool isEnd11)
{
if (isInteriorVertexIntersection(p00, p10, isEnd00, isEnd10)) {
return true;
}
if (isInteriorVertexIntersection(p00, p11, isEnd00, isEnd11)) {
return true;
}
if (isInteriorVertexIntersection(p01, p10, isEnd01, isEnd10)) {
return true;
}
if (isInteriorVertexIntersection(p01, p11, isEnd01, isEnd11)) {
return true;
}
return false;
};
static bool isEndSegment(const SegmentString* segStr, std::size_t index)
{
if (index == 0) {
return true;
}
if (index >= segStr->size() - 2) {
return true;
}
return false;
};
};
} // namespace geos.noding
} // namespace geos
geos::algorithm::LineIntersector
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition LineIntersector.h:53
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::noding::NodingIntersectionFinder
Finds non-noded intersections in a set of SegmentStrings, if any exist.
Definition NodingIntersectionFinder.h:47
geos::noding::NodingIntersectionFinder::setFindAllIntersections
void setFindAllIntersections(bool fAI)
Sets whether all intersections should be computed.
Definition NodingIntersectionFinder.h:129
geos::noding::NodingIntersectionFinder::getIntersectionSegments
const std::vector< geom::Coordinate > & getIntersectionSegments() const
Gets the endpoints of the intersecting segments.
Definition NodingIntersectionFinder.h:140
geos::noding::NodingIntersectionFinder::getInteriorIntersection
const geom::Coordinate & getInteriorIntersection() const
Gets the computed location of the intersection. Due to round-off, the location may not be exact.
Definition NodingIntersectionFinder.h:85
geos::noding::NodingIntersectionFinder::setCheckEndSegmentsOnly
void setCheckEndSegmentsOnly(bool isCESO)
Sets whether only end segments should be tested for interior intersection.
Definition NodingIntersectionFinder.h:112
geos::noding::NodingIntersectionFinder::NodingIntersectionFinder
NodingIntersectionFinder(algorithm::LineIntersector &newLi)
Creates an intersection finder which finds an interior intersection if one exists.
Definition NodingIntersectionFinder.h:57
geos::noding::NodingIntersectionFinder::hasIntersection
bool hasIntersection() const
Tests whether an intersection was found.
Definition NodingIntersectionFinder.h:73
geos::noding::NodingIntersectionFinder::processIntersections
void processIntersections(SegmentString *e0, std::size_t segIndex0, SegmentString *e1, std::size_t segIndex1) override
This method is called by clients of the SegmentIntersector class to process intersections for two seg...
geos::noding::NodingIntersectionFinder::isDone
bool isDone() const override
Reports whether the client of this class needs to continue testing all intersections in an arrangemen...
Definition NodingIntersectionFinder.h:159
geos::noding::NodingIntersectionFinder::count
size_t count() const
Gets the count of intersections found.
Definition NodingIntersectionFinder.h:96
geos::noding::SegmentString
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::geom
Definition Angle.h:26
geos::noding
Classes to compute nodings for arrangements of line segments and line segment sequences.
Definition CoverageCleaner.h:42
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38