diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index 8e63939341..209640b42b 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -829,6 +829,24 @@ void CenterLine::dump(const char* title) Base::Console().Message("CL::dump - %s \n",toString().c_str()); } +std::tuple CenterLine::rotatePointsAroundMid(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d mid, double rotate) { + //rotate p1, p2 about mid + double revRotate = -rotate; + double cosTheta = cos(revRotate * M_PI / 180.0); + double sinTheta = sin(revRotate * M_PI / 180.0); + Base::Vector3d toOrg = p1 - mid; + double xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; + double yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; + Base::Vector3d newp1 = Base::Vector3d(xRot, yRot, 0.0) + mid; + toOrg = p2 - mid; + xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; + yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; + Base::Vector3d newp2 = Base::Vector3d(xRot, yRot, 0.0) + mid; + + return std::make_tuple(newp1, newp2); +} + + //end points for centerline with no geometry reference std::pair CenterLine::calcEndPointsNoRef( Base::Vector3d start, @@ -852,17 +870,7 @@ std::pair CenterLine::calcEndPointsNoRef( //rotate if (!DrawUtil::fpCompare(rotate, 0.0)) { //rotate p1, p2 about mid point - double revRotate = -rotate; - double cosTheta = cos(revRotate * M_PI / 180.0); - double sinTheta = sin(revRotate * M_PI / 180.0); - Base::Vector3d toOrg = p1 - mid; - double xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; - double yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; - p1 = Base::Vector3d(xRot, yRot, 0.0) + mid; - toOrg = p2 - mid; - xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; - yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; - p2 = Base::Vector3d(xRot, yRot, 0.0) + mid; + tie(p1, p2) = rotatePointsAroundMid(p1, p2, mid, rotate); } //shift @@ -958,17 +966,7 @@ std::pair CenterLine::calcEndPoints(DrawViewPart //rotate if (!DrawUtil::fpCompare(rotate, 0.0)) { //rotate p1, p2 about mid point - double revRotate = -rotate; - double cosTheta = cos(revRotate * M_PI / 180.0); - double sinTheta = sin(revRotate * M_PI / 180.0); - Base::Vector3d toOrg = p1 - mid; - double xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; - double yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; - p1 = Base::Vector3d(xRot, yRot, 0.0) + mid; - toOrg = p2 - mid; - xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; - yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; - p2 = Base::Vector3d(xRot, yRot, 0.0) + mid; + tie(p1, p2) = rotatePointsAroundMid(p1, p2, mid, rotate); } //shift @@ -1068,17 +1066,7 @@ std::pair CenterLine::calcEndPoints2Lines(DrawVi //rotate if (!DrawUtil::fpCompare(rotate, 0.0)) { //rotate p1, p2 about mid - double revRotate = -rotate; - double cosTheta = cos(revRotate * M_PI / 180.0); - double sinTheta = sin(revRotate * M_PI / 180.0); - Base::Vector3d toOrg = p1 - mid; - double xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; - double yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; - p1 = Base::Vector3d(xRot, yRot, 0.0) + mid; - toOrg = p2 - mid; - xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; - yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; - p2 = Base::Vector3d(xRot, yRot, 0.0) + mid; + tie(p1, p2) = rotatePointsAroundMid(p1, p2, mid, rotate); } //shift @@ -1167,17 +1155,7 @@ std::pair CenterLine::calcEndPoints2Points(DrawV //rotate if (!DrawUtil::fpCompare(rotate, 0.0)) { //rotate p1, p2 about mid - double revRotate = -rotate; - double cosTheta = cos(revRotate * M_PI / 180.0); - double sinTheta = sin(revRotate * M_PI / 180.0); - Base::Vector3d toOrg = p1 - mid; - double xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; - double yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; - p1 = Base::Vector3d(xRot, yRot, 0.0) + mid; - toOrg = p2 - mid; - xRot = toOrg.x * cosTheta - toOrg.y * sinTheta; - yRot = toOrg.y * cosTheta + toOrg.x * sinTheta; - p2 = Base::Vector3d(xRot, yRot, 0.0) + mid; + tie(p1, p2) = rotatePointsAroundMid(p1, p2, mid, rotate); } //shift diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index 401b9155b6..96d3d54209 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -218,6 +218,11 @@ public: bool flip = false); TechDraw::BaseGeomPtr scaledGeometry(TechDraw::DrawViewPart* partFeat); + static std::tuple rotatePointsAroundMid( + Base::Vector3d p1, + Base::Vector3d p2, + Base::Vector3d mid, + double rotate); static std::pair calcEndPointsNoRef( Base::Vector3d start, Base::Vector3d end,