Пример #1
0
bool MgCmdDrawLines::canAddPoint(const MgMotion* sender, const Point2d& pnt)
{
    float distmin = sender->displayMmToModel(3.f);
    int maxIndex = ((MgBaseLines*)dynshape()->shape())->maxEdgeIndex();
    Point2d prevPt(dynshape()->shape()->getPoint(m_index - 1));
    
    if (prevPt.distanceTo(pnt) < distmin) {
        return false;
    }
    if (m_index < maxIndex) {
        if (dynshape()->shape()->getPoint(m_index + 1).distanceTo(pnt) < distmin) {
            return false;
        }
    }
    if (dynshape()->shape()->isClosed() || m_index < maxIndex) {
        int n = dynshape()->shape()->getPointCount();
        Point2d nextPt(dynshape()->shape()->getPoint( (m_index + 1) % n) );
        Point2d nearpt;
        
        if (mglnrel::ptToLine(prevPt, nextPt, pnt, nearpt)
            < sender->displayMmToModel(1.f)) {
            return false;
        }
    }
    
    return true;
}
Пример #2
0
//----------------------------------------------------------						
void ofxVectorGraphics::endShape(bool bClose){
	if(bDraw){
		ofEndShape(bClose);
	}
	if(bRecord){
											
		//catmull roms - we need at least 4 points to draw
		if( whichShapeMode == 1 && curvePts.size() > 3){												
			
			//we go through and we calculate the bezier of each 
			//catmull rom curve - smart right? :)
			for (int i = 1; i< curvePts.size()-2; i++) {
				
				ofPoint3 prevPt(	curvePts[i-1][0],	curvePts[i-1][1]);
				ofPoint3 startPt(curvePts[i][0],		curvePts[i][1]);							
				ofPoint3 endPt(	curvePts[i+1][0],	curvePts[i+1][1]);
				ofPoint3 nextPt(	curvePts[i+2][0],	curvePts[i+2][1]);
				
				//SUPER WEIRD MAGIC CONSTANT = 1/6
				//Someone please explain this!!! 
				//It works and is 100% accurate but wtf!
				ofPoint3 cp1 = startPt + ( endPt - prevPt ) * (1.0/6);
				ofPoint3 cp2 = endPt + ( startPt - nextPt ) * (1.0/6);						
				
				//if this is the first line we are drawing 
				//we have to start the path at a location
				if( i == 1 ){
					creeps.startPath(startPt.x, startPt.y);
					bShouldClose = true;
				}
				
				creeps.addCurve( cp1.x, cp1.y, cp2.x, cp2.y, endPt.x, endPt.y);
			}						
		}
		
		if(bShouldClose){														
			//we close the path if requested
			if(bClose)creeps.closeSubpath();
		
			//render the stroke as either a fill or a stroke.
			if(bFill){
				creeps.endPath(CreEPS::FILL);
			}else{
				creeps.endPath(CreEPS::STROKE);
			}
			bShouldClose = false;
		}
		
		//we want to clear all the vertices
		//otherwise we keep adding points from
		//the previous file - cool but not what we want!
		clearAllVertices();
		
	}
}			
Пример #3
0
	ClipperLib::Path pathToClipperPath(const panda::types::Path& path)
	{
		ClipperLib::Path out;
		auto maxVal = std::numeric_limits<ClipperLib::cInt>::max();
		ClipperLib::IntPoint prevPt(maxVal, maxVal);
		for (const auto& pt : path.points)
		{
			auto newPt = convert(pt);
			if (newPt == prevPt)
				continue;
			out.push_back(newPt);
			prevPt = newPt;
		}

		if (path.points.size() > 1 && path.points.back() == path.points.front())
			out.pop_back();
		return out;
	}