1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/**********************************************************************
* $Id: SegmentString.cpp,v 1.11 2004/12/08 13:54:43 strk Exp $
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
* 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 Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#include <geos/noding.h>
namespace geos {
/**
* This function copies given CoordinateSequence
*/
SegmentString::SegmentString(const CoordinateSequence *newPts, const void* newContext)
{
eiList=new SegmentNodeList(this);
isIsolatedVar=false;
pts=newPts;
context=newContext;
}
SegmentString::~SegmentString() {
delete eiList;
//delete pts;
}
const void*
SegmentString::getContext() const
{
return context;
}
SegmentNodeList*
SegmentString::getIntersectionList() const
{
return eiList;
}
int
SegmentString::size() const
{
return pts->getSize();
}
const Coordinate&
SegmentString::getCoordinate(int i) const
{
return pts->getAt(i);
}
CoordinateSequence*
SegmentString::getCoordinates() const
{
return pts->clone();
}
const CoordinateSequence*
SegmentString::getCoordinatesRO() const
{
return pts;
}
void SegmentString::setIsolated(bool isIsolated) {
isIsolatedVar=isIsolated;
}
bool
SegmentString::isIsolated() const
{
return isIsolatedVar;
}
bool
SegmentString::isClosed() const
{
return pts->getAt(0)==pts->getAt(pts->getSize()-1);
}
/**
* Adds EdgeIntersections for one or both
* intersections found for a segment of an edge to the edge intersection list.
*/
void
SegmentString::addIntersections(LineIntersector *li, int segmentIndex, int geomIndex)
{
for (int i=0; i<li->getIntersectionNum(); i++) {
addIntersection(li,segmentIndex, geomIndex, i);
}
}
/**
* Add an SegmentNode for intersection intIndex.
* An intersection that falls exactly on a vertex
* of the SegmentString is normalized
* to use the higher of the two possible segmentIndexes
*/
void
SegmentString::addIntersection(LineIntersector *li, int segmentIndex, int geomIndex, int intIndex)
{
const Coordinate &intPt=li->getIntersection(intIndex);
double dist=li->getEdgeDistance(geomIndex, intIndex);
addIntersection((Coordinate&)intPt, segmentIndex, dist);
//delete intPt;
}
/**
* Add an EdgeIntersection for intersection intIndex.
* An intersection that falls exactly on a vertex of the edge is normalized
* to use the higher of the two possible segmentIndexes
*/
void
SegmentString::addIntersection(Coordinate& intPt, int segmentIndex)
{
double dist=LineIntersector::computeEdgeDistance(intPt,pts->getAt(segmentIndex),pts->getAt(segmentIndex + 1));
addIntersection(intPt, segmentIndex, dist);
}
void
SegmentString::addIntersection(Coordinate& intPt,
int segmentIndex, double dist)
{
int normalizedSegmentIndex = segmentIndex;
//Debug.println("edge intpt: " + intPt + " dist: " + dist);
// normalize the intersection point location
int nextSegIndex = normalizedSegmentIndex + 1;
if (nextSegIndex < pts->getSize()) {
const Coordinate &nextPt = pts->getAt(nextSegIndex);
//Debug.println("next pt: " + nextPt);
// Normalize segment index if intPt falls on vertex
// The check for point equality is 2D only - Z values are ignored
if (intPt.equals2D(nextPt)) {
//Debug.println("normalized distance");
normalizedSegmentIndex = nextSegIndex;
dist = 0.0;
}
}
/**
* Add the intersection point to edge intersection list.
*/
//SegmentNode *ei=
eiList->add(&intPt, normalizedSegmentIndex, dist);
//ei.print(System.out);
}
} // namespace geos
/**********************************************************************
* $Log: SegmentString.cpp,v $
* Revision 1.11 2004/12/08 13:54:43 strk
* gcc warnings checked and fixed, general cleanups.
*
* Revision 1.10 2004/11/01 16:43:04 strk
* Added Profiler code.
* Temporarly patched a bug in DoubleBits (must check drawbacks).
* Various cleanups and speedups.
*
* Revision 1.9 2004/07/08 19:34:49 strk
* Mirrored JTS interface of CoordinateSequence, factory and
* default implementations.
* Added DefaultCoordinateSequenceFactory::instance() function.
*
* Revision 1.8 2004/07/02 13:28:27 strk
* Fixed all #include lines to reflect headers layout change.
* Added client application build tips in README.
*
* Revision 1.7 2004/07/01 14:12:44 strk
*
* Geometry constructors come now in two flavors:
* - deep-copy args (pass-by-reference)
* - take-ownership of args (pass-by-pointer)
* Same functionality is available through GeometryFactory,
* including buildGeometry().
*
* Revision 1.6 2004/06/16 13:13:25 strk
* Changed interface of SegmentString, now copying CoordinateSequence argument.
* Fixed memory leaks associated with this and MultiGeometry constructors.
* Other associated fixes.
*
* Revision 1.5 2004/05/27 10:27:03 strk
* Memory leaks fixed.
*
* Revision 1.4 2004/05/07 07:57:27 strk
* Added missing EdgeNodingValidator to build scripts.
* Changed SegmentString constructor back to its original form
* (takes const void *), implemented local tracking of "contexts"
* in caller objects for proper destruction.
*
* Revision 1.3 2004/05/06 15:54:15 strk
* SegmentNodeList keeps track of created splitEdges for later destruction.
* SegmentString constructor copies given Label.
* Buffer operation does no more leaks for doc/example.cpp
*
* Revision 1.2 2004/04/19 16:14:52 strk
* Some memory leaks plugged in noding algorithms.
*
* Revision 1.1 2004/03/26 07:48:30 ybychkov
* "noding" package ported (JTS 1.4)
*
*
**********************************************************************/
|