From 47539cf6a34fa16529a2e4b82243e0fcb7e8c5cc Mon Sep 17 00:00:00 2001 From: Karan Palan Date: Wed, 21 Aug 2024 17:05:47 +0530 Subject: [PATCH] fix(masonry): Fix bounding box scale error for all bricks --- .../masonry/src/brick/design0/BrickBlock.ts | 71 ++++++++++++++++--- .../src/brick/design0/BrickExpression.ts | 40 ++++++++--- .../src/brick/design0/BrickStatement.ts | 49 ++++++++++--- modules/masonry/src/brick/design0/utils.ts | 25 ------- 4 files changed, 131 insertions(+), 54 deletions(-) delete mode 100644 modules/masonry/src/brick/design0/utils.ts diff --git a/modules/masonry/src/brick/design0/BrickBlock.ts b/modules/masonry/src/brick/design0/BrickBlock.ts index 03902b61..969a7c6e 100644 --- a/modules/masonry/src/brick/design0/BrickBlock.ts +++ b/modules/masonry/src/brick/design0/BrickBlock.ts @@ -52,7 +52,16 @@ export default class BrickBlock extends BrickModelBlock { } public get bBoxBrick(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxBrick; + return { + extent: { + width: this._pathResults.bBoxBrick.extent.width * this._scale, + height: this._pathResults.bBoxBrick.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxBrick.coords.x * this._scale, + y: this._pathResults.bBoxBrick.coords.y * this._scale, + }, + }; } public get bBoxArgs(): Record { @@ -60,30 +69,70 @@ export default class BrickBlock extends BrickModelBlock { const result: Record = {}; argsKeys.forEach((key, index) => { - result[key] = { extent: { width: 0, height: 0 }, coords: { x: 0, y: 0 } }; - const argX = this._pathResults.bBoxArgs.coords[index].x; - const argY = this._pathResults.bBoxArgs.coords[index].y; - - result[key].extent = this._pathResults.bBoxArgs.extent; - result[key].coords = { x: argX, y: argY }; + result[key] = { + extent: { + width: this._pathResults.bBoxArgs.extent.width * this._scale, + height: this._pathResults.bBoxArgs.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxArgs.coords[index].x * this._scale, + y: this._pathResults.bBoxArgs.coords[index].y * this._scale, + }, + }; }); return result; } public get bBoxNotchArg(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxNotchArg!; + return { + extent: { + width: this._pathResults.bBoxNotchArg!.extent.width * this._scale, + height: this._pathResults.bBoxNotchArg!.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxNotchArg!.coords.x * this._scale, + y: this._pathResults.bBoxNotchArg!.coords.y * this._scale, + }, + }; } public get bBoxNotchInsTop(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxNotchInsTop!; + return { + extent: { + width: this._pathResults.bBoxNotchInsTop!.extent.width * this._scale, + height: this._pathResults.bBoxNotchInsTop!.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxNotchInsTop!.coords.x * this._scale, + y: this._pathResults.bBoxNotchInsTop!.coords.y * this._scale, + }, + }; } public get bBoxNotchInsBot(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxNotchInsBot!; + return { + extent: { + width: this._pathResults.bBoxNotchInsBot!.extent.width * this._scale, + height: this._pathResults.bBoxNotchInsBot!.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxNotchInsBot!.coords.x * this._scale, + y: this._pathResults.bBoxNotchInsBot!.coords.y * this._scale, + }, + }; } public get bBoxNotchInsNestTop(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxNotchInsNestTop!; + return { + extent: { + width: this._pathResults.bBoxNotchInsNestTop!.extent.width * this._scale, + height: this._pathResults.bBoxNotchInsNestTop!.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxNotchInsNestTop!.coords.x * this._scale, + y: this._pathResults.bBoxNotchInsNestTop!.coords.y * this._scale, + }, + }; } } diff --git a/modules/masonry/src/brick/design0/BrickExpression.ts b/modules/masonry/src/brick/design0/BrickExpression.ts index 8b910f3a..e039180a 100644 --- a/modules/masonry/src/brick/design0/BrickExpression.ts +++ b/modules/masonry/src/brick/design0/BrickExpression.ts @@ -7,7 +7,7 @@ import { generatePath } from '../utils/path'; /** * @class - * Final class that defines a expression brick. + * Final class that defines an expression brick. */ export default class BrickExpression extends BrickModelExpression { readonly _pathResults: ReturnType; @@ -50,7 +50,16 @@ export default class BrickExpression extends BrickModelExpression { } public get bBoxBrick(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxBrick; + return { + extent: { + width: this._pathResults.bBoxBrick.extent.width * this._scale, + height: this._pathResults.bBoxBrick.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxBrick.coords.x * this._scale, + y: this._pathResults.bBoxBrick.coords.y * this._scale, + }, + }; } public get bBoxArgs(): Record { @@ -58,18 +67,31 @@ export default class BrickExpression extends BrickModelExpression { const result: Record = {}; argsKeys.forEach((key, index) => { - result[key] = { extent: { width: 0, height: 0 }, coords: { x: 0, y: 0 } }; - const argX = this._pathResults.bBoxArgs.coords[index].x; - const argY = this._pathResults.bBoxArgs.coords[index].y; - - result[key].extent = this._pathResults.bBoxArgs.extent; - result[key].coords = { x: argX, y: argY }; + result[key] = { + extent: { + width: this._pathResults.bBoxArgs.extent.width * this._scale, + height: this._pathResults.bBoxArgs.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxArgs.coords[index].x * this._scale, + y: this._pathResults.bBoxArgs.coords[index].y * this._scale, + }, + }; }); return result; } public get bBoxNotchArg(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxNotchArg!; + return { + extent: { + width: this._pathResults.bBoxNotchArg!.extent.width * this._scale, + height: this._pathResults.bBoxNotchArg!.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxNotchArg!.coords.x * this._scale, + y: this._pathResults.bBoxNotchArg!.coords.y * this._scale, + }, + }; } } diff --git a/modules/masonry/src/brick/design0/BrickStatement.ts b/modules/masonry/src/brick/design0/BrickStatement.ts index aa710959..c6e588fd 100644 --- a/modules/masonry/src/brick/design0/BrickStatement.ts +++ b/modules/masonry/src/brick/design0/BrickStatement.ts @@ -51,7 +51,16 @@ export default class BrickStatement extends BrickModelStatement { } public get bBoxBrick(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxBrick; + return { + extent: { + width: this._pathResults.bBoxBrick.extent.width * this._scale, + height: this._pathResults.bBoxBrick.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxBrick.coords.x * this._scale, + y: this._pathResults.bBoxBrick.coords.y * this._scale, + }, + }; } public get bBoxArgs(): Record { @@ -59,22 +68,44 @@ export default class BrickStatement extends BrickModelStatement { const result: Record = {}; argsKeys.forEach((key, index) => { - result[key] = { extent: { width: 0, height: 0 }, coords: { x: 0, y: 0 } }; - const argX = this._pathResults.bBoxArgs.coords[index].x; - const argY = this._pathResults.bBoxArgs.coords[index].y; - - result[key].extent = this._pathResults.bBoxArgs.extent; - result[key].coords = { x: argX, y: argY }; + result[key] = { + extent: { + width: this._pathResults.bBoxArgs.extent.width * this._scale, + height: this._pathResults.bBoxArgs.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxArgs.coords[index].x * this._scale, + y: this._pathResults.bBoxArgs.coords[index].y * this._scale, + }, + }; }); return result; } public get bBoxNotchInsTop(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxNotchInsTop!; + return { + extent: { + width: this._pathResults.bBoxNotchInsTop!.extent.width * this._scale, + height: this._pathResults.bBoxNotchInsTop!.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxNotchInsTop!.coords.x * this._scale, + y: this._pathResults.bBoxNotchInsTop!.coords.y * this._scale, + }, + }; } public get bBoxNotchInsBot(): { extent: TBrickExtent; coords: TBrickCoords } { - return this._pathResults.bBoxNotchInsBot!; + return { + extent: { + width: this._pathResults.bBoxNotchInsBot!.extent.width * this._scale, + height: this._pathResults.bBoxNotchInsBot!.extent.height * this._scale, + }, + coords: { + x: this._pathResults.bBoxNotchInsBot!.coords.x * this._scale, + y: this._pathResults.bBoxNotchInsBot!.coords.y * this._scale, + }, + }; } } diff --git a/modules/masonry/src/brick/design0/utils.ts b/modules/masonry/src/brick/design0/utils.ts deleted file mode 100644 index 6b049b67..00000000 --- a/modules/masonry/src/brick/design0/utils.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { - TBrickType, - TBrickCoords, - IBrickData, - IBrickExpression, - IBrickStatement, - IBrickBlock, -} from '@/@types/brick'; - -type InstanceMap = { - data: IBrickData; - expression: IBrickExpression; - statement: IBrickStatement; - block: IBrickBlock; -}; - -export type Brick = { - id: string; - type: TBrickType; - instance: InstanceMap[TBrickType]; - surroundingBricks: { above: string; below: string }; - childBricks: string[]; - coords: TBrickCoords; - children?: Brick[]; -};