Skip to content

Commit cbcc5f5

Browse files
iscgarphkahler
authored andcommitted
slvs: don't try to initially satisfy unsupported constraints
The current code expects a constraint to only generate a single equation in order to be initially satisfiable. However, some constraints generate more than a single equation, and this hits an assertion. SolveSpace itself only initially satisfies a small subset of constraints, so there is no point in trying to satisfy all types.
1 parent 18fbd99 commit cbcc5f5

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

src/slvs/lib.cpp

+63-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,61 @@ default: SolveSpace::Platform::FatalError("bad entity type " + std::to_string(ty
8282
}
8383
}
8484

85+
static bool Slvs_CanInitiallySatisfy(const ConstraintBase &c) {
86+
switch(c.type) {
87+
case ConstraintBase::Type::CUBIC_LINE_TANGENT:
88+
case ConstraintBase::Type::PARALLEL:
89+
// Can't initially satisfy if not projected onto a workplane
90+
return c.workplane != EntityBase::FREE_IN_3D;
91+
92+
case ConstraintBase::Type::PT_PT_DISTANCE:
93+
case ConstraintBase::Type::PROJ_PT_DISTANCE:
94+
case ConstraintBase::Type::PT_LINE_DISTANCE:
95+
case ConstraintBase::Type::PT_PLANE_DISTANCE:
96+
case ConstraintBase::Type::PT_FACE_DISTANCE:
97+
case ConstraintBase::Type::EQUAL_LENGTH_LINES:
98+
case ConstraintBase::Type::EQ_LEN_PT_LINE_D:
99+
case ConstraintBase::Type::EQ_PT_LN_DISTANCES:
100+
case ConstraintBase::Type::LENGTH_RATIO:
101+
case ConstraintBase::Type::ARC_ARC_LEN_RATIO:
102+
case ConstraintBase::Type::ARC_LINE_LEN_RATIO:
103+
case ConstraintBase::Type::LENGTH_DIFFERENCE:
104+
case ConstraintBase::Type::ARC_ARC_DIFFERENCE:
105+
case ConstraintBase::Type::ARC_LINE_DIFFERENCE:
106+
case ConstraintBase::Type::DIAMETER:
107+
case ConstraintBase::Type::EQUAL_RADIUS:
108+
case ConstraintBase::Type::EQUAL_LINE_ARC_LEN:
109+
case ConstraintBase::Type::PT_IN_PLANE:
110+
case ConstraintBase::Type::PT_ON_FACE:
111+
case ConstraintBase::Type::PT_ON_CIRCLE:
112+
case ConstraintBase::Type::HORIZONTAL:
113+
case ConstraintBase::Type::VERTICAL:
114+
case ConstraintBase::Type::PERPENDICULAR:
115+
case ConstraintBase::Type::ANGLE:
116+
case ConstraintBase::Type::EQUAL_ANGLE:
117+
case ConstraintBase::Type::ARC_LINE_TANGENT:
118+
case ConstraintBase::Type::CURVE_CURVE_TANGENT:
119+
return true;
120+
121+
case ConstraintBase::Type::AT_MIDPOINT:
122+
// Can initially satisfy if between a line segment and a workplane
123+
return c.ptA == EntityBase::NO_ENTITY;
124+
125+
case ConstraintBase::Type::POINTS_COINCIDENT:
126+
case ConstraintBase::Type::PT_ON_LINE:
127+
case ConstraintBase::Type::SYMMETRIC:
128+
case ConstraintBase::Type::SYMMETRIC_HORIZ:
129+
case ConstraintBase::Type::SYMMETRIC_VERT:
130+
case ConstraintBase::Type::SYMMETRIC_LINE:
131+
case ConstraintBase::Type::SAME_ORIENTATION:
132+
case ConstraintBase::Type::WHERE_DRAGGED:
133+
case ConstraintBase::Type::COMMENT:
134+
// Can't initially satisfy these constraints
135+
return false;
136+
}
137+
ssassert(false, "Unexpected constraint type");
138+
}
139+
85140
bool Slvs_IsFreeIn3D(Slvs_Entity e) {
86141
return e.h == SLVS_FREE_IN_3D;
87142
}
@@ -818,7 +873,10 @@ Slvs_SolveResult Slvs_SolveSketch(uint32_t shg, int calculateFaileds = 0)
818873
SYS.param.Add(&p);
819874
}
820875
constraintParams.Clear();
821-
c->ModifyToSatisfy();
876+
877+
if(Slvs_CanInitiallySatisfy(*c)) {
878+
c->ModifyToSatisfy();
879+
}
822880
}
823881
}
824882

@@ -962,7 +1020,10 @@ void Slvs_Solve(Slvs_System *ssys, uint32_t shg)
9621020
SYS.param.Add(&p);
9631021
}
9641022
params.Clear();
965-
c.ModifyToSatisfy();
1023+
1024+
if(Slvs_CanInitiallySatisfy(c)) {
1025+
c.ModifyToSatisfy();
1026+
}
9661027
}
9671028

9681029
SK.constraint.Add(&c);

0 commit comments

Comments
 (0)