//---------------------------------------------------------- void ofPath::scale(float x, float y){ if(mode==COMMANDS){ for(int j=0;j<(int)commands.size();j++){ commands[j].to.x*=x; commands[j].to.y*=y; if(commands[j].type==Command::bezierTo || commands[j].type==Command::quadBezierTo){ commands[j].cp1.x*=x; commands[j].cp1.y*=y; commands[j].cp2.x*=x; commands[j].cp2.y*=y; } if(commands[j].type==Command::arc || commands[j].type==Command::arcNegative){ commands[j].radiusX *= x; commands[j].radiusY *= y; } } }else{ for(int i=0;i<(int)polylines.size();i++){ for(int j=0;j<(int)polylines[i].size();j++){ polylines[i][j].x*=x; polylines[i][j].y*=y; } } } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::close(){ if(mode==COMMANDS){ addCommand(Command(Command::close)); }else{ lastPolyline().setClosed(true); } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::lineTo(const ofPoint & p){ if(mode==COMMANDS){ addCommand(Command(Command::lineTo,p)); }else{ lastPolyline().lineTo(p); } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::quadBezierTo(const ofPoint & cp1, const ofPoint & cp2, const ofPoint & p){ if(mode==COMMANDS){ addCommand(Command(Command::quadBezierTo,p,cp1,cp2)); }else{ lastPolyline().quadBezierTo(cp1,cp2,p,curveResolution); } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::arcNegative(const ofPoint & centre, float radiusX, float radiusY, float angleBegin, float angleEnd){ if(mode==COMMANDS){ addCommand(Command(Command::arcNegative,centre,radiusX,radiusY,angleBegin,angleEnd)); }else{ lastPolyline().arcNegative(centre,radiusX,radiusY,angleBegin,angleEnd,circleResolution); } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::curveTo(const ofPoint & p){ if(mode==COMMANDS){ addCommand(Command(Command::curveTo,p)); }else{ lastPolyline().curveTo(p,curveResolution); } flagShapeChanged(); }
//---------------------------------------------------------- vector<ofPath::Command> & ofPath::getCommands(){ if(mode==POLYLINES){ ofLogWarning("ofPath") << "getCommands(): trying to get path commands from shape with polylines only"; }else{ flagShapeChanged(); } return commands; }
//---------------------------------------------------------- void ofPath::bezierTo(const glm::vec3 & cp1, const glm::vec3 & cp2, const glm::vec3 & p){ if(mode==COMMANDS){ addCommand(Command(Command::bezierTo,p,cp1,cp2)); }else{ lastPolyline().bezierTo(cp1,cp2,p,curveResolution); } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::moveTo(const ofPoint & p){ if(mode==COMMANDS){ addCommand(Command(Command::moveTo,p)); }else{ if(lastPolyline().size()>0) newSubPath(); lastPolyline().addVertex(p); } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::clear(){ commands.clear(); // for performance, instead of clearing the whole vector // let one polyline and clear it: avoids instantiation polylines.resize(1); polylines[0].clear(); cachedTessellation.clear(); flagShapeChanged(); }
void ofPath::append(const ofPath & path){ if(mode==COMMANDS){ for(auto & command: path.getCommands()){ addCommand(command); } }else{ for(auto & poly: path.getOutline()){ polylines.push_back(poly); } } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::translate(const ofPoint & p){ if(mode==COMMANDS){ for(int j=0;j<(int)commands.size();j++){ commands[j].to += p; if(commands[j].type==Command::bezierTo || commands[j].type==Command::quadBezierTo){ commands[j].cp1 += p; commands[j].cp2 += p; } } }else{ for(int i=0;i<(int)polylines.size();i++){ for(int j=0;j<(int)polylines[i].size();j++){ polylines[i][j] += p; } } } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::rotate(float az, const ofVec3f& axis ){ if(mode==COMMANDS){ for(int j=0;j<(int)commands.size();j++){ commands[j].to.rotate(az,axis); if(commands[j].type==Command::bezierTo || commands[j].type==Command::quadBezierTo){ commands[j].cp1.rotate(az,axis); commands[j].cp2.rotate(az,axis); } if(commands[j].type==Command::arc || commands[j].type==Command::arcNegative){ commands[j].angleBegin += az; commands[j].angleEnd += az; } } }else{ for(int i=0;i<(int)polylines.size();i++){ for(int j=0;j<(int)polylines[i].size();j++){ polylines[i][j].rotate(az,axis); } } } flagShapeChanged(); }
//---------------------------------------------------------- void ofPath::rotate(float az, const glm::vec3& axis ){ auto radians = ofDegToRad(az); if(mode==COMMANDS){ for(int j=0;j<(int)commands.size();j++){ commands[j].to = glm::rotate(commands[j].to, radians, axis); if(commands[j].type==Command::bezierTo || commands[j].type==Command::quadBezierTo){ commands[j].cp1 = glm::rotate(commands[j].cp1, radians, axis); commands[j].cp2 = glm::rotate(commands[j].cp2, radians, axis); } if(commands[j].type==Command::arc || commands[j].type==Command::arcNegative){ commands[j].angleBegin += az; commands[j].angleEnd += az; } } }else{ for(int i=0;i<(int)polylines.size();i++){ for(int j=0;j<(int)polylines[i].size();j++){ polylines[i][j] = glm::rotate(toGlm(polylines[i][j]), radians, axis); } } } flagShapeChanged(); }