1 /**********************************************************************
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
7 * Copyright (C) 2005-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 **********************************************************************/
19 #include <geos/algorithm/InteriorPointLine.h>
20 #include <geos/geom/Coordinate.h>
21 #include <geos/geom/Geometry.h>
22 #include <geos/geom/GeometryCollection.h>
23 #include <geos/geom/LineString.h>
24 #include <geos/geom/CoordinateSequence.h>
34 using namespace geos::geom
;
37 namespace algorithm
{ // geos.algorithm
39 InteriorPointLine::InteriorPointLine(const Geometry
*g
)
41 minDistance
=DoubleInfinity
;
43 if ( g
->getCentroid(centroid
) )
46 std::cerr
<< "Centroid: " << centroid
<< std::endl
;
49 if (!hasInterior
) addEndpoints(g
);
53 InteriorPointLine::~InteriorPointLine()
59 * Tests the interior vertices (if any)
60 * defined by a linear Geometry for the best inside point.
61 * If a Geometry is not of dimension 1 it is not tested.
62 * @param geom the geometry to add
65 InteriorPointLine::addInterior(const Geometry
*geom
)
67 const LineString
*ls
= dynamic_cast<const LineString
*>(geom
);
69 addInterior(ls
->getCoordinatesRO());
73 const GeometryCollection
*gc
= dynamic_cast<const GeometryCollection
*>(geom
);
76 for(std::size_t i
=0, n
=gc
->getNumGeometries(); i
<n
; i
++) {
77 addInterior(gc
->getGeometryN(i
));
83 InteriorPointLine::addInterior(const CoordinateSequence
*pts
)
85 const std::size_t n
=pts
->getSize()-1;
86 for(std::size_t i
=1; i
<n
; ++i
)
94 * Tests the endpoint vertices
95 * defined by a linear Geometry for the best inside point.
96 * If a Geometry is not of dimension 1 it is not tested.
97 * @param geom the geometry to add
100 InteriorPointLine::addEndpoints(const Geometry
*geom
)
102 const LineString
*ls
= dynamic_cast<const LineString
*>(geom
);
104 addEndpoints(ls
->getCoordinatesRO());
108 const GeometryCollection
*gc
= dynamic_cast<const GeometryCollection
*>(geom
);
111 for(std::size_t i
=0, n
=gc
->getNumGeometries(); i
<n
; i
++) {
112 addEndpoints(gc
->getGeometryN(i
));
118 InteriorPointLine::addEndpoints(const CoordinateSequence
*pts
)
121 add(pts
->getAt(pts
->getSize()-1));
126 InteriorPointLine::add(const Coordinate
& point
)
129 double dist
=point
.distance(centroid
);
131 std::cerr
<< "point " << point
<< " dist " << dist
<< ", minDistance " << minDistance
<< std::endl
;
133 if (!hasInterior
|| dist
<minDistance
) {
136 std::cerr
<< " is new InteriorPoint" << std::endl
;
144 InteriorPointLine::getInteriorPoint(Coordinate
& ret
) const
146 if ( ! hasInterior
) return false;
151 } // namespace geos.algorithm
154 /**********************************************************************
156 * Revision 1.18 2006/03/21 11:12:23 strk
157 * Cleanups: headers inclusion and Log section
159 * Revision 1.17 2006/03/09 16:46:45 strk
160 * geos::geom namespace definition, first pass at headers split
161 **********************************************************************/