/** * this should handle modifyOffset *@ coord, indicate direction of offset *@ distance of offset * *@Author, Dongxu Li */ bool RS_Polyline::offset(const RS_Vector& coord, const double& distance){ double dist; //find the nearest one int length=count(); QVector<RS_Vector> intersections(length); if(length>1){//sort the polyline entity start/end point order int i(0); double d0,d1; RS_Entity* en0(entityAt(0)); RS_Entity* en1(entityAt(1)); RS_Vector vStart(en0->getStartpoint()); RS_Vector vEnd(en0->getEndpoint()); en1->getNearestEndpoint(vStart,&d0); en1->getNearestEndpoint(vEnd,&d1); if(d0<d1) en0->revertDirection(); for(i=1;i<length;en0=en1){ //linked to head-tail chain en1=entityAt(i); vStart=en1->getStartpoint(); vEnd=en1->getEndpoint(); en0->getNearestEndpoint(vStart,&d0); en0->getNearestEndpoint(vEnd,&d1); if(d0>d1) en1->revertDirection(); intersections[i-1]=(en0->getEndpoint()+en1->getStartpoint())*0.5; i++; } } RS_Entity* en(getNearestEntity(coord, &dist, RS2::ResolveNone)); if(en==NULL) return false; int indexNearest=findEntity(en); // RS_Vector vp(en->getNearestPointOnEntity(coord,false)); // RS_Vector direction(en->getTangentDirection(vp)); // RS_Vector vp1(-direction.y,direction.x);//normal direction // double a2(vp1.squared()); // if(a2<RS_TOLERANCE2) return false; // vp1 *= distance/sqrt(a2); // move(vp1); // return true; RS_Polyline* pnew= static_cast<RS_Polyline*>(clone()); int i; i=indexNearest; int previousIndex(i); pnew->entityAt(i)->offset(coord,distance); RS_Vector vp; //offset all //fixme, this is too ugly for(i=indexNearest-1;i>=0;i--){ RS_VectorSolutions sol0=RS_Information::getIntersection(pnew->entityAt(previousIndex),entityAt(i),true); // RS_VectorSolutions sol1; double dmax(RS_TOLERANCE15); RS_Vector trimP(false); for(int j=0;j<sol0.getNumber();j++){ double d0( (sol0.get(j) - pnew->entityAt(previousIndex)->getStartpoint()).squared());//potential bug, need to trim better if(d0>dmax) { dmax=d0; trimP=sol0.get(j); } } if(trimP.valid){ static_cast<RS_AtomicEntity*>(pnew->entityAt(previousIndex))->trimStartpoint(trimP); static_cast<RS_AtomicEntity*>(pnew->entityAt(i))->trimEndpoint(trimP); vp=pnew->entityAt(previousIndex)->getMiddlePoint(); }else{ vp=pnew->entityAt(previousIndex)->getStartpoint(); vp.rotate(entityAt(previousIndex)->getStartpoint(),entityAt(i)->getDirection2()-entityAt(previousIndex)->getDirection1()+M_PI); } pnew->entityAt(i)->offset(vp,distance); previousIndex=i; } previousIndex=indexNearest; for(i=indexNearest+1;i<length;i++){ RS_VectorSolutions sol0=RS_Information::getIntersection(pnew->entityAt(previousIndex),entityAt(i),true); // RS_VectorSolutions sol1; double dmax(RS_TOLERANCE15); RS_Vector trimP(false); for(int j=0;j<sol0.getNumber();j++){ double d0( (sol0.get(j) - pnew->entityAt(previousIndex)->getEndpoint()).squared());//potential bug, need to trim better if(d0>dmax) { dmax=d0; trimP=sol0.get(j); } } if(trimP.valid){ static_cast<RS_AtomicEntity*>(pnew->entityAt(previousIndex))->trimEndpoint(trimP); static_cast<RS_AtomicEntity*>(pnew->entityAt(i))->trimStartpoint(trimP); vp=pnew->entityAt(previousIndex)->getMiddlePoint(); }else{ vp=pnew->entityAt(previousIndex)->getEndpoint(); vp.rotate(entityAt(previousIndex)->getEndpoint(),entityAt(i)->getDirection1()-entityAt(previousIndex)->getDirection2()+M_PI); } pnew->entityAt(i)->offset(vp,distance); previousIndex=i; } //trim //connect and trim RS_Modification m(*container, graphicView); for(i=0;i<length-1;i++){ RS_VectorSolutions sol0=RS_Information::getIntersection(pnew->entityAt(i),pnew->entityAt(i+1),true); if(sol0.getNumber()==0) { sol0=RS_Information::getIntersection(pnew->entityAt(i),pnew->entityAt(i+1)); // RS_Vector vp0(pnew->entityAt(i)->getEndpoint()); // RS_Vector vp1(pnew->entityAt(i+1)->getStartpoint()); // double a0(intersections.at(i).angleTo(vp0)); // double a1(intersections.at(i).angleTo(vp1)); RS_VectorSolutions sol1; for(int j=0;j<sol0.getNumber();j++){ if(RS_Math::isAngleBetween(intersections.at(i).angleTo(sol0.get(j)), pnew->entityAt(i)->getDirection2(), pnew->entityAt(i+1)->getDirection1(), false)==false){ sol1.push_back(sol0.get(j)); } } if(sol1.getNumber()==0) continue; RS_Vector trimP(sol1.getClosest(intersections.at(i))); static_cast<RS_AtomicEntity*>(pnew->entityAt(i))->trimEndpoint(trimP); static_cast<RS_AtomicEntity*>(pnew->entityAt(i+1))->trimStartpoint(trimP); }else{ RS_Vector trimP(sol0.getClosest(pnew->entityAt(i)->getStartpoint())); static_cast<RS_AtomicEntity*>(pnew->entityAt(i))->trimEndpoint(trimP); static_cast<RS_AtomicEntity*>(pnew->entityAt(i+1))->trimStartpoint(trimP); } } *this = *pnew; return true; }
void ecs::BaseSystem::entityRemoved(ecs::EntityID entityID) { if(satisfies(entityID)) { entities_.erase(findEntity(entityID)); } }
const std::pair<bool, std::unique_ptr<ComponentCollection>>& EntityManager::findEntity(Entity entity) const { return findEntity(*this, entity); }
ComponentCollection& EntityManager::getEntity(Entity entity) const { auto&[_, components] = findEntity(entity); return *components; }
void EntityManager::enableEntity(Entity entity, bool enable) { std::get<0>(findEntity(entity)) = enable; }
bool EntityManager::isEntityEnabled(Entity entity) const { const auto&[enabled, _] = findEntity(entity); return enabled; }