//rotation void RS_Solid::rotate(const RS_Vector& center, const double& angle) { RS_Vector angleVector(angle); for (int i=0; i<4; ++i) { data.corner[i].rotate(center, angleVector); } calculateBorders(); }
/** * Constructor. * @param d Polyline data */ RS_Polyline::RS_Polyline(RS_EntityContainer* parent, const RS_PolylineData& d) :RS_EntityContainer(parent), data(d) { closingEntity = NULL; calculateBorders(); }
/** * Constructor. * * @para parent Parent Entity Container. * @para d Common dimension geometrical data. * @para ed Extended geometrical data for angular dimension. */ RS_DimAngular::RS_DimAngular(RS_EntityContainer* parent, const RS_DimensionData& d, const RS_DimAngularData& ed) : RS_Dimension(parent, d), edata(ed) { calculateBorders(); }
/** * Removes an entity from this container and updates the borders of * this entity-container if autoUpdateBorders is true. */ bool RS_EntityContainer::removeEntity(RS_Entity* entity) { bool ret = entities.remove(entity); if (autoUpdateBorders) { calculateBorders(); } return ret; }
/** * Constructor. */ RS_Ellipse::RS_Ellipse(RS_EntityContainer* parent, const RS_EllipseData& d) :RS_AtomicEntity(parent), data(d) { //calculateEndpoints(); calculateBorders(); }
/** * Constructor. * * @para parent Parent Entity Container. * @para d Common dimension geometrical data. * @para ed Extended geometrical data for diametric dimension. */ RS_DimDiametric::RS_DimDiametric(RS_EntityContainer* parent, const RS_DimensionData& d, const RS_DimDiametricData& ed) : RS_Dimension(parent, d), edata(ed) { calculateBorders(); }
void RS_Ellipse::moveEndpoint(const RS_Vector& pos) { data.angle2 = getEllipseAngle(pos); //data.angle2 = data.center.angleTo(pos); //calculateEndpoints(); correctAngles(); // make sure angleLength is no more than 2*M_PI calculateBorders(); }
/** * Implementation of update. Updates the arrow. */ void RS_Leader::update() { // find and delete arrow: for(auto e: entities){ if (e->rtti()==RS2::EntitySolid) { removeEntity(e); break; } } if (isUndone()) { return; } RS_Entity* fe = firstEntity(); if (fe && fe->isAtomic()) { RS_Vector p1 = ((RS_AtomicEntity*)fe)->getStartpoint(); RS_Vector p2 = ((RS_AtomicEntity*)fe)->getEndpoint(); // first entity must be the line which gets the arrow: if (hasArrowHead()) { RS_Solid* s = new RS_Solid(this, RS_SolidData()); s->shapeArrow(p1, p2.angleTo(p1), getGraphicVariableDouble("$DIMASZ", 2.5)* getGraphicVariableDouble("$DIMSCALE", 1.0)); s->setPen(RS_Pen(RS2::FlagInvalid)); s->setLayer(nullptr); RS_EntityContainer::addEntity(s); } } calculateBorders(); }
/** * Constructor. */ RS_Image::RS_Image(RS_EntityContainer* parent, const RS_ImageData& d) :RS_AtomicEntity(parent), data(d) { update(); calculateBorders(); }
/** * Constructor. * * @para parent Parent Entity Container. * @para d Common dimension geometrical data. * @para ed Extended geometrical data for aligned dimension. */ RS_DimAligned::RS_DimAligned(RS_EntityContainer* parent, const RS_DimensionData& d, const RS_DimAlignedData& ed) : RS_Dimension(parent, d), edata(ed) { calculateBorders(); }
void RS_Image::rotate(const RS_Vector& center, const double& angle) { RS_Vector angleVector(angle); data.insertionPoint.rotate(center, angleVector); data.uVector.rotate(angleVector); data.vVector.rotate(angleVector); calculateBorders(); }
void RS_Image::updateData(RS_Vector size, RS_Vector Uv, RS_Vector Vv) { data.size = size; data.uVector = Uv; data.vVector = Vv; update(); calculateBorders(); }
/** * Constructor. */ RS_Line::RS_Line(RS_EntityContainer* parent, const RS_LineData& d) :RS_AtomicEntity(parent), data(d), division(1), point_set(false) { calculateBorders(); initLabel(); }
/** * Creates an arc from its startpoint, endpoint and bulge. */ bool RS_Arc::createFrom2PBulge(const RS_Vector& startPoint, const RS_Vector& endPoint, double bulge) { data.reversed = (bulge<0.0); double alpha = atan(bulge)*4.0; RS_Vector middle = (startPoint+endPoint)/2.0; double dist = startPoint.distanceTo(endPoint)/2.0; // alpha can't be 0.0 at this point data.radius = fabs(dist / sin(alpha/2.0)); double wu = fabs(RS_Math::pow(data.radius, 2.0) - RS_Math::pow(dist, 2.0)); double h = sqrt(wu); double angle = startPoint.angleTo(endPoint); if (bulge>0.0) { angle+=M_PI/2.0; } else { angle-=M_PI/2.0; } if (fabs(alpha)>M_PI) { h*=-1.0; } data.center.setPolar(h, angle); data.center+=middle; data.angle1 = data.center.angleTo(startPoint); data.angle2 = data.center.angleTo(endPoint); calculateEndpoints(); calculateBorders(); return true; }
/* Dongxu Li's Version, 19 Aug 2011 * scale an ellipse * Find the eigen vactors and eigen values by optimization * original ellipse equation, * x= a cos t * y= b sin t * rotated by angle, * * x = a cos t cos (angle) - b sin t sin(angle) * y = a cos t sin (angle) + b sin t cos(angle) * scaled by ( kx, ky), * x *= kx * y *= ky * find the maximum and minimum of x^2 + y^2, */ void RS_Ellipse::scale(RS_Vector center, RS_Vector factor) { data.center.scale(center, factor); RS_Vector vpStart=getStartpoint().scale(getCenter(),factor); RS_Vector vpEnd=getEndpoint().scale(getCenter(),factor);; double ct=cos(getAngle()); double ct2 = ct*ct; // cos^2 angle double st=sin(getAngle()); double st2=1.0 - ct2; // sin^2 angle double kx2= factor.x * factor.x; double ky2= factor.y * factor.y; double a=getMajorRadius(); double b=getMinorRadius(); double cA=0.5*a*a*(kx2*ct2+ky2*st2); double cB=0.5*b*b*(kx2*st2+ky2*ct2); double cC=a*b*ct*st*(ky2-kx2); RS_Vector vp(cA-cB,cC); setMajorP(RS_Vector(a,b).scale(RS_Vector(vp.angle())).rotate(RS_Vector(ct,st)).scale(factor)); a=cA+cB; b=vp.magnitude(); setRatio( sqrt((a - b)/(a + b) )); if( std::isnormal(getAngle1()) || std::isnormal(getAngle2() ) ) { //only reset start/end points for ellipse arcs, i.e., angle1 angle2 are not both zero setAngle1(getEllipseAngle(vpStart)); setAngle2(getEllipseAngle(vpEnd)); } correctAngles();//avoid extra 2.*M_PI in angles //calculateEndpoints(); calculateBorders(); }
/** * Creates an arc from its startpoint, endpoint, start direction (angle) * and radius. * * @retval true Successfully created arc * @retval false Cannot creats arc (radius to small or endpoint to far away) */ bool RS_Arc::createFrom2PDirectionRadius(const RS_Vector& startPoint, const RS_Vector& endPoint, double direction1, double radius) { RS_Vector ortho; ortho.setPolar(radius, direction1 + M_PI/2.0); RS_Vector center1 = startPoint + ortho; RS_Vector center2 = startPoint - ortho; if (center1.distanceTo(endPoint) < center2.distanceTo(endPoint)) { data.center = center1; } else { data.center = center2; } data.radius = radius; data.angle1 = data.center.angleTo(startPoint); data.angle2 = data.center.angleTo(endPoint); data.reversed = false; double diff = RS_Math::correctAngle(getDirection1()-direction1); if (fabs(diff-M_PI)<1.0e-1) { data.reversed = true; } calculateEndpoints(); calculateBorders(); return true; }
/** * Default constructor. */ RS_Solid::RS_Solid(RS_EntityContainer* parent, const RS_SolidData& d) : RS_AtomicEntity(parent), data(d) { calculateBorders(); }
void RS_Image::mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2) { data.insertionPoint.mirror(axisPoint1, axisPoint2); RS_Vector vp0(0.,0.); RS_Vector vp1( axisPoint2-axisPoint1 ); data.uVector.mirror(vp0,vp1); data.vVector.mirror(vp0,vp1); calculateBorders(); }
void RS_Arc::reverse() { double a = data.angle1; data.angle1 = data.angle2; data.angle2 = a; data.reversed = !data.reversed; calculateEndpoints(); calculateBorders(); }
void RS_Arc::rotate(RS_Vector center, double angle) { RS_DEBUG->print("RS_Arc::rotate"); data.center.rotate(center, angle); data.angle1 = RS_Math::correctAngle(data.angle1+angle); data.angle2 = RS_Math::correctAngle(data.angle2+angle); calculateEndpoints(); calculateBorders(); RS_DEBUG->print("RS_Arc::rotate: OK"); }
/** * Constructor. * @param d Polyline data */ RS_Polyline::RS_Polyline(RS_EntityContainer* parent, const RS_PolylineData& d) :RS_EntityContainer(parent, true) ,data(d) ,closingEntity(nullptr) ,nextBulge(0.) { calculateBorders(); }
void RS_EntityContainer::rotate(const RS_Vector& center, const RS_Vector& angleVector) { for(auto e: entities){ e->rotate(center, angleVector); } if (autoUpdateBorders) { calculateBorders(); } }
void RS_EntityContainer::move(RS_Vector offset) { for (RS_Entity* e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone)) { e->move(offset); } if (autoUpdateBorders) { calculateBorders(); } }
void RS_EntityContainer::rotate(RS_Vector center, double angle) { for (RS_Entity* e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone)) { e->rotate(center, angle); } if (autoUpdateBorders) { calculateBorders(); } }
void RS_Line::scale(const RS_Vector& center, const RS_Vector& factor) { // RS_DEBUG->print("RS_Line::scale1: sp: %f/%f, ep: %f/%f", // data.startpoint.x, data.startpoint.y, // data.endpoint.x, data.endpoint.y); data.startpoint.scale(center, factor); data.endpoint.scale(center, factor); // RS_DEBUG->print("RS_Line::scale2: sp: %f/%f, ep: %f/%f", // data.startpoint.x, data.startpoint.y, // data.endpoint.x, data.endpoint.y); calculateBorders(); }
void RS_Polyline::moveRef(const RS_Vector& ref, const RS_Vector& offset) { RS_EntityContainer::moveRef(ref, offset); if (ref.distanceTo(data.startpoint)<1.0e-4) { data.startpoint.move(offset); } if (ref.distanceTo(data.endpoint)<1.0e-4) { data.endpoint.move(offset); } calculateBorders(); //update(); }
void RS_Line::scale(RS_Vector center, RS_Vector factor) { RS_DEBUG->print("RS_Line::scale1: sp: %f/%f, ep: %f/%f", data.startpoint.x, data.startpoint.y, data.endpoint.x, data.endpoint.y); data.startpoint.scale(center, factor); data.endpoint.scale(center, factor); RS_DEBUG->print("RS_Line::scale2: sp: %f/%f, ep: %f/%f", data.startpoint.x, data.startpoint.y, data.endpoint.x, data.endpoint.y); calculateBorders(); }
void RS_EntityContainer::moveSelectedRef(const RS_Vector& ref, const RS_Vector& offset) { for(auto e: entities){ e->moveSelectedRef(ref, offset); } if (autoUpdateBorders) { calculateBorders(); } }
void RS_EntityContainer::scale(const RS_Vector& center, const RS_Vector& factor) { if (fabs(factor.x)>RS_TOLERANCE && fabs(factor.y)>RS_TOLERANCE) { for(auto e: entities){ e->scale(center, factor); } } if (autoUpdateBorders) { calculateBorders(); } }
void RS_EntityContainer::moveSelectedRef(const RS_Vector& ref, const RS_Vector& offset) { for (RS_Entity* e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone)) { e->moveSelectedRef(ref, offset); } if (autoUpdateBorders) { calculateBorders(); } }