Geometry* BezierSpline::scatter() const { CoordinateArraySequence cds; Coordinate cd,p0,p1,p2,p3; double t; for(int i=0; i<m_firstControlPoints.size(); i++) { p0 = m_knots[i]; p1 = m_firstControlPoints[i]; p2 = m_secondControlPoints[i]; p3 = m_knots[i+1]; for(int j=0; j<=10; j++) { t = j*0.1; cd.x = (1-t)*(1-t)*(1-t)*p0.x + 3*(1-t)*(1-t)*t*p1.x + 3*(1-t)*t*t*p2.x + t*t*t*p3.x; cd.y = (1-t)*(1-t)*(1-t)*p0.y + 3*(1-t)*(1-t)*t*p1.y + 3*(1-t)*t*t*p2.y + t*t*t*p3.y; cds.add(cd); } } LineString* pString = GeometryFactory::getDefaultInstance()->createLineString(cds); return (Geometry*)pString; }
/*public*/ void OffsetCurveBuilder::getSingleSidedLineCurve(const CoordinateSequence* inputPts, double distance, vector<CoordinateSequence*>& lineList, bool leftSide, bool rightSide) { // A zero or negative width buffer of a line/point is empty. if ( distance <= 0.0 ) return ; init( distance ) ; if ( inputPts->getSize() < 2 ) { // No cap, so just return. return ; } else { computeLineBufferCurve( *inputPts ) ; } // NOTE: we take ownership of lineCoord here ... std::auto_ptr<CoordinateSequence> lineCoord (vertexList->getCoordinates()); // [strk] Oct 1, 2009 // Left side: index [n-1] to [endCapIndex] // Right side: index [endCapIndex+1] to [n-2] // Where n is the last index (size-1). int n = lineCoord->size() - 1 ; // Add the left side curve to the line list. if ( leftSide ) { CoordinateArraySequence* coordSeq = new CoordinateArraySequence() ; //coordSeq->add( ( *lineCoord )[n-2] ) ; coordSeq->add( ( *lineCoord )[n-1] ) ; for ( int i = 0 ; i <= endCapIndex ; ++i ) { coordSeq->add( ( *lineCoord )[i] ) ; } lineList.push_back( coordSeq ) ; } // Add the right side curve to the line list. if ( rightSide ) { CoordinateArraySequence* coordSeq = new CoordinateArraySequence() ; for ( int i = endCapIndex+1 ; i <= n-2 ; ++i ) { coordSeq->add( ( *lineCoord )[i] ) ; } lineList.push_back( coordSeq ) ; } }
CoordinateArraySequence::CoordinateArraySequence( const CoordinateArraySequence &c ) : CoordinateSequence(c), vect(new vector<Coordinate>(*(c.vect))), dimension(c.getDimension()) { }
void object::test<2>() { Coordinate c1(1.0000000000004998, -7.989685402102996); Coordinate c2(10.0, -7.004368924503866); Coordinate c3(1.0000000000005, -7.989685402102996); CoordinateArraySequence pts; pts.add(c1); pts.add(c2); pts.add(c3); int const a = CGAlgorithms::computeOrientation(pts[0], pts[1], pts[2]); int const b = CGAlgorithms::computeOrientation(pts[0], pts[1], pts[2]); int const c = CGAlgorithms::computeOrientation(pts[0], pts[1], pts[2]); ensure_equals( a, b ); ensure_equals( a, c ); }
void object::test<16>() { using geos::geom::Coordinate; using geos::geom::CoordinateArraySequence; // Create empty sequence to fill with coordinates CoordinateArraySequence sequence; sequence.add(Coordinate(0,0)); sequence.add(Coordinate(1,1)); sequence.add(Coordinate(2,2)); ensure_equals( sequence.size(), std::size_t(3)); sequence.add(0, Coordinate(4,4), false); // don't alow repeated ensure_equals( sequence.size(), std::size_t(4) ); ensure_equals( sequence.getAt(0).x, std::size_t(4) ); // do not allow repeated sequence.add(0, Coordinate(4,4), false); ensure_equals( sequence.size(), std::size_t(4) ); // allow repeated sequence.add(0, Coordinate(4,4), true); ensure_equals( sequence.size(), std::size_t(5) ); // Now looks like this: 4,4,0,1,2 // we'll add at position 4 a 2 (equals to the one after) sequence.add(4, Coordinate(2,2), false); ensure_equals( sequence.size(), std::size_t(5) ); // we'll add at position 4 a 1 (equals to the one before) sequence.add(4, Coordinate(1,1), false); ensure_equals( sequence.size(), std::size_t(5) ); // we'll add at position 4 a 1 (equals to the one before) // but allowing duplicates sequence.add(4, Coordinate(1,1), true); ensure_equals( sequence.size(), std::size_t(6) ); ensure_equals( sequence.getAt(3).x, 1 ); ensure_equals( sequence.getAt(4).x, 1 ); ensure_equals( sequence.getAt(5).x, 2 ); }