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>
This commit is contained in:
Jolbas
2023-03-29 07:38:04 +02:00
committed by 0penBrain
parent 99644ac5e7
commit 53aa302d8b
2 changed files with 28 additions and 26 deletions

View File

@@ -73,22 +73,17 @@ short PolarPattern::mustExecute() const
const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App::DocumentObject*>)
{
double angle = Angle.getValue();
double radians = Base::toRadians<double>(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<gp_Trsf> 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<double>(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<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
if (reversed)
axis.SetDirection(axis.Direction().Reversed());
std::list<gp_Trsf> 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);