Replies: 6 comments 6 replies
-
Are you using originX and originY in a way that maybe is very useful and if they go missing your project will be hurt? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I support removing originX and originY. I can accept setting the center point as either left, top, or center, center by default, as long as there is a corresponding method to get the other value. For example, if the default center point is center, center and the rotation angle of the shape is a, getLeftTopByAngle(a) should return left, top. Or if the default center point is left, top and the rotation angle of the shape is a, getCenterByAngle(a) should return center, center. I hope that the positioning of elements within the group can support originXByParent and originYByParent. Currently, the coordinates of elements within the group are all based on the center of the group by default. I may need them to be based on the top left corner. 2024-03-18.10.54.50.mov |
Beta Was this translation helpful? Give feedback.
-
Hey @asturur in my implementation of an ObjectContainer (using groups in v5.3) I'm using originX and originY to pin the object to one of the 9 possible positions inside a group. It is a requirement for the platform to support layout positioning. This way when I scale the object (in this case, an image) inside the group, it scales from that position itself. Having originX and originY simplifies the implementation significantly. Do let me know if you have any alternative approaches to handle this without originX and originY Video for reference attached here OriginX.mp4 |
Beta Was this translation helpful? Give feedback.
-
I am for removal. All those LEFT, RIGHT, BOTTOM, TOP are unnecessary overconfiguration, and this behavior can easily be archived by something like setPositionByOrigin when needed. The problem with .left/.top remains but not super important I think. |
Beta Was this translation helpful? Give feedback.
-
Those notes are the base of an evaluation of removing customization of origins for objects in fabricjs in order to possibly reduce complexity of the code and the api.
This idea fits in a long term simplification plan of dropping features of possible low utilization in order to improve maintainability of the code.
Please vote this message with a thumb up if you think is a good idea or a good change, or use the thumb down AND add a message under the second message explaining why you would like to maintain originX and originY
TLDR
remove originX / originY and make everything as if they are set to center/center.
Introduction - What are originX and originY
Origin(x/y) can be one of 3 values or a number. The combination of originX and originY represent which point of the object is associated to the values of the properties left and top.
Today the default values ia left/top and another popular combination is center/center
In the library originX and originY are used a lot for object transforms to find a point in which the object needs to be stable during scaling or rotation, and that is not being touched or changed.
Origins can also be a number when the standards value are not enough, usually between 0 and 1, but i used also origins like -2 and + 3 for cropping controls.
Why do we have OriginX and OriginY
I do not know, they were here in 2014 when i joined, i tried to search the PR history for information but i didn't find much.
Pros of having configurable origins
Cons of having configurable origins
A very common operation is calculating the center of the object, because we draw based on the center. When the origin is set on left/top it means that the position we have is at the extremity of the bounding box, including stroke, strokeUniform and scaling and rotation. As a consequence every time we want to calculate the center (every render every object multiple times ) we go through the necessary calculations. If the origin were set to center/center, all those calculations are equivalent to just taking left/top property and consider it as the center.
What happen if we remove it
If we remove originX and originY from an object, the following side effects are expected:
Import of old design is possibly broken and need an updater
Possible plan of action
We open a PR and we start deleting and following typescript we identify all the places where origins are in play.
In those places we keep the code working as the value of origin was center/center.
getRelativeCenterPoint
becomes () => new Point(this.left, this.top);between
translateToOriginPoint
andgetPointByOrigin
only one survives and probably gets renamedtranslateToCenterPoint
is probably removed_getLeftTopCoords
is probably removedThe
ObjectOrigin
class goes away and gets merged in the nearest class ( with time things have been moved/removed and now is small enough that with this final change maybe it doesn’t make sense anymore ).An updater needs to be created so old designs do not break, details of how you use it are TBD.
Can be enforced on every operation and unremovable or optionally included, the option that is less painful for the developer that will have to migrate.
The issue with top and left properties
If we assume that the origins are center based, because is the easiest for calculation and the most neutral for objects, at this point top and left need to be renamed.
That is very destructive, so we need to add probably deprecated getters and setters for that that will set 2 new properties that will replace left/top ( x,y / position: Point, others... ). That shouldn’t happen in the same pr and it should probably not go extensively on all the codebase, maybe we do it where it matters and we iterate.
When this happens we need to increment the major version by 1.
Beta Was this translation helpful? Give feedback.
All reactions