Skip to content

Commit

Permalink
Remove rotation code.
Browse files Browse the repository at this point in the history
  • Loading branch information
samwho committed Mar 21, 2024
1 parent e6b9d33 commit c0d1843
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 54 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pixijs-layout",
"version": "0.1.21",
"version": "0.1.22",
"description": "",
"main": "./out/index.js",
"types": "./out/index.d.ts",
Expand Down
Binary file modified screenshots/rotated-tube-fit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 10 additions & 53 deletions src/Leaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,6 @@ enum Align {
None,
}

function getRotatedDimensions(width: number, height: number, rotation: number) {
const sinAngle = Math.abs(Math.sin(rotation));
const cosAngle = Math.abs(Math.cos(rotation));
return {
width: width * cosAngle + height * sinAngle,
height: width * sinAngle + height * cosAngle,
};
}

function getOriginalDimensions(
rotatedWidth: number,
rotatedHeight: number,
rotation: number,
) {
const sinAngle = Math.abs(Math.sin(rotation));
const cosAngle = Math.abs(Math.cos(rotation));

const originalWidth =
(rotatedWidth * cosAngle + rotatedHeight * sinAngle) /
(cosAngle + sinAngle);
const originalHeight =
(rotatedHeight * cosAngle + rotatedWidth * sinAngle) /
(cosAngle + sinAngle);

// const originalWidth =
// (rotatedWidth * cosAngle + rotatedHeight * sinAngle) /
// (cosAngle * cosAngle + sinAngle * sinAngle);
// const originalHeight =
// (rotatedHeight * cosAngle + rotatedWidth * sinAngle) /
// (cosAngle * cosAngle + sinAngle * sinAngle);

return { width: originalWidth, height: originalHeight };
}

export function Leaf(child: Container): LeafComponent {
return new LeafComponent(child);
}
Expand Down Expand Up @@ -195,24 +161,21 @@ export class LeafComponent extends Container implements Positioner {

let x = this._child.x;
let y = this._child.y;
let { width, height } = getRotatedDimensions(
this._child.width,
this._child.height,
this._child.rotation,
);
let containerAspectRatio = space.width / space.height;
let width = this._child.width;
let height = this._child.height;
let aspectRatio = width / height;

switch (this._resize) {
case Resize.Fit:
x = space.x;
y = space.y;
if (containerAspectRatio > aspectRatio) {
width = space.height * aspectRatio;
height = space.height;
} else {
height = space.width / aspectRatio;
if (space.width / aspectRatio < space.height) {
width = space.width;
height = width / aspectRatio;
}
if (space.width / aspectRatio > space.height) {
height = space.height;
width = height * aspectRatio;
}
break;
case Resize.Stretch:
Expand Down Expand Up @@ -267,14 +230,8 @@ export class LeafComponent extends Container implements Positioner {
this._child.x = x;
this._child.y = y;

const finalDimensions = getOriginalDimensions(
width,
height,
this._child.rotation,
);

this._child.width = finalDimensions.width;
this._child.height = finalDimensions.height;
this._child.width = width;
this._child.height = height;

if ("arrange" in this._child) {
let child = this._child as Positioner;
Expand Down

0 comments on commit c0d1843

Please sign in to comment.