Complete Note#1 in the http://wiki.osgeo.org/wiki/GEOS_Provenance_Review to get out...
[geos.git] / src / operation / linemerge / EdgeString.cpp
blobe03ac6ed5104fe044ce1c32757f33923ddfbb6b8
1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
7 * Copyright (C) 2006 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
15 **********************************************************************
17 * Last port: operation/linemerge/EdgeString.java r378 (JTS-1.12)
19 **********************************************************************/
21 #include <geos/operation/linemerge/EdgeString.h>
22 #include <geos/operation/linemerge/LineMergeEdge.h>
23 #include <geos/operation/linemerge/LineMergeDirectedEdge.h>
24 #include <geos/geom/GeometryFactory.h>
25 #include <geos/geom/CoordinateSequenceFactory.h>
26 #include <geos/geom/CoordinateSequence.h>
27 #include <geos/geom/LineString.h>
29 #include <vector>
30 #include <cassert>
32 using namespace std;
33 using namespace geos::geom;
35 namespace geos {
36 namespace operation { // geos.operation
37 namespace linemerge { // geos.operation.linemerge
39 /**
40 * Constructs an EdgeString with the given factory used to convert
41 * this EdgeString to a LineString
43 EdgeString::EdgeString(const GeometryFactory *newFactory):
44 factory(newFactory),
45 directedEdges(),
46 coordinates(NULL)
50 EdgeString::~EdgeString() {
53 /**
54 * Adds a directed edge which is known to form part of this line.
56 void
57 EdgeString::add(LineMergeDirectedEdge *directedEdge)
59 directedEdges.push_back(directedEdge);
62 CoordinateSequence *
63 EdgeString::getCoordinates()
65 if (coordinates==NULL) {
66 int forwardDirectedEdges = 0;
67 int reverseDirectedEdges = 0;
68 coordinates=factory->getCoordinateSequenceFactory()->create(NULL);
69 for (std::size_t i=0, e=directedEdges.size(); i<e; ++i) {
70 LineMergeDirectedEdge* directedEdge = directedEdges[i];
71 if (directedEdge->getEdgeDirection()) {
72 forwardDirectedEdges++;
73 } else {
74 reverseDirectedEdges++;
77 assert(dynamic_cast<LineMergeEdge*>(directedEdge->getEdge()));
78 LineMergeEdge* lme=static_cast<LineMergeEdge*>( directedEdge->getEdge());
80 coordinates->add(lme->getLine()->getCoordinatesRO(),
81 false,
82 directedEdge->getEdgeDirection());
84 if (reverseDirectedEdges > forwardDirectedEdges) {
85 CoordinateSequence::reverse(coordinates);
88 return coordinates;
92 * Converts this EdgeString into a new LineString.
94 LineString*
95 EdgeString::toLineString()
97 return factory->createLineString(getCoordinates());
100 } // namespace geos.operation.linemerge
101 } // namespace geos.operation
102 } // namespace geos
104 /**********************************************************************
105 * $Log$
106 * Revision 1.10 2006/03/22 10:13:54 strk
107 * opLinemerge.h split
109 **********************************************************************/