From 5afe4c64f236abde2a28450a579ff9f1f2dd4899 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Mon, 31 Oct 2022 03:01:59 +0200 Subject: [PATCH] dep(): `_setCornerCoords` => `_calcCornerCoords` --- src/mixins/object_interactivity.mixin.ts | 72 ++++++++++++------------ 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/src/mixins/object_interactivity.mixin.ts b/src/mixins/object_interactivity.mixin.ts index dfe4f939422..2ef90fe518d 100644 --- a/src/mixins/object_interactivity.mixin.ts +++ b/src/mixins/object_interactivity.mixin.ts @@ -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; }; @@ -185,7 +185,11 @@ export class InteractiveFabricObject extends FabricObject { coords: Record = {}; 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 @@ -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 @@ -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