Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
samwho committed Mar 21, 2024
1 parent c0d1843 commit a0d1c5c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
Binary file removed screenshots/rotated-tube-center.png
Binary file not shown.
Binary file removed screenshots/rotated-tube-fit.png
Binary file not shown.
Binary file added screenshots/tall-segment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/tall-tube-segment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 20 additions & 20 deletions test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,39 @@ export function rect({
}

export function tube({
x,
y,
width,
height,
center,
angle,
x = 0,
y = 0,
width = 100,
height = 50,
center = true,
orientation = "horizontal",
}: {
x?: number;
y?: number;
width?: number;
height?: number;
center?: boolean;
angle?: number;
orientation?: "horizontal" | "vertical";
} = {}): PIXI.Graphics {
x = x ?? 0;
y = y ?? 0;
width = width ?? 100;
height = height ?? 50;
center = center ?? true;

let tube = new PIXI.Graphics();

if (center) {
tube.pivot.x = width / 2;
tube.pivot.y = height / 2;
}
tube.beginFill(0xff0000);
tube.drawRect(x, y, width, height);
tube.drawCircle(x, y + height / 2, height / 2);
tube.drawCircle(x + width, y + height / 2, height / 2);
tube.endFill();
if (orientation === "horizontal") {
tube.beginFill(0xff0000);
tube.drawRect(x, y, width, height);
tube.drawCircle(x, y + height / 2, height / 2);
tube.drawCircle(x + width, y + height / 2, height / 2);
tube.endFill();
} else {
tube.beginFill(0xff0000);
tube.drawRect(x, y, width, height);
tube.drawCircle(x + width / 2, y, width / 2);
tube.drawCircle(x + width / 2, y + height, width / 2);
tube.endFill();
}

tube.angle = angle ?? 0;
return tube;
}

Expand Down
27 changes: 13 additions & 14 deletions tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,19 @@ componentTest("grid-of-tube-fit", () =>
).leaves((leaf) => leaf.center().fit().padding(5)),
);

componentTest("rotated-tube-center", () =>
HStack(tube({ angle: 90 })).leaves((leaf) => leaf.center()),
componentTest("tall-segment", () =>
HStack(rect({ center: true }), rect({ center: true }))
.proportions(10, 1)
.leaves((leaf) => leaf.fit())
.debug(),
);

componentTest("rotated-tube-fit", () =>
HStack(tube({ angle: 90 })).leaves((leaf) => leaf.fit()),
componentTest("tall-tube-segment", () =>
HStack(
tube({ center: true, orientation: "vertical" }),
tube({ center: true, orientation: "vertical" }),
)
.proportions(10, 1)
.leaves((leaf) => leaf.fit())
.debug(),
);

// Can't yet handle non-90 degree rotations
// componentTest("rotated-tube-fit-45", () =>
// HStack(tube({ angle: 45 })).leaves((leaf) => leaf.fit()),
// );
//
// Can't yet handle non-90 degree rotations
// componentTest("rotated-tube-fit-10", () =>
// HStack(tube({ angle: 10 })).leaves((leaf) => leaf.fit()),
// );

0 comments on commit a0d1c5c

Please sign in to comment.