From 18ecd174a8517020d2cd8fef462179f34e93b679 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Fri, 25 Dec 2020 07:51:36 +0100 Subject: [PATCH] Sketcher: make Sketch::calculateNormalAtPoint const --- src/Mod/Sketcher/App/Sketch.cpp | 11 +++++++++-- src/Mod/Sketcher/App/Sketch.h | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 0a3fe6a213..645ee33621 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -1427,6 +1427,13 @@ GCS::Curve* Sketch::getGCSCurveByGeoId(int geoId) }; } +const GCS::Curve* Sketch::getGCSCurveByGeoId(int geoId) const +{ + // I hereby guarantee that if I modify the non-const version, I will still + // never modify (this). I return const copy to enforce on my users. + return const_cast(this)->getGCSCurveByGeoId(geoId); +} + // constraint adding ========================================================== int Sketch::addConstraint(const Constraint *constraint) @@ -3177,7 +3184,7 @@ double Sketch::calculateAngleViaPoint(int geoId1, int geoId2, double px, double return GCSsys.calculateAngleViaPoint(*crv1, *crv2, p); } -Base::Vector3d Sketch::calculateNormalAtPoint(int geoIdCurve, double px, double py) +Base::Vector3d Sketch::calculateNormalAtPoint(int geoIdCurve, double px, double py) const { geoIdCurve = checkGeoId(geoIdCurve); @@ -3186,7 +3193,7 @@ Base::Vector3d Sketch::calculateNormalAtPoint(int geoIdCurve, double px, double p.y = &py; //check pointers - GCS::Curve* crv = getGCSCurveByGeoId(geoIdCurve); + const GCS::Curve* crv = getGCSCurveByGeoId(geoIdCurve); if (!crv) { throw Base::ValueError("calculateNormalAtPoint: getGCSCurveByGeoId returned NULL!\n"); } diff --git a/src/Mod/Sketcher/App/Sketch.h b/src/Mod/Sketcher/App/Sketch.h index 8448935830..3babff3a9a 100644 --- a/src/Mod/Sketcher/App/Sketch.h +++ b/src/Mod/Sketcher/App/Sketch.h @@ -356,7 +356,7 @@ public: double calculateAngleViaPoint(int geoId1, int geoId2, double px, double py ); //This is to be used for rendering of angle-via-point constraint. - Base::Vector3d calculateNormalAtPoint(int geoIdCurve, double px, double py); + Base::Vector3d calculateNormalAtPoint(int geoIdCurve, double px, double py) const; //icstr should be the value returned by addXXXXConstraint //see more info in respective function in GCS. @@ -485,6 +485,7 @@ private: /// checks if the index bounds and converts negative indices to positive int checkGeoId(int geoId) const; GCS::Curve* getGCSCurveByGeoId(int geoId); + const GCS::Curve* getGCSCurveByGeoId(int geoId) const; }; } //namespace Part