hlorus / CAD_Sketcher

Constraint-based geometry sketcher for blender
GNU General Public License v3.0
2.58k stars 122 forks source link

Handling redundant constraints #444

Open zevv opened 5 months ago

zevv commented 5 months ago

Every now and then I run into the problem where the solver tells me I have redundant constraints; no constraints are specifically marked, so the only way to solve this for me is to remove them one by one until I find the offending combination.

This is quite cumbersome, and I'm sure I'm doing something wrong here. What's the proper way to handle this situation?

HummerSee451437 commented 5 days ago

I have the same problem. Did you find a solution by any chance?

zevv commented 5 days ago

No, I still remove them one by one until I find the offending combination :)

hlorus commented 5 days ago

We're limited by the capability of the solver which doesn't mark the offending constraints unfortunately. There was a recent addition to avoid creating the same constraints multiple times at least, see: https://github.com/hlorus/CAD_Sketcher/commit/14762356659dfc39cd9386c2dc4b8db169b06b84

zevv commented 5 days ago

Is this something we could bring up with the solvespace people? I don't know a single thing about the CAD sketcher implementation, but I guess it would be a sensible feature for a solver to offer this kind of feedback on a failure.

zevv commented 5 days ago

I just tried Solvespace for the first time, using it is a breeze because I already know how to use CAD sketcher :)

However, Solvespace actually is able to indicate the source of redundant constraints, it tells me to "remove any of these to fix this" and shows a list of the constraints causing the conflict. This suggests that the info is available in solvespace itself, so the question would be how to get that out and propagate it to CAD sketcher, right?

In solvespace the case SolveResult::REDUNDANT_OKAY: is handled and the list of problematic constraints is dumped:

    for(int i = 0; i < g->solved.remove.n; i++) {                          
        hConstraint hc = g->solved.remove[i];                                  
        Constraint *c = SK.constraint.FindByIdNoOops(hc); 
        if(!c) continue;                               

        Printf(false, "%Bp   %Fl%Ll%D%f%h%s%E",
            (i & 1) ? 'd' : 'a',
            c->h.v, (&TextWindow::ScreenSelectConstraint),     
            (&TextWindow::ScreenHoverConstraint),
            c->DescriptionString().c_str());                                      
    }                                                                                

This suggests the required info should be available at this point, but I'm not sure if this is all available through the Python binding of course.

hlorus commented 5 days ago

Solvespace unfortunately doesn't ship python bindings. We're using this python library by realthunder which has some memory improvements but also seems to be pinne to a rather old version of solvespace. The solver does already provide a list of failed constraints (which CAD Sketcher uses and paints in red). Redundant constraints don't seem to be communicated, maybe it was added in a later version of the solver or is just not exposed in the python bi dings we're using. @vespakoen was looking into adding official solvespace python bindings a while back, this would obviously be the perfect solution but i guess his efforts never made it into the trunk. Here's some more info on the topic: https://github.com/hlorus/CAD_Sketcher/pull/320