-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Canvas): provide correctly named canvas pointer methods. BREAKING: rm _normalizePointer
, restorePointerVpt
#9175
Conversation
Build Stats
|
not a single test to account for
_normalizePointer
, restorePointerVpt
getPointer
bug, rm _normalizePointer
, restorePointerVpt
getPointer
bug, rm _normalizePointer
, restorePointerVpt
getPointer
usage bugs, rm _normalizePointer
, restorePointerVpt
f2766a6
to
065ad0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG that slipped under the radar
@jiayihu could this be the reason for the very strange outputs in tests?
src/canvas/Canvas.ts
Outdated
pointer: this.getHTMLPointFromEvent(e), | ||
absolutePointer: this.getCanvasPointFromEvent(e), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an example of the bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/canvas/SelectableCanvas.ts
Outdated
// http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u32.html | ||
// http://idav.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link are DEAD
src/canvas/SelectableCanvas.ts
Outdated
? sendPointToPlane( | ||
pointer, | ||
invertTransform(this.viewportTransform), | ||
objToCheck.group.calcTransformMatrix() | ||
) | ||
: pointer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look at this
sending a pointer in the canvas/object plane if under group or sending a pointer in the HTML plane if not
BUG BUG BUG
I remembered when rewriting group I could not grasp containsPoint
, now I do. A complete mess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How the bug manifest? The fact that the code is not your liking doesn't mean is bugged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does.
The method accepts points in different cases, under group with viewportTransform removed from the point and if not under group then the point in the html plane.
If that is not a bug in design I do not now what a bug is.
I do not plan to touch this because #8767 fixed that and I am tired of getting back to things I fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bug because I can't use containsPoint, no one can without copying this code because it makes no sense
065ad0c
to
d201b34
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asturur this is critical before v6
I imagine we should add tests
Yes, tests for something so important should be there. This is the base of many interactions an application can build on top of the canvas. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the sanpshot show clearly we need to expose a method that prepares the event data for consistency
bc9971b
to
e384006
Compare
leanup Update eventData.test.ts
e384006
to
0b47e20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event data is TESTED
This PR can merge
Please add a description showcase of the bug. What the bug was? how did you find it? |
src/canvas/SelectableCanvas.ts
Outdated
* the same plane as the plane {@link FabricObject#getCenterPoint} exists in | ||
* @return {Point} | ||
*/ | ||
protected getPointer(e: TPointerEvent, inHTMLPlane = false): Point { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please restore getPointer as normal method, we are not adding another migration headache to devs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean remove the protected keyword?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that.
As I see it it is a present for the dev.
TS will warn them about it. Then they can read the comment and decide if to change it or not. It is not a must. But it might help devs when debugging a hard bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from saving the devs, having it protected saves fabric devs - I care about that a lot.
But it is not a must if you disapprove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can let it public and deprecated and later it will be protected with an internal name. we can't remove it now, i think i have hundreds of getPointer usage and so have others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very well
renamed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed, rm transformPointRelativeToCanvas
which is related to this mess
abfe8f3
to
a6c96e0
Compare
a6c96e0
to
6e3a2b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems ready apart for the useless tests
@@ -855,7 +855,7 @@ export class Canvas extends SelectableCanvas implements CanvasOptions { | |||
transform.target, | |||
originalControl | |||
); | |||
pointer = pointer || this.getPointer(e); | |||
pointer = pointer || this.getScenePoint(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems redundant since we cache getScenePoint
src/canvas/Canvas.ts
Outdated
// this is an absolute pointer, the naming is wrong | ||
const pointer = this.getPointer(e); | ||
const pointer = this.getScenePoint(e); | ||
this.freeDrawingBrush && | ||
this.freeDrawingBrush.onMouseDown(pointer, { e, pointer }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should rename this as well when doing the absolutePointer rename
this._pointer = this.getViewportPoint(e); | ||
this._absolutePointer = sendPointToPlane( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also these should be renamed and maybe put into an object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test does not seem very useful
and now I pushed a regression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test should pass now
obj.containsPoint( | ||
sendPointToPlane(pointer, undefined, this.viewportTransform), | ||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep this in mind for conflict resolution with #9395
ok i m merging. |
/** | ||
* @deprecated | ||
* use viewportPoint instead. | ||
* Kept for compatibility | ||
*/ | ||
pointer: Point; | ||
/** | ||
* @deprecated | ||
* use scenePoint instead. | ||
* Kept for compatibility | ||
*/ | ||
absolutePointer: Point; | ||
scenePoint: Point; | ||
viewportPoint: Point; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the order is confusing
should have been
pointer,
absolutePointer,
viewportPoint,
scenePoint
OR
pointer,
viewportPoint,
absolutePointer,
scenePoint
It might seem petty or insignificant but IMO it isn't
A dev reading this code will be confused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot the brushes
const getEventPoints = (canvas: Canvas, e: TPointerEvent) => { | ||
const viewportPoint = canvas.getViewportPoint(e); | ||
const scenePoint = canvas.getScenePoint(e); | ||
return { | ||
viewportPoint, | ||
scenePoint, | ||
pointer: viewportPoint, | ||
absolutePointer: scenePoint, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is anotherthing I have been thinking of lately
Since we cache the points an event can do
scenePoint.x += 5
And cause a bug all across fabric so we should return a clone
I will PR
#9483 has some jsdocs fixes including what you pointed out |
Motivation
This PR adds 2 new methods to get a point from a mouse event and tries to remove the confusion about pointer and absolutePointer.
After much discussion we ended up renaming:
-scenePoint (before absolutePointer) a point that is the fabricCanvas plane, the one in which you measure object.top and object.left of an object added in the canvas.
-viewportPoint (before pointer) a point in the viewport coordinate, for which the point 0,0 is the top left corner of the canvas container, while canvas.width, canvas.height is the bottom right corner of the canvas container ( because of retina scaling i avoid on purpose of talking about the HTMLCanvasElement )
canvas.getPointer(event, ignoreVpt)
becomescanvas.getPointer(event, fromViewport)
and becomes deprecated, will be moved to protected or private next major version.Developers are directed to use:
canvas.getViewportPoint(event)
forcanvas.getPointer(event, true)
and
canvas.getScenePoint(event)
forcanvas.getPointer(event, false)
All the events that were emitted with pointer and absolutePointer still are doing so, those event properties are deprecated and the new
scenePoint
takes the place of absolutePointer andviewportPoint
takes the place of pointer.restorePointerVpt
has been removed and alsotransformPointRelativeToCanvas
in favor ofsendPointToPlane