Skip to content

Commit

Permalink
refactor() BREAKING Remove calculate option from geometry methods (#9483
Browse files Browse the repository at this point in the history
)
  • Loading branch information
asturur committed Nov 12, 2023
1 parent 0cc0f46 commit 3adbb0f
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 171 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- BREAKING: remove calculate true/false from the api. [#9483](https://github.com/fabricjs/fabric.js/pull/9483)
- chore(): remove some Type assertions [#8950](https://github.com/fabricjs/fabric.js/pull/8950)
- chore(): expose `sendVectorToPlane` [#9479](https://github.com/fabricjs/fabric.js/pull/9479)
- BREAKING: remove absolute true/false from the api. [#9395](https://github.com/fabricjs/fabric.js/pull/9395)
Expand Down
7 changes: 4 additions & 3 deletions src/benchmarks/raycasting.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const findCrossPoints = (point, lines) => {
/**
* Method that returns an object with the object edges in it, given the coordinates of the corners
* @private
* @param {Object} lineCoords or aCoords Coordinates of the object corners
* @param {Object} aCoords Coordinates of the object corners
*/
const getImageLines = ({ tl, tr, bl, br }) => {
const lines = {
Expand Down Expand Up @@ -101,8 +101,9 @@ export const cornerPointContainsPoint = (point, cornerPoint) => {
// END OF OLD CODE

class Test1 extends FabricObject {
containsPoint(point, absolute, calculate) {
return cornerPointContainsPoint(point, this._getCoords(calculate));
containsPoint(point) {
const [tl, tr, br, bl] = this.getCoords();
return cornerPointContainsPoint(point, { tl, tr, br, bl });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/canvas/SelectableCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents>
];
// in case of padding we calculate the new coords on the fly.
// otherwise we have to maintain 2 sets of coordinates for everything.
// we can reiterate on storing those on something similar to lineCoords
// we can reiterate on storing them.
// if this is slow, for now the semplification is large and doesn't impact
// rendering.
// the idea behind this is that outside target check we don't need ot know
Expand Down
13 changes: 3 additions & 10 deletions src/canvas/StaticCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,9 @@ export class StaticCanvas<
declare allowTouchScrolling: boolean;

declare viewportTransform: TMat2D;

/**
* Describe canvas element extension over design
* properties are tl,tr,bl,br.
* if canvas is not zoomed/panned those points are the four corner of canvas
* if canvas is viewportTransformed you those points indicate the extension
* of canvas element in plain untrasformed coordinates
* The coordinates get updated with @method calcViewportBoundaries.
* The viewport bounding box in scene plane coordinates, see {@link calcViewportBoundaries}
*/
declare vptCoords: TCornerPoint;

Expand Down Expand Up @@ -504,10 +500,7 @@ export class StaticCanvas<

/**
* Calculate the position of the 4 corner of canvas with current viewportTransform.
* helps to determinate when an object is in the current rendering viewport using
* object absolute coordinates ( aCoords )
* @return {Object} points.tl
* @chainable
* helps to determinate when an object is in the current rendering viewport
*/
calcViewportBoundaries(): TCornerPoint {
const width = this.width,
Expand Down
17 changes: 5 additions & 12 deletions src/shapes/Object/InteractiveObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,10 @@ export class InteractiveFabricObject<
declare moveCursor: CSSStyleDeclaration['cursor'] | null;

/**
* Describe object's corner position in canvas element coordinates.
* properties are depending on control keys and padding the main controls.
* each property is an object with x, y and corner.
* The `corner` property contains in a similar manner the 4 points of the
* interactive area of the corner.
* The coordinates depends from the controls positionHandler and are used
* to draw and locate controls
* The object's controls' position in viewport coordinates
* Calculated by {@link Control#positionHandler} and {@link Control#calcCornerCoords}, depending on {@link padding}.
* `corner/touchCorner` describe the 4 points forming the interactive area of the corner.
* Used to draw and locate controls.
*/
declare oCoords: Record<string, TOCoord>;

Expand Down Expand Up @@ -292,16 +289,12 @@ export class InteractiveFabricObject<
}

/**
* Sets corner and controls position coordinates based on current angle, width and height, left and top.
* oCoords are used to find the corners
* aCoords are used to quickly find an object on the canvas
* lineCoords are used to quickly find object during pointer events.
* @override set controls' coordinates as well
* See {@link https://github.com/fabricjs/fabric.js/wiki/When-to-call-setCoords} and {@link http://fabricjs.com/fabric-gotchas}
* @return {void}
*/
setCoords(): void {
super.setCoords();
// set coordinates of the draggable boxes in the corners used to scale/rotate the image
this.canvas && (this.oCoords = this.calcOCoords());
}

Expand Down
4 changes: 2 additions & 2 deletions src/shapes/Object/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1376,9 +1376,9 @@ export class FabricObject<
sendObjectToPlane(this, this.getViewportTransform());
}

this.setCoords();
const el = createCanvasElement(),
// calculate with setCoords now.
boundingRect = this.getBoundingRect(true),
boundingRect = this.getBoundingRect(),
shadow = this.shadow,
shadowOffset = new Point();

Expand Down
Loading

0 comments on commit 3adbb0f

Please sign in to comment.