Skip to content

Text: implement IDraggable#1616

Merged
swharden merged 8 commits intoScottPlot:masterfrom
BambOoxX:text-draggable
Feb 2, 2022
Merged

Text: implement IDraggable#1616
swharden merged 8 commits intoScottPlot:masterfrom
BambOoxX:text-draggable

Conversation

@BambOoxX
Copy link
Contributor

@BambOoxX BambOoxX commented Jan 29, 2022

This PR implements drag functionality for Text plottables.

The current isUnderMouse test fails, but that seems internal to GDI.

Another implementation, not pushed though, works fine using this test
https://math.stackexchange.com/questions/190111/how-to-check-if-a-point-is-inside-a-rectangle
image

This PR also contains a patch for GetCoordinateY in 650f60e EDIT: moved to #1625/#1626

- `Text` now supports `IDraggable` interface
- `RectangleUnits` should hold the bounding box rectangle around the text in unit dimensions
- The `DeltaCX` and `DeltaCY` properties are used to hold the offset between the reference corner of the bounding box and the actual position of the mouse so that the Text does not *jump* during drag
- The current `isUnderMouse` test using `RectangleF.Contains` fails though the coordinates are actually inside the rechangle.
Any ideas @swharden ?
@swharden
Copy link
Member

swharden commented Feb 1, 2022

@BambOoxX thank you so much for identifying and fixing the error PlotDimensions.GetCoordinateY()! I implemented your important fix in a separate issue/PR #1625/#1626, added regression tests to ensure it doesn't break in the future, and merged those changes back into this PR.

Note that I'm working toward a soft feature freeze #1624 to let me focus on some deep refactoring of this library (namely #1036), but that I'll do my best to devote good time to this PR and the other existing open issues over the next few days. Thanks again for all your work on this! 👍

@swharden
Copy link
Member

swharden commented Feb 1, 2022

The current isUnderMouse test fails, but that seems internal to GDI.

Since ScottPlot 5 will not use GDI or System.Drawing (#1036) I was motivated to figure-out how to implement hit detection on arbitrary rotated rectangles.

Another implementation, not pushed though, works fine using this test

It sounds like I may have duplicate some of your work here, but I made a little test application to demonstrate the effect

point-inside-rotated-rectangle

https://github.com/swharden/Csharp-Data-Visualization/blob/203e024253a2545fc325d1f68d2861a1b9fac74d/projects/rotated-rectangle-intersection/Form1.cs#L98-L134

... I'll put this down for the night, but work on this PR more tomorrow 👍

@swharden
Copy link
Member

swharden commented Feb 2, 2022

After hours of debugging I figured-out the problem was because the coordinate rectangle had a negative height. Swapping the Y values used for the top and bottom of the rectangle fixed the problem, and draggable functionality worked beautifully.

Thanks again for all your help on this @BambOoxX!

I even got a blog post out of the deal 😎 https://swharden.com/blog/2022-02-01-point-in-rectangle/

@swharden swharden changed the title Text draggable Text: implement IDraggable Feb 2, 2022
@swharden swharden enabled auto-merge February 2, 2022 00:44
@swharden swharden merged commit a60f42b into ScottPlot:master Feb 2, 2022
@swharden swharden mentioned this pull request Feb 2, 2022
@BambOoxX BambOoxX deleted the text-draggable branch February 2, 2022 06:57
@BambOoxX
Copy link
Contributor Author

BambOoxX commented Feb 2, 2022

@swharden Nice work finding the bug ! I saw the triangle surface method, but I think the scalar projection method is much more elegant. Of course for a single rectangle that should not make much difference, but this way you only compute 3 distances and at most 4 scalar products. I will try to implement this when I get some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants