Esempio n. 1
0
/* public static */
void
DistanceToPoint::computeDistance(const geom::LineString& line,
                                          const geom::Coordinate& pt,
                                          PointPairDistance& ptDist)
{
	const CoordinateSequence* coordsRO = line.getCoordinatesRO();
	const CoordinateSequence& coords = *coordsRO;

	size_t npts = coords.size();
	if ( ! npts ) return; // can this ever be ?

	LineSegment tempSegment;
	Coordinate closestPt;

	Coordinate* segPts[2] = { &(tempSegment.p0), &(tempSegment.p1) };
	tempSegment.p0 = coords.getAt(0);
	for (size_t i=1; i<npts; ++i)
	{
		*(segPts[i%2]) = coords.getAt(i);

		// this is somewhat inefficient - could do better
		tempSegment.closestPoint(pt, closestPt);
		ptDist.setMinimum(closestPt, pt);
	}
}
Esempio n. 2
0
void MaximalSubline::MatchCriteria::maximalNearestSubline(LineSegment& a,
        LineSegment& b) const
{
    Coordinate a1, a2;
    Coordinate b1, b2;

    a.closestPoint(b.p0, a1);
    a.closestPoint(b.p1, a2);

    b.closestPoint(a.p0, b1);
    b.closestPoint(a.p1, b2);

    a.p0 = a1;
    a.p1 = a2;

    b.p0 = b1;
    b.p1 = b2;
}