Skip to content

Commit 8c101d5

Browse files
ruevsphkahler
authored andcommitted
Fix tangent constraints of curves.
This fixes a regression introduced in 96958f4 (#833.) Three `return` statements got "swallowed" by the newly created functions. (e.g .96958f4#diff-49abc03ed071148c0ebae0c64aafb625fa6223135f77aeecdb47dab4cf8b940cL638 ) Because of this it was possible to constrain arcs and cubics tangent to each other or line segments, without them sharing an endpoint. This kind of worked, but always chose the "starting" points of the curves and lines. In the future this can be turned into a feature. See the discussion in #937.
1 parent 697ffdd commit 8c101d5

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/constraint.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ hConstraint Constraint::ConstrainCoincident(hEntity ptA, hEntity ptB) {
127127
Entity::NO_ENTITY, Entity::NO_ENTITY, /*other=*/false, /*other2=*/false);
128128
}
129129

130-
void Constraint::ConstrainArcLineTangent(Constraint *c, Entity *line, Entity *arc) {
130+
bool Constraint::ConstrainArcLineTangent(Constraint *c, Entity *line, Entity *arc) {
131131
Vector l0 = SK.GetEntity(line->point[0])->PointGetNum(),
132132
l1 = SK.GetEntity(line->point[1])->PointGetNum();
133133
Vector a1 = SK.GetEntity(arc->point[1])->PointGetNum(),
@@ -140,11 +140,12 @@ void Constraint::ConstrainArcLineTangent(Constraint *c, Entity *line, Entity *ar
140140
Error(_("The tangent arc and line segment must share an "
141141
"endpoint. Constrain them with Constrain -> "
142142
"On Point before constraining tangent."));
143-
return;
143+
return false;
144144
}
145+
return true;
145146
}
146147

147-
void Constraint::ConstrainCubicLineTangent(Constraint *c, Entity *line, Entity *cubic) {
148+
bool Constraint::ConstrainCubicLineTangent(Constraint *c, Entity *line, Entity *cubic) {
148149
Vector l0 = SK.GetEntity(line->point[0])->PointGetNum(),
149150
l1 = SK.GetEntity(line->point[1])->PointGetNum();
150151
Vector as = cubic->CubicGetStartNum(),
@@ -158,11 +159,12 @@ void Constraint::ConstrainCubicLineTangent(Constraint *c, Entity *line, Entity *
158159
Error(_("The tangent cubic and line segment must share an "
159160
"endpoint. Constrain them with Constrain -> "
160161
"On Point before constraining tangent."));
161-
return;
162+
return false;
162163
}
164+
return true;
163165
}
164166

165-
void Constraint::ConstrainCurveCurveTangent(Constraint *c, Entity *eA, Entity *eB) {
167+
bool Constraint::ConstrainCurveCurveTangent(Constraint *c, Entity *eA, Entity *eB) {
166168
Vector as = eA->EndpointStart(),
167169
af = eA->EndpointFinish(),
168170
bs = eB->EndpointStart(),
@@ -183,8 +185,9 @@ void Constraint::ConstrainCurveCurveTangent(Constraint *c, Entity *eA, Entity *e
183185
Error(_("The curves must share an endpoint. Constrain them "
184186
"with Constrain -> On Point before constraining "
185187
"tangent."));
186-
return;
188+
return false;
187189
}
190+
return true;
188191
}
189192

190193
void Constraint::MenuConstrain(Command id) {
@@ -690,7 +693,9 @@ void Constraint::MenuConstrain(Command id) {
690693
if(line->type == Entity::Type::ARC_OF_CIRCLE) {
691694
swap(line, arc);
692695
}
693-
ConstrainArcLineTangent(&c, line, arc);
696+
if(!ConstrainArcLineTangent(&c, line, arc)) {
697+
return;
698+
}
694699
c.type = Type::ARC_LINE_TANGENT;
695700
c.entityA = arc->h;
696701
c.entityB = line->h;
@@ -700,7 +705,9 @@ void Constraint::MenuConstrain(Command id) {
700705
if(line->type == Entity::Type::CUBIC) {
701706
swap(line, cubic);
702707
}
703-
ConstrainCubicLineTangent(&c, line, cubic);
708+
if(!ConstrainCubicLineTangent(&c, line, cubic)) {
709+
return;
710+
}
704711
c.type = Type::CUBIC_LINE_TANGENT;
705712
c.entityA = cubic->h;
706713
c.entityB = line->h;
@@ -711,7 +718,9 @@ void Constraint::MenuConstrain(Command id) {
711718
}
712719
Entity *eA = SK.GetEntity(gs.entity[0]),
713720
*eB = SK.GetEntity(gs.entity[1]);
714-
ConstrainCurveCurveTangent(&c, eA, eB);
721+
if(!ConstrainCurveCurveTangent(&c, eA, eB)) {
722+
return;
723+
}
715724
c.type = Type::CURVE_CURVE_TANGENT;
716725
c.entityA = eA->h;
717726
c.entityB = eB->h;

src/sketch.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,9 @@ class Constraint : public ConstraintBase {
790790
static hConstraint TryConstrain(Constraint::Type type, hEntity ptA, hEntity ptB,
791791
hEntity entityA, hEntity entityB = Entity::NO_ENTITY,
792792
bool other = false, bool other2 = false);
793-
static void ConstrainArcLineTangent(Constraint *c, Entity *line, Entity *arc);
794-
static void ConstrainCubicLineTangent(Constraint *c, Entity *line, Entity *cubic);
795-
static void ConstrainCurveCurveTangent(Constraint *c, Entity *eA, Entity *eB);
793+
static bool ConstrainArcLineTangent(Constraint *c, Entity *line, Entity *arc);
794+
static bool ConstrainCubicLineTangent(Constraint *c, Entity *line, Entity *cubic);
795+
static bool ConstrainCurveCurveTangent(Constraint *c, Entity *eA, Entity *eB);
796796
};
797797

798798
class hEquation {

0 commit comments

Comments
 (0)