⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 offsetcurvebuilder.cpp

📁 在Linux下做的QuadTree的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*private*/voidOffsetCurveBuilder::addLastSegment(){	vertexList->addPt(offset1.p1);}/*private*/voidOffsetCurveBuilder::computeOffsetSegment(const LineSegment& seg, int side,	double distance, LineSegment& offset){	int sideSign = side == Position::LEFT ? 1 : -1;	double dx = seg.p1.x - seg.p0.x;	double dy = seg.p1.y - seg.p0.y;	double len = sqrt(dx * dx + dy * dy);	// u is the vector that is the length of the offset, in the direction of the segment	double ux = sideSign * distance * dx / len;	double uy = sideSign * distance * dy / len;	offset.p0.x = seg.p0.x - uy;	offset.p0.y = seg.p0.y + ux;	offset.p1.x = seg.p1.x - uy;	offset.p1.y = seg.p1.y + ux;}/*private*/voidOffsetCurveBuilder::addLineEndCap(const Coordinate &p0,const Coordinate &p1){	LineSegment seg(p0, p1);	LineSegment offsetL;	computeOffsetSegment(seg, Position::LEFT, distance, offsetL);	LineSegment offsetR;	computeOffsetSegment(seg, Position::RIGHT, distance, offsetR);	double dx=p1.x-p0.x;	double dy=p1.y-p0.y;	double angle=atan2(dy, dx);	switch (endCapStyle) {		case BufferOp::CAP_ROUND:			// add offset seg points with a fillet between them			vertexList->addPt(offsetL.p1);			addFillet(p1, angle+PI/2.0, angle-PI/2.0, CGAlgorithms::CLOCKWISE, distance);			vertexList->addPt(offsetR.p1);			break;		case BufferOp::CAP_BUTT:			// only offset segment points are added			vertexList->addPt(offsetL.p1);			vertexList->addPt(offsetR.p1);			break;		case BufferOp::CAP_SQUARE:			// add a square defined by extensions of the offset segment endpoints			Coordinate squareCapSideOffset;			squareCapSideOffset.x=fabs(distance)*cos(angle);			squareCapSideOffset.y=fabs(distance)*sin(angle);			Coordinate squareCapLOffset(offsetL.p1.x+squareCapSideOffset.x,					offsetL.p1.y+squareCapSideOffset.y);			Coordinate squareCapROffset(offsetR.p1.x+squareCapSideOffset.x,					offsetR.p1.y+squareCapSideOffset.y);			vertexList->addPt(squareCapLOffset);			vertexList->addPt(squareCapROffset);			break;	}}/*private*/voidOffsetCurveBuilder::addFillet(const Coordinate &p, const Coordinate &p0,	const Coordinate &p1, int direction, double distance){	double dx0=p0.x-p.x;	double dy0=p0.y-p.y;	double startAngle=atan2(dy0, dx0);	double dx1=p1.x-p.x;	double dy1=p1.y-p.y;	double endAngle=atan2(dy1, dx1);	if (direction==CGAlgorithms::CLOCKWISE) {		if (startAngle<= endAngle) startAngle += 2.0*PI;	} else {    // direction==COUNTERCLOCKWISE		if (startAngle>=endAngle) startAngle-=2.0*PI;	}	vertexList->addPt(p0);	addFillet(p, startAngle, endAngle, direction, distance);	vertexList->addPt(p1);}/*private*/voidOffsetCurveBuilder::addFillet(const Coordinate &p, double startAngle,	double endAngle, int direction, double distance){	int directionFactor=direction==CGAlgorithms::CLOCKWISE ? -1 : 1;	double totalAngle=fabs(startAngle-endAngle);	int nSegs=(int) (totalAngle / filletAngleQuantum+0.5);	if (nSegs<1) return;   // no segments because angle is less than increment-nothing to do!	double initAngle, currAngleInc;	// choose angle increment so that each segment has equal length	initAngle=0.0;	currAngleInc=totalAngle / nSegs;	double currAngle=initAngle;	Coordinate pt;	while (currAngle<totalAngle) {		double angle=startAngle+directionFactor*currAngle;		pt.x=p.x+distance*cos(angle);		pt.y=p.y+distance*sin(angle);		vertexList->addPt(pt);		currAngle += currAngleInc;	}}/*private*/voidOffsetCurveBuilder::addCircle(const Coordinate &p, double distance){	// add start point	Coordinate pt(p);	pt.x+=distance;	vertexList->addPt(pt);	addFillet(p, 0.0, 2.0*PI, -1, distance);}/*private*/voidOffsetCurveBuilder::addSquare(const Coordinate &p, double distance){	// add start point	vertexList->addPt(Coordinate(p.x+distance, p.y+distance));	vertexList->addPt(Coordinate(p.x+distance, p.y-distance));	vertexList->addPt(Coordinate(p.x-distance, p.y-distance));	vertexList->addPt(Coordinate(p.x-distance, p.y+distance));	vertexList->addPt(Coordinate(p.x+distance, p.y+distance));}} // namespace geos.operation.buffer} // namespace geos.operation} // namespace geos/********************************************************************** * $Log$ * Revision 1.34  2006/03/27 17:59:00  strk * Fixed small leak. * * Revision 1.33  2006/03/27 17:04:18  strk * Cleanups and explicit initializations * * Revision 1.32  2006/03/20 11:42:29  strk * Added missing <cmath> include * * Revision 1.31  2006/03/14 00:19:40  strk * opBuffer.h split, streamlined headers in some (not all) files in operation/buffer/ * * Revision 1.30  2006/03/11 16:58:41  strk * Fixed bug in OffsetCurveBuilder::getCoordinates. * * Revision 1.29  2006/03/09 17:40:24  strk * Fixed bug#33 (hopefully) * * Revision 1.28  2006/03/09 16:46:49  strk * geos::geom namespace definition, first pass at headers split * * Revision 1.27  2006/03/07 14:20:15  strk * Big deal of heap allocations reduction * * Revision 1.26  2006/03/03 10:46:21  strk * Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46) * * Revision 1.25  2006/03/02 12:12:01  strk * Renamed DEBUG macros to GEOS_DEBUG, all wrapped in #ifndef block to allow global override (bug#43) * * Revision 1.24  2006/02/28 19:22:21  strk * Fixed in-place definition of static members in OffsetCurveBuilder (bug#33) * * Revision 1.23  2006/02/28 14:34:05  strk * Added many assertions and debugging output hunting for a bug in BufferOp * * Revision 1.22  2006/02/19 19:46:49  strk * Packages <-> namespaces mapping for most GEOS internal code (uncomplete, but working). Dir-level libs for index/ subdirs. * * Revision 1.21  2006/02/18 21:08:09  strk * - new CoordinateSequence::applyCoordinateFilter method (slow but useful) * - SegmentString::getCoordinates() doesn't return a clone anymore. * - SegmentString::getCoordinatesRO() obsoleted. * - SegmentString constructor does not promises constness of passed *   CoordinateSequence anymore. * - NEW ScaledNoder class * - Stubs for MCIndexPointSnapper and  MCIndexSnapRounder * - Simplified internal interaces of OffsetCurveBuilder and OffsetCurveSetBuilder * * Revision 1.20  2006/01/31 19:07:34  strk * - Renamed DefaultCoordinateSequence to CoordinateArraySequence. * - Moved GetNumGeometries() and GetGeometryN() interfaces *   from GeometryCollection to Geometry class. * - Added getAt(int pos, Coordinate &to) funtion to CoordinateSequence class. * - Reworked automake scripts to produce a static lib for each subdir and *   then link all subsystem's libs togheter * - Moved C-API in it's own top-level dir capi/ * - Moved source/bigtest and source/test to tests/bigtest and test/xmltester * - Fixed PointLocator handling of LinearRings * - Changed CoordinateArrayFilter to reduce memory copies * - Changed UniqueCoordinateArrayFilter to reduce memory copies * - Added CGAlgorithms::isPointInRing() version working with *   Coordinate::ConstVect type (faster!) * - Ported JTS-1.7 version of ConvexHull with big attention to *   memory usage optimizations. * - Improved XMLTester output and user interface * - geos::geom::util namespace used for geom/util stuff * - Improved memory use in geos::geom::util::PolygonExtractor * - New ShortCircuitedGeometryVisitor class * - New operation/predicate package * * Revision 1.19  2005/06/24 11:09:43  strk * Dropped RobustLineIntersector, made LineIntersector a concrete class. * Added LineIntersector::hasIntersection(Coordinate&,Coordinate&,Coordinate&) * to avoid computing intersection point (Z) when it's not necessary. * * Revision 1.18  2005/05/19 10:29:28  strk * Removed some CGAlgorithms instances substituting them with direct calls * to the static functions. Interfaces accepting CGAlgorithms pointers kept * for backward compatibility but modified to make the argument optional. * Fixed a small memory leak in OffsetCurveBuilder::getRingCurve. * Inlined some smaller functions encountered during bug hunting. * Updated Copyright notices in the touched files. * * Revision 1.17  2005/02/17 09:56:31  strk * Commented out unused variable. * * Revision 1.16  2005/02/05 05:44:47  strk * Changed geomgraph nodeMap to use Coordinate pointers as keys, reduces * lots of other Coordinate copies. * * Revision 1.15  2004/12/08 13:54:44  strk * gcc warnings checked and fixed, general cleanups. * * Revision 1.14  2004/11/04 19:08:07  strk * Cleanups, initializers list, profiling. * * Revision 1.13  2004/07/13 08:33:53  strk * Added missing virtual destructor to virtual classes. * Fixed implicit unsigned int -> int casts * * Revision 1.12  2004/07/08 19:34:49  strk * Mirrored JTS interface of CoordinateSequence, factory and * default implementations. * Added CoordinateArraySequenceFactory::instance() function. * * Revision 1.11  2004/07/02 13:28:27  strk * Fixed all #include lines to reflect headers layout change. * Added client application build tips in README. * * Revision 1.10  2004/05/27 08:37:16  strk * Fixed a bug preventing OffsetCurveBuilder point list from being reset. * * Revision 1.9  2004/05/26 19:48:19  strk * Changed abs() to fabs() when working with doubles. * Used dynamic_cast<> instead of typeid() when JTS uses instanceof. * * Revision 1.8  2004/05/19 13:40:49  strk * Fixed bug in ::addCircle * * Revision 1.7  2004/05/05 13:08:01  strk * Leaks fixed, explicit allocations/deallocations reduced. * * Revision 1.6  2004/04/20 10:58:04  strk * More memory leaks removed. * * Revision 1.5  2004/04/19 16:14:52  strk * Some memory leaks plugged in noding algorithms. * * Revision 1.4  2004/04/19 15:14:46  strk * Added missing virtual destructor in SpatialIndex class. * Memory leaks fixes. Const and throw specifications added. * * Revision 1.3  2004/04/16 13:03:17  strk * More leaks fixed * * Revision 1.2  2004/04/16 12:48:07  strk * Leak fixes. * * Revision 1.1  2004/04/10 08:40:01  ybychkov * "operation/buffer" upgraded to JTS 1.4 * * **********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -