Skip to content

Add ability to select 3 faces#1258

Merged
phkahler merged 5 commits intosolvespace:masterfrom
phkahler:three-faces
Jan 2, 2023
Merged

Add ability to select 3 faces#1258
phkahler merged 5 commits intosolvespace:masterfrom
phkahler:three-faces

Conversation

@phkahler
Copy link
Member

This allows the user to select 3 faces vs the old limit of 2. I would like to allow constraining a point to more than one face at a time, and 3 would be the maximum. This is a prerequisite to that.

The remaining problem is that the 3rd selected face is not shown as selected. The selection code indicates that the limit of 2 was for rendering performance reasons, which may or may not be a problem today. I'm not sure where the relevant rendering code is to show the selected faces. Help would be appreciated but this is a low priority. Might be a good way for someone to dig into more obscure parts of the code.

@ruevs ruevs marked this pull request as draft June 22, 2022 08:13
@phkahler
Copy link
Member Author

phkahler commented Jul 5, 2022

@Evil-Spirit do you know where/how selected faces get rendered vs not-selected?

@ruevs
Copy link
Member

ruevs commented Jul 8, 2022

@phkahler there you go ;-)

How would the "point on three faces" constraint be stored? A completely new type?

We should not merge this before it can do something useful - it would be rather confusing.

@phkahler
Copy link
Member Author

phkahler commented Jul 8, 2022

@phkahler there you go ;-)

How would the "point on three faces" constraint be stored? A completely new type?

No. We shall create 3 point-on-face constraints. I've been pondering how to do the variadic constraints request and looking at the neglected PR on the topic.

I'm not sure why whitequark didnt accept it. It isnt really conforming to the style, nor is the existing style really great. I think creating multiple constraints inline would be fine in most cases vs creating a list of them.

@ruevs
Copy link
Member

ruevs commented Jul 9, 2022

OK understood - select a point and one to three faces; hit O - get one to thee constraints automatically generated. Makes sense. Of course then there would be three constraints to delete but that could legitimately be called a feature.

In the meantime the face selection code was too ugly for me - I cleaned it up a bit.

...variadic constraints request and looking at the neglected PR on the topic.
I'm not sure why whitequark didnt accept it.

There are two PR-s on the topic #530 and #836 which one are you pondering? ;-)

@ruevs ruevs force-pushed the three-faces branch 3 times, most recently from 82a1279 to 2a78431 Compare July 9, 2022 00:33
@ruevs ruevs removed the help wanted label Jul 9, 2022
@phkahler
Copy link
Member Author

I'd like to just merge it now.

There are two PR-s on the topic #530 and #836 which one are you pondering? ;-)

Well, #530 is a little odd in making a list and then creating them all at once. #836 was designed for a specific use-case and assumes pairs of things to constrain (not what we want) but I think the style of the code is more in line with how I'd like it. So I was planning to just start rewrite the code for each type of constraint over again. If anyone wants to give that a go, I'm happy to merge PRs for these.

@ruevs
Copy link
Member

ruevs commented Jul 11, 2022

I'd like to just merge it now.

Please don't.

If for no other reason, than for the awful "loop unrolling" in describesreen. And even if we were to merge it, we have to set MAX_SELECTABLE_FACES to 2 until selecting three does something (but then the commit messages make no sense and need to be changed).

In general a lot of code in constraint and describescreen fells like "copy-paste, but not quite" - it annoys me every time I look at it. I've dealt with this pattern in the past and have some ideas. But there is A LOT of code and logic, and thus huge opportunity for regressions in both files. And the test suite covers none of it :-( So it will be a lot of work to plan, refactor and test.

And in my opinion neither #530 nor #836 nor your planned "a point and one to three faces coincident" goes in before such a clean up.

} else if(gs.n == 3 && gs.faces == 3) {
Printf(false, "%FtTHREE PLANE FACES");

Vector n0 = SK.GetEntity(gs.face[0])->FaceGetNormalNum();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is wrong with a for loop?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I "fixed" this in c59e93c

Vector n2 = SK.GetEntity(gs.face[2])->FaceGetNormalNum();
Printf(true, " planeC normal = " PT_AS_NUM, CO(n2));
Vector p2 = SK.GetEntity(gs.face[2])->FaceGetPointNum();
Printf(false, " planeB thru = " PT_AS_STR, COSTR(SK.GetEntity(gs.face[2]), p2));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See, copy-pasta already bit you. (planeB) ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed his in c59e93c

@phkahler
Copy link
Member Author

In general a lot of code in constraint and describescreen fells like "copy-paste, but not quite" - it annoys me every time I look at it.

Agreed, but it is fairly readable. Many areas of solvespace look like this often because the failure to use polymorphism, but I can understand and sometimes appreciate the simplicity of it.

One thought I had on the constraints was to make a table indicating what constraint type could be applied to which combinations of entities, but I haven't really dug into that idea enough to like it or not. That might even simplify the code for dialogs that pop up if you misapply a constraint. The complexity will never go away, so it's a question of how to embody it in code so people can read and understand it.

@phkahler
Copy link
Member Author

phkahler commented Jul 12, 2022

Allowing multiple point-on-plane constraints at once should be simple by modifying this:

            } else if(gs.points == 1 && gs.workplanes == 1 && gs.n == 2) {
                c.type = Type::PT_IN_PLANE;
                c.ptA = gs.point[0];
                c.entityA = gs.entity[0];
            } else if(gs.points == 1 && gs.lineSegments == 1 && gs.n == 2) {

The condition changes to:

            } else if(gs.points == 1 && gs.workplanes > 0 && gs.n == (gs.workplanes+1) ) {

Then just do the body of the condition in a loop over all the workplanes including the "AddConstraint(&c);" line from further down.

Then we either have to add a "break" when done, or move the "AddConstraint(&c);" to all the cases within ON_ENTITY. Neither of those seems desirable, but the other option seems to be to make a list of constraints like PR #530 and loop over them where "AddConstraint()" is called now.

@ruevs I don't see a cleaner way to do this. Please fill me in on what you think it should look like. Maybe @rpavlik can recommend something too, he seems to appreciate clean C++ .

Edit: The code above is in constraint.cpp

@ruevs
Copy link
Member

ruevs commented Jul 12, 2022

Agreed, but it is fairly readable

It is indeed readable. But it is getting... long.

One thought I had on the constraints was to make a table indicating...

A "table" of sorts is what I imagine as well! The complexity will indeed not go away - it will just be encoded in a more... structured... way. If I ever get to it I'll share the results of course.

@phkahler
Copy link
Member Author

phkahler commented Dec 4, 2022

@ruevs I want to push this in. I made a 3.2 milestone and I intend to do variadic constrain equal length and diameter, as well as probably 1-3 point-on-face constraints. However, my local and personal repos on github are quite broken so I want to re-fork and I don't want to lose these changes since they work and are not that big.

@ruevs
Copy link
Member

ruevs commented Dec 5, 2022

@phkahler I rebased on master, fixed the copy-pasta in describescreen.cpp and also pushed the branch to my fork here: https://github.com/ruevs/solvespace/tree/wip_phkahler_three-faces
so it is safe.

If you want I can also push the branch to the main repository, but in my opinion it is unwise to merge it into master- after all one can select three faces but can not do anything with them for now.

P.S. I also pushed to your branch.

@phkahler
Copy link
Member Author

phkahler commented Jan 2, 2023

@ruevs I rebased this on master after merging variadic constraints. Then I added a commit here to allow constraining a point to multiple faces at once. This is very handy for getting a point on a vertex that is a result of boolean operations where no point gets created.

@ruevs
Copy link
Member

ruevs commented Jan 2, 2023

@ruevs I rebased this on master after merging variadic constraints. Then I added a commit here to allow constraining a point to multiple faces at once.

Happy New Year @phkahler. This looks reasonable, but I have not tried it. Tomorrow I'll try to take a look at (and test) this and all the "multi-constraint" changes from the last few days.

@phkahler
Copy link
Member Author

phkahler commented Jan 2, 2023

@ruevs I rebased this on master after merging variadic constraints. Then I added a commit here to allow constraining a point to multiple faces at once.

Happy New Year @phkahler. This looks reasonable, but I have not tried it. Tomorrow I'll try to take a look at (and test) this and all the "multi-constraint" changes from the last few days.

In that case I'll just merge it. I tested it on 2 and 3 faces. Merging multi-constraints broke a bunch of stuff and needed fixing on master. It's slightly messy but I'd rather just do testing with master since it's still changing.

@phkahler phkahler marked this pull request as ready for review January 2, 2023 22:24
@phkahler phkahler changed the title WIP Add ability to select 3 faces Add ability to select 3 faces Jan 2, 2023
@phkahler phkahler merged commit 3833dd0 into solvespace:master Jan 2, 2023
@phkahler phkahler deleted the three-faces branch January 4, 2023 20:08
@ruevs ruevs added the UI label Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants