Skip to content

Commit

Permalink
fix(masonry): Fix bounding box scale error for all bricks
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan-Palan committed Aug 21, 2024
1 parent 224fa18 commit 47539cf
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 54 deletions.
71 changes: 60 additions & 11 deletions modules/masonry/src/brick/design0/BrickBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,87 @@ 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<string, { extent: TBrickExtent; coords: TBrickCoords }> {
const argsKeys = Object.keys(this._args);
const result: Record<string, { extent: TBrickExtent; coords: TBrickCoords }> = {};

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,
},
};
}
}
40 changes: 31 additions & 9 deletions modules/masonry/src/brick/design0/BrickExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof generatePath>;
Expand Down Expand Up @@ -50,26 +50,48 @@ 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<string, { extent: TBrickExtent; coords: TBrickCoords }> {
const argsKeys = Object.keys(this._args);
const result: Record<string, { extent: TBrickExtent; coords: TBrickCoords }> = {};

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,
},
};
}
}
49 changes: 40 additions & 9 deletions modules/masonry/src/brick/design0/BrickStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,61 @@ 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<string, { extent: TBrickExtent; coords: TBrickCoords }> {
const argsKeys = Object.keys(this._args);
const result: Record<string, { extent: TBrickExtent; coords: TBrickCoords }> = {};

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,
},
};
}
}
25 changes: 0 additions & 25 deletions modules/masonry/src/brick/design0/utils.ts

This file was deleted.

0 comments on commit 47539cf

Please sign in to comment.