From 53aa302d8be775fa5b0a63dbcd997804196762b1 Mon Sep 17 00:00:00 2001 From: Jolbas <39026960+Jolbas@users.noreply.github.com> Date: Wed, 29 Mar 2023 07:38:04 +0200 Subject: [PATCH] PartDesign: Return directly if occurrences is 1 In LinearPattern and PolarPattern. Skip all checks if occurrences is 1. Allows Expressions on Length/Angle that evaluates to 0 if Occurrences is 1. Co-Authored-By: 0penBrain <48731257+0penBrain@users.noreply.github.com> --- .../PartDesign/App/FeatureLinearPattern.cpp | 31 ++++++++++--------- .../PartDesign/App/FeaturePolarPattern.cpp | 23 +++++++------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp index a98c5fe7cd..fe862b5099 100644 --- a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp +++ b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp @@ -72,12 +72,16 @@ short LinearPattern::mustExecute() const const std::list LinearPattern::getTransformations(const std::vector) { - double distance = Length.getValue(); - if (distance < Precision::Confusion()) - throw Base::ValueError("Pattern length too small"); int occurrences = Occurrences.getValue(); if (occurrences < 1) throw Base::ValueError("At least one occurrence required"); + + if (occurrences == 1) + return {gp_Trsf()}; + + double distance = Length.getValue(); + if (distance < Precision::Confusion()) + throw Base::ValueError("Pattern length too small"); bool reversed = Reversed.getValue(); App::DocumentObject* refObject = Direction.getValue(); @@ -168,23 +172,20 @@ const std::list LinearPattern::getTransformations(const std::vectorgetLocation().Inverted(); dir.Transform(invObjLoc.Transformation()); - gp_Vec direction(dir.X(), dir.Y(), dir.Z()); - + gp_Vec offset(dir.X(), dir.Y(), dir.Z()); + offset *= distance / (occurrences - 1); if (reversed) - direction.Reverse(); + offset.Reverse(); - // Note: The original feature is NOT included in the list of transformations! Therefore - // we start with occurrence number 1, not number 0 std::list transformations; gp_Trsf trans; - transformations.push_back(trans); // identity transformation + transformations.push_back(trans); - if (occurrences > 1) { - double offset = distance / (occurrences - 1); - for (int i = 1; i < occurrences; i++) { - trans.SetTranslation(direction * i * offset); - transformations.push_back(trans); - } + // Note: The original feature is already included in the list of transformations! + // Therefore we start with occurrence number 1 + for (int i = 1; i < occurrences; i++) { + trans.SetTranslation(offset * i); + transformations.push_back(trans); } return transformations; diff --git a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp index c2d6c0e13f..66f5ad4dfb 100644 --- a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp +++ b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp @@ -73,22 +73,17 @@ short PolarPattern::mustExecute() const const std::list PolarPattern::getTransformations(const std::vector) { - double angle = Angle.getValue(); - double radians = Base::toRadians(angle); - if (radians < Precision::Angular()) - throw Base::ValueError("Pattern angle too small"); int occurrences = Occurrences.getValue(); if (occurrences < 1) throw Base::ValueError("At least one occurrence required"); - // Note: The original feature is NOT included in the list of transformations! Therefore - // we start with occurrence number 1, not number 0 - std::list transformations; - gp_Trsf trans; - transformations.push_back(trans); // identity transformation + if (occurrences == 1) + return {gp_Trsf()}; - if (occurrences < 2) - return transformations; + double angle = Angle.getValue(); + double radians = Base::toRadians(angle); + if (radians < Precision::Angular()) + throw Base::ValueError("Pattern angle too small"); bool reversed = Reversed.getValue(); double offset; @@ -171,6 +166,12 @@ const std::list PolarPattern::getTransformations(const std::vector transformations; + gp_Trsf trans; + transformations.push_back(trans); + + // Note: The original feature is already included in the list of transformations! + // Therefore we start with occurrence number 1 for (int i = 1; i < occurrences; i++) { trans.SetRotation(axis.Axis(), i * offset); transformations.push_back(trans);