From c5410c336deb1cb25577d8ce97a69485d7c1cf9e Mon Sep 17 00:00:00 2001 From: Ralf Gerlich Date: Tue, 1 Jan 2008 22:07:47 +0100 Subject: [PATCH] Now using a much simpler method for finding a point in a polygon (taken from GRASS GIS) --- src/Lib/Geometry/poly_support.cxx | 108 ++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 7 deletions(-) diff --git a/src/Lib/Geometry/poly_support.cxx b/src/Lib/Geometry/poly_support.cxx index e5dd1a36..93c572ef 100644 --- a/src/Lib/Geometry/poly_support.cxx +++ b/src/Lib/Geometry/poly_support.cxx @@ -30,10 +30,13 @@ #include #include #include +#include #include #include +#include + #define REAL double extern "C" { #include @@ -47,6 +50,7 @@ extern "C" { SG_USING_STD(cout); SG_USING_STD(endl); +SG_USING_STD(sort); // Given a line segment specified by two endpoints p1 and p2, return // the slope of the line. @@ -811,6 +815,46 @@ static Point3D point_inside_contour( TGContourNode *node, const TGPolygon &p ) { } +static void intersect_yline_with_contour( double yline, TGContourNode *node, TGPolygon &p, vector < double > &xcuts ) { + int contour_num = node->get_contour_num(); + const point_list& pts=p.get_contour(contour_num); + + point_list::size_type count = pts.size(); + + cout << "intersect_yline_with_contour() yline=" << yline << endl; + + for ( int i = 0; i < count; ++i ) { + const Point3D &p0 = pts[ i ]; + const Point3D &p1 = pts[ ( i + 1 ) % count ]; + + double ymin=p0.y(),ymax=p0.y(); + + if (p1.y() maxlen) { + maxlen=x1-x0; + longest=i; + } + } + + double x = (xcuts[ longest ] + xcuts[ longest + 1 ])/2.0; + + p.set_point_inside( contour_num, Point3D(x, yline, -9999.0) ); } - static void print_contour_tree( TGContourNode *node, string indent ) { cout << indent << node->get_contour_num() << endl;