Skip to content

Comments

Clipboard fixes#833

Merged
vespakoen merged 1 commit intosolvespace:masterfrom
vespakoen:clipboard-fixes
Dec 22, 2020
Merged

Clipboard fixes#833
vespakoen merged 1 commit intosolvespace:masterfrom
vespakoen:clipboard-fixes

Conversation

@vespakoen
Copy link
Contributor

@vespakoen vespakoen commented Dec 1, 2020

I found some more oddities with paste transformed.

I am hoping I can solve them and am planning to add some new tests for these as well.

The first thing I noticed is that rotating happens in counter clockwise direction (at least in the workplane that is opened by default when starting a new sketch) stupid me, scrap that.

The second thing I noticed is that when flipping an arc with tangent constraints, the arc gets inverted, removing the constraints fixes this, but there should be a better way to actually invert the arc which I haven't found yet.

Here is a little sketch to try out.

rotate-and-flip-me.slvs.zip

@vespakoen vespakoen added the bug label Dec 1, 2020
@ruevs
Copy link
Member

ruevs commented Dec 1, 2020

In math (and physics) positive angles go counter-clockwise from the X+ axis. Please do not change that. Otherwise sin(PI/2) would be -1 ;-)
https://www.physicsforums.com/threads/why-do-trigonometry-angles-go-counter-clockwise.554994/

ruevs
ruevs previously requested changes Dec 1, 2020
@ruevs
Copy link
Member

ruevs commented Dec 1, 2020

The arc one is tough - it's been discussed before, but I can not find where right now...

@phkahler
Copy link
Member

phkahler commented Dec 2, 2020

The trick with arcs is that the end points need to be swapped. You can see code for that in the paste-transformed. The reason is that arcs are defined as counter-clockwise from the start point to the end point. This also why arcs are not created for Revolve extrusions - they were either correct or went the wrong way around depending which way you dragged it.

For the paste you may run into other issues if you swap them as there may be constraints or something that won't be right. An alternative to swapping the end points is to flip the normal. Arcs have a normal and that needs to be copied with a flip. This is the same issue with flipping text entites which I haven't had enough time to look into. Maybe you or I will get them both fixed at once.

BTW what does it mean to flip a normal? It's either scale it by -1 or a member function to flip it... I think... maybe. :-)

@vespakoen
Copy link
Contributor Author

vespakoen commented Dec 2, 2020

I found out that the other and other2 properties influence the arc tangent position.

ARC_LINE_TANGENT only uses the other property as seen here:

Vector l0 = SK.GetEntity(line->point[0])->PointGetNum(),
l1 = SK.GetEntity(line->point[1])->PointGetNum();
Vector a1 = SK.GetEntity(arc->point[1])->PointGetNum(),
a2 = SK.GetEntity(arc->point[2])->PointGetNum();
if(l0.Equals(a1) || l1.Equals(a1)) {
c.other = false;
} else if(l0.Equals(a2) || l1.Equals(a2)) {
c.other = true;
} else {

Swapping that when scale < 0 seems to do the trick.

The same goes for CUBIC_LINE_TANGENT, reference:

Vector l0 = SK.GetEntity(line->point[0])->PointGetNum(),
l1 = SK.GetEntity(line->point[1])->PointGetNum();
Vector as = cubic->CubicGetStartNum(),
af = cubic->CubicGetFinishNum();
if(l0.Equals(as) || l1.Equals(as)) {
c.other = false;
} else if(l0.Equals(af) || l1.Equals(af)) {
c.other = true;
} else {

CURVE_CURVE_TANGENT uses both the other and other2 properties as seen:

Entity *eA = SK.GetEntity(gs.entity[0]),
*eB = SK.GetEntity(gs.entity[1]);
Vector as = eA->EndpointStart(),
af = eA->EndpointFinish(),
bs = eB->EndpointStart(),
bf = eB->EndpointFinish();
if(as.Equals(bs)) {
c.other = false; c.other2 = false;
} else if(as.Equals(bf)) {
c.other = false; c.other2 = true;
} else if(af.Equals(bs)) {
c.other = true; c.other2 = false;
} else if(af.Equals(bf)) {
c.other = true; c.other2 = true;
} else {

Swapping those, and the entities also seems to work, but i'm not sure if it's the right / cleanest solution.

@vespakoen vespakoen marked this pull request as ready for review December 2, 2020 07:57
@vespakoen vespakoen dismissed ruevs’s stale review December 2, 2020 07:58

I reverted the -theta change

@vespakoen
Copy link
Contributor Author

My limited? test: Screenshot 2020-12-02 at 09 08 20

@vespakoen
Copy link
Contributor Author

vespakoen commented Dec 2, 2020

Another improvement? (at least to most of my usecases) I added:

EQUAL_RADIUS, EQUAL_LINE_ARC_LEN and EQUAL_LENGTH_LINES now will link to the "original"

DIAMETER gets changed into a EQUAL_RADIUS constraint with the "original"

So when I paste things now, it will all reference the original copy. I guess this is what we mostly want?
Let me know if I should put this behind a flag somewhere.

EDIT: I removed this feature, it was not working correctly and is probably too much "magic"

Screenshot 2020-12-02 at 10 30 13

@vespakoen
Copy link
Contributor Author

In hindsight I shouldn't have added the last changes to this PR, it's not working 100% correctly and it is probably out of scope of what this PR was trying to achieve in the first place (fixing bugs in the current implementation).

Will update this one soon.

@phkahler
Copy link
Member

phkahler commented Dec 4, 2020

I'm for fixing bugs for 3.0.

After that i was wondering if copy-paste should use the entity copy-as stuff (at the end of group.cpp) so that all the copies will change if the original is changed. This is how copies happen for new groups - like the 2 ends of an extrude. The copies are created by applying one of several transformations to the original. All copies use the same transform parameters so they move together. Maybe that's worth opening a separate issue to discuss?

@vespakoen did you flip the arc normals or fix the tangent constraints? Also, drop a text entity in there ;-)

@ruevs
Copy link
Member

ruevs commented Dec 4, 2020

Copy-paste in my opinion should leave the copies completely independent - and thus independently editable. That is how copy-paste works "everywhere".

On the other hand step translating does almost what you describe. Perhaps something like "clone multiple" which makes N clones but allows them to be moved freeley?

@ruevs
Copy link
Member

ruevs commented Dec 4, 2020

At any rate all of this should be post 3.0

@vespakoen
Copy link
Contributor Author

Reverted the last change, now it only fixes the H / V constraints and tangent problems.

@vespakoen
Copy link
Contributor Author

(So no more dependencies between copies)

It simply:

  • Fixes the direction of CURVE_CURVE_TANGENT, CUBIC_LINE_TANGENT, and ARC_LINE_TANGENT when mirroring
  • Removes HORIZONTAL and VERTICAL constraints when NOT rotating 90 degrees or any multiple of it.

@ruevs I think this can safely be included in 3.0, it's a pretty annoying bug and I think is worth including the fix asap.

Copy link
Member

@ruevs ruevs left a comment

Choose a reason for hiding this comment

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

This does not quite work. It moves the constraints to the "other"/wrong end of the curves sometimes.

@ruevs
Copy link
Member

ruevs commented Dec 9, 2020

This does not quite work. It moves the constraints to the "other"/wrong end of the curves sometimes.
TangentCurvesPateTransformed.zip
TangentCurvesPateTransformed

@ruevs
Copy link
Member

ruevs commented Dec 9, 2020

TangentCurvesPateTransformed2

@ruevs
Copy link
Member

ruevs commented Dec 9, 2020

The constraints between the vertical line and the bezier and the horizontal line and the bezier are swapped.
Clipboard02

@vespakoen
Copy link
Contributor Author

Thanks testing! I'll take another look at this.

@vespakoen
Copy link
Contributor Author

Think I fixed it, works with both of our tests now.

@ruevs
Copy link
Member

ruevs commented Dec 14, 2020

Hmm not quite. Lines tangent to beziers still get "swapped" incorrectly.
pr833_TangentCurvesLinesPasteTransformedBug.zip

ruevs
ruevs previously requested changes Dec 14, 2020
Copy link
Member

@ruevs ruevs left a comment

Choose a reason for hiding this comment

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

Still not correct for two lines tangent at the ends of a bezier.

@vespakoen vespakoen force-pushed the clipboard-fixes branch 2 times, most recently from 21017b6 to 8aa3335 Compare December 14, 2020 22:41
@vespakoen
Copy link
Contributor Author

I guess I found the correct solution, but this duplicates code from constraint.cpp.
There are also calls to "swap" in constraint.cpp of which I am not sure what exactly they do and if those should be taken into account.

I should probably move these into a function that can be called from the clipboard.cpp as well.

@vespakoen
Copy link
Contributor Author

Just moved the duplicated stuff into new functions, seems to work good now, let me know if this is the right way / place of things.

@vespakoen vespakoen requested a review from ruevs December 15, 2020 14:42
@phkahler
Copy link
Member

@vespakoen swap(a,b) literally swaps the "values" two variables of the same type. By values I mean all members, so Vectors will exchange x,y, and z values. For example, line/arc tangent constraint appears to be unsure of which parameter is the arc because they are the same type? So it checks and if the one whose variable name is line happens to be the arc, it swaps line and arc. Why? because one has 2 points and one has 3 plus a normal, so it's important to have them the right way when making the constraint equations.

An example would be mirroring an arc. The entity contains handles to the 2 end points, so the mirror image should mirror all points and then in the arc entity it should swap the handles for the 2 end points to ensure it goes the right way around. Either that or flip the normal.

@vespakoen
Copy link
Contributor Author

@ruevs @phkahler What do you think of the current implementation?
I moved the code that is duplicated into static functions on the Constraint class, I wonder if this is the right place for it though.

@phkahler
Copy link
Member

I think the implementation is fine. You have to try all 3 kinds of constraints you modified code for, both pasted and regularly applied to existing entities. Then I'm happy with it.

@vespakoen
Copy link
Contributor Author

I just did a whole bunch of testing and actually found a problem with my code, but that is now fixed and it is working perfectly now.

I have tested all the changed constraints, in both "directions" of selecting, and also mirrored and pasted, then removed and re-applied constraints.

All is working fine.

@vespakoen vespakoen dismissed ruevs’s stale review December 22, 2020 13:07

This is fixed now

@vespakoen vespakoen merged commit 96958f4 into solvespace:master Dec 22, 2020
@vespakoen vespakoen deleted the clipboard-fixes branch December 22, 2020 14:36
@ruevs
Copy link
Member

ruevs commented Dec 22, 2020

OK now it works for all test I tried. And it looks good. I will do an extra small clean up.

ruevs added a commit to ruevs/solvespace that referenced this pull request Mar 3, 2021
This fixes a regression introduced in  96958f4
(solvespace#833.)
Three `return` statements got "swallowed" by the newly created functions.
(e.g .solvespace@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 solvespace#937.
phkahler pushed a commit that referenced this pull request Mar 6, 2021
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.
ruevs added a commit to ruevs/solvespace that referenced this pull request Nov 6, 2024
…edge

The functions Constraint::
	ConstrainArcLineTangent
	ConstrainCubicLineTangent
	ConstrainCurveCurveTangent
were introduced in 96958f4 in order to
properly paste arcs tangent to other objects when mirrored. See the original
pull request for details solvespace#833
and test files.

However these functions use the original logic in constraint.cpp that
relies on the two entities sharing an end point. This will interfere
implementing tangents on entities without coincident points so I changed
the logic to remove the dependency. As a side benefit it makes it cleaner
and it's intent more obvious.
See solvespace#937
devin-ai-integration bot pushed a commit to erkinalp/solvespace that referenced this pull request Apr 3, 2025
devin-ai-integration bot pushed a commit to erkinalp/solvespace that referenced this pull request Apr 3, 2025
This fixes a regression introduced in  96958f4
(solvespace#833.)
Three `return` statements got "swallowed" by the newly created functions.
(e.g .solvespace@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 solvespace#937.
devin-ai-integration bot pushed a commit to erkinalp/solvespace that referenced this pull request Apr 3, 2025
…edge

The functions Constraint::
	ConstrainArcLineTangent
	ConstrainCubicLineTangent
	ConstrainCurveCurveTangent
were introduced in 96958f4 in order to
properly paste arcs tangent to other objects when mirrored. See the original
pull request for details solvespace#833
and test files.

However these functions use the original logic in constraint.cpp that
relies on the two entities sharing an end point. This will interfere
implementing tangents on entities without coincident points so I changed
the logic to remove the dependency. As a side benefit it makes it cleaner
and it's intent more obvious.
See solvespace#937
dennisyangji pushed a commit to Orthogonalpub/ode_solvespace that referenced this pull request Nov 25, 2025
dennisyangji pushed a commit to Orthogonalpub/ode_solvespace that referenced this pull request Nov 25, 2025
This fixes a regression introduced in  d1906c2
(solvespace#833.)
Three `return` statements got "swallowed" by the newly created functions.
(e.g .solvespace@d1906c2#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 solvespace#937.
dennisyangji pushed a commit to Orthogonalpub/ode_solvespace that referenced this pull request Nov 25, 2025
…edge

The functions Constraint::
	ConstrainArcLineTangent
	ConstrainCubicLineTangent
	ConstrainCurveCurveTangent
were introduced in d1906c2 in order to
properly paste arcs tangent to other objects when mirrored. See the original
pull request for details solvespace#833
and test files.

However these functions use the original logic in constraint.cpp that
relies on the two entities sharing an end point. This will interfere
implementing tangents on entities without coincident points so I changed
the logic to remove the dependency. As a side benefit it makes it cleaner
and it's intent more obvious.
See solvespace#937
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.

3 participants