void GeometryGraph::addPolygon(const Polygon *p) { const LineString* ls; const LinearRing* lr; ls = p->getExteriorRing(); assert(dynamic_cast<const LinearRing*>(ls)); lr = static_cast<const LinearRing*>(ls); addPolygonRing(lr, Location::EXTERIOR, Location::INTERIOR); for (size_t i=0, n=p->getNumInteriorRing(); i<n; ++i) { // Holes are topologically labelled opposite to the shell, since // the interior of the polygon lies on their opposite side // (on the left, if the hole is oriented CW) ls = p->getInteriorRingN(i); assert(dynamic_cast<const LinearRing*>(ls)); lr = static_cast<const LinearRing*>(ls); addPolygonRing(lr, Location::INTERIOR, Location::EXTERIOR); } }
void OffsetCurveSetBuilder::addPolygon(const Polygon *p) { double offsetDistance=distance; int offsetSide=Position::LEFT; if (distance < 0.0) { offsetDistance=-distance; offsetSide=Position::RIGHT; } const LinearRing *shell=(const LinearRing *)p->getExteriorRing(); CoordinateSequence *shellCoord = CoordinateSequence::removeRepeatedPoints(shell->getCoordinatesRO()); // optimization - don't bother computing buffer // if the polygon would be completely eroded if (distance < 0.0 && isErodedCompletely(shellCoord, distance)) { delete shellCoord; return; } addPolygonRing(shellCoord,offsetDistance,offsetSide,Location::EXTERIOR,Location::INTERIOR); delete shellCoord; for (int i=0;i<p->getNumInteriorRing(); i++) { const LinearRing *hole=(const LinearRing *)p->getInteriorRingN(i); CoordinateSequence *holeCoord=CoordinateSequence::removeRepeatedPoints(hole->getCoordinatesRO()); // optimization - don't bother computing buffer for this hole // if the hole would be completely covered if (distance > 0.0 && isErodedCompletely(holeCoord, -distance)) { delete holeCoord; continue; } // Holes are topologically labelled opposite to the shell, since // the interior of the polygon lies on their opposite side // (on the left, if the hole is oriented CCW) addPolygonRing(holeCoord,offsetDistance,Position::opposite(offsetSide),Location::INTERIOR,Location::EXTERIOR); delete holeCoord; } }
/*private*/ void OffsetCurveSetBuilder::addPolygon(const Polygon *p) { double offsetDistance=distance; int offsetSide=Position::LEFT; if (distance < 0.0) { offsetDistance = -distance; offsetSide = Position::RIGHT; } // FIXME: avoid the C-style cast const LinearRing *shell=(const LinearRing *)p->getExteriorRing(); CoordinateSequence *shellCoord = CoordinateSequence::removeRepeatedPoints(shell->getCoordinatesRO()); // optimization - don't bother computing buffer // if the polygon would be completely eroded if (distance < 0.0 && isErodedCompletely(shellCoord, distance)) { delete shellCoord; return; } // don't attemtp to buffer a polygon // with too few distinct vertices if (distance <= 0.0 && shellCoord->size() < 3) { delete shellCoord; return; } addPolygonRing( shellCoord, offsetDistance, offsetSide, Location::EXTERIOR, Location::INTERIOR); delete shellCoord; for (size_t i=0, n=p->getNumInteriorRing(); i<n; ++i) { const LineString *hls=p->getInteriorRingN(i); assert(dynamic_cast<const LinearRing *>(hls)); const LinearRing *hole=static_cast<const LinearRing *>(hls); CoordinateSequence *holeCoord=CoordinateSequence::removeRepeatedPoints(hole->getCoordinatesRO()); // optimization - don't bother computing buffer for this hole // if the hole would be completely covered if (distance > 0.0 && isErodedCompletely(holeCoord, -distance)) { delete holeCoord; continue; } // Holes are topologically labelled opposite to the shell, // since the interior of the polygon lies on their opposite // side (on the left, if the hole is oriented CCW) addPolygonRing( holeCoord, offsetDistance, Position::opposite(offsetSide), Location::INTERIOR, Location::EXTERIOR); delete holeCoord; } }