From c0f800615e47396648f975492024a2572ead623b Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sat, 23 Nov 2024 18:39:23 +0530 Subject: [PATCH] [Sketcher] Use `switch`-`case` in `getPointForGeometry()` Minor readability improvement. --- src/Mod/Sketcher/App/SketchObject.cpp | 72 +++++++++++++++++++++------ 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 848d9fdf66..1a30ae4479 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1401,10 +1401,16 @@ Base::Vector3d SketchObject::getPointForGeometry<>(const Part::GeomPoint *geomPo template <> Base::Vector3d SketchObject::getPointForGeometry<>(const Part::GeomLineSegment *lineSeg, PointPos PosId) { - if (PosId == PointPos::start) + switch (PosId) { + case PointPos::start: { return lineSeg->getStartPoint(); - else if (PosId == PointPos::end) + } + case PointPos::end: { return lineSeg->getEndPoint(); + } + default: + break; + } return Base::Vector3d(); } @@ -1429,58 +1435,92 @@ Base::Vector3d SketchObject::getPointForGeometry<>(const Part::GeomEllipse *elli template <> Base::Vector3d SketchObject::getPointForGeometry<>(const Part::GeomArcOfCircle *aoc, PointPos PosId) { - if (PosId == PointPos::start) + switch (PosId) { + case PointPos::start: { return aoc->getStartPoint(/*emulateCCW=*/true); - else if (PosId == PointPos::end) + } + case PointPos::end: { return aoc->getEndPoint(/*emulateCCW=*/true); - else if (PosId == PointPos::mid) + } + case PointPos::mid: { return aoc->getCenter(); + } + default: + break; + } return Base::Vector3d(); } template <> Base::Vector3d SketchObject::getPointForGeometry<>(const Part::GeomArcOfEllipse *aoe, PointPos PosId) { - if (PosId == PointPos::start) + switch (PosId) { + case PointPos::start: { return aoe->getStartPoint(/*emulateCCW=*/true); - else if (PosId == PointPos::end) + } + case PointPos::end: { return aoe->getEndPoint(/*emulateCCW=*/true); - else if (PosId == PointPos::mid) + } + case PointPos::mid: { return aoe->getCenter(); + } + default: + break; + } return Base::Vector3d(); } template <> Base::Vector3d SketchObject::getPointForGeometry<>(const Part::GeomArcOfHyperbola *aoh, PointPos PosId) { - if (PosId == PointPos::start) + switch (PosId) { + case PointPos::start: { return aoh->getStartPoint(); - else if (PosId == PointPos::end) + } + case PointPos::end: { return aoh->getEndPoint(); - else if (PosId == PointPos::mid) + } + case PointPos::mid: { return aoh->getCenter(); + } + default: + break; + } return Base::Vector3d(); } template <> Base::Vector3d SketchObject::getPointForGeometry<>(const Part::GeomArcOfParabola *aop, PointPos PosId) { - if (PosId == PointPos::start) + switch (PosId) { + case PointPos::start: { return aop->getStartPoint(); - else if (PosId == PointPos::end) + } + case PointPos::end: { return aop->getEndPoint(); - else if (PosId == PointPos::mid) + } + case PointPos::mid: { return aop->getCenter(); + } + default: + break; + } return Base::Vector3d(); } template <> Base::Vector3d SketchObject::getPointForGeometry<>(const Part::GeomBSplineCurve *bsp, PointPos PosId) { - if (PosId == PointPos::start) + switch (PosId) { + case PointPos::start: { return bsp->getStartPoint(); - else if (PosId == PointPos::end) + } + case PointPos::end: { return bsp->getEndPoint(); + } + default: + break; + } return Base::Vector3d(); }