Skip to content

Commit

Permalink
dep(): _setCornerCoords => _calcCornerCoords
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Oct 31, 2022
1 parent 53c27e4 commit 5afe4c6
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions src/mixins/object_interactivity.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { IPoint, Point } from '../point.class';
import type { TCornerPoint, TDegree, TMat2D } from '../typedefs';
import { ControlRenderingStyleOverride } from '../controls';
import type { Control } from '../controls/control.class';
import { Point } from '../point.class';
import { FabricObject } from '../shapes/object.class';
import { degreesToRadians } from '../util/misc/radiansDegreesConversion';
import type { TCornerPoint, TDegree, TMat2D } from '../typedefs';
import {
calcRotateMatrix,
multiplyTransformMatrices,
qrDecompose,
TQrDecomposeOut,
} from '../util/misc/matrix';
import { ObjectGeometry } from './object_geometry.mixin';
import type { Control } from '../controls/control.class';
import { sizeAfterTransform } from '../util/misc/objectTransforms';
import { ControlRenderingStyleOverride } from '../controls';
import { degreesToRadians } from '../util/misc/radiansDegreesConversion';
import { ObjectGeometry } from './object_geometry.mixin';

type TOCoord = IPoint & {
type TOCoord = Point & {
corner: TCornerPoint;
touchCorner: TCornerPoint;
};
Expand Down Expand Up @@ -185,7 +185,11 @@ export class InteractiveFabricObject extends FabricObject {
coords: Record<string, TOCoord> = {};

this.forEachControl((control, key) => {
coords[key] = control.positionHandler(dim, finalMatrix, this, control);
const position = control.positionHandler(dim, finalMatrix, this, control);
coords[key] = Object.assign(
position,
this._calcCornerCoords(control, position)
);
});

// debug code
Expand All @@ -204,6 +208,31 @@ export class InteractiveFabricObject extends FabricObject {
return coords;
}

/**
* Sets the coordinates that determine the interaction area of each control
* note: if we would switch to ROUND corner area, all of this would disappear.
* everything would resolve to a single point and a pythagorean theorem for the distance
* @todo evaluate simplification of code switching to circle interaction area at runtime
* @private
*/
private _calcCornerCoords(control: Control, position: Point) {
const corner = control.calcCornerCoords(
this.angle,
this.cornerSize,
position.x,
position.y,
false
);
const touchCorner = control.calcCornerCoords(
this.angle,
this.touchCornerSize,
position.x,
position.y,
true
);
return { corner, touchCorner };
}

/**
* Sets corner and controls position coordinates based on current angle, width and height, left and top.
* oCoords are used to find the corners
Expand Down Expand Up @@ -239,33 +268,6 @@ export class InteractiveFabricObject extends FabricObject {
}
}

/**
* Sets the coordinates that determine the interaction area of each control
* note: if we would switch to ROUND corner area, all of this would disappear.
* everything would resolve to a single point and a pythagorean theorem for the distance
* @todo evaluate simplification of code switching to circle interaction area at runtime
* @private
*/
_setCornerCoords(): void {
Object.entries(this.oCoords).forEach(([controlKey, control]) => {
const controlObject = this.controls[controlKey];
control.corner = controlObject.calcCornerCoords(
this.angle,
this.cornerSize,
control.x,
control.y,
false
);
control.touchCorner = controlObject.calcCornerCoords(
this.angle,
this.touchCornerSize,
control.x,
control.y,
true
);
});
}

/**
* Draws a colored layer behind the object, inside its selection borders.
* Requires public options: padding, selectionBackgroundColor
Expand Down

0 comments on commit 5afe4c6

Please sign in to comment.