Skip to content

Commit

Permalink
arc: move by center
Browse files Browse the repository at this point in the history
  • Loading branch information
dxli committed Dec 17, 2015
1 parent 18f846d commit 0417bdd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
34 changes: 25 additions & 9 deletions librecad/src/lib/engine/rs_arc.cpp
Expand Up @@ -281,7 +281,8 @@ void RS_Arc::calculateBorders() {

RS_VectorSolutions RS_Arc::getRefPoints() const
{
return RS_VectorSolutions({startpoint, endpoint, data.center});
//order: start, end, center
return {startpoint, endpoint, data.center};
}

double RS_Arc::getDirection1() const {
Expand Down Expand Up @@ -850,16 +851,31 @@ void RS_Arc::mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2) {



void RS_Arc::moveRef(const RS_Vector& ref, const RS_Vector& offset) {
if(fabs(fabs(getAngleLength()-M_PI)-M_PI)<RS_TOLERANCE_ANGLE){
void RS_Arc::moveRef(const RS_Vector& ref, const RS_Vector& offset)
{
//avoid moving start/end points for full circle arcs
//as start/end points coincident
if (fabs(fabs(getAngleLength()-M_PI)-M_PI) < RS_TOLERANCE_ANGLE){
move(offset);
return;
}
if (ref.distanceTo(startpoint)<1.0e-4) {
moveStartpoint(startpoint+offset);
}else if (ref.distanceTo(endpoint)<1.0e-4) {
moveEndpoint(endpoint+offset);
}
}
auto const refs = getRefPoints();
double dMin;
size_t index;
RS_Vector const vp = refs.getClosest(ref, &dMin, &index);

//reference points must be by the order: start, end, center
switch (index) {
case 0:
moveStartpoint(vp + offset);
return;
case 1:
moveEndpoint(vp + offset);
return;
default:
move(offset);
}

correctAngles(); // make sure angleLength is no more than 2*M_PI
}

Expand Down
2 changes: 1 addition & 1 deletion librecad/src/lib/engine/rs_arc.h
Expand Up @@ -223,7 +223,7 @@ class RS_Arc : public RS_AtomicEntity {
virtual void rotate(const RS_Vector& center, const RS_Vector& angleVector);
virtual void scale(const RS_Vector& center, const RS_Vector& factor);
virtual void mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2);
virtual void moveRef(const RS_Vector& ref, const RS_Vector& offset);
virtual void moveRef(const RS_Vector& ref, const RS_Vector& offset) override;
virtual void stretch(const RS_Vector& firstCorner,
const RS_Vector& secondCorner,
const RS_Vector& offset);
Expand Down

0 comments on commit 0417bdd

Please sign in to comment.