Skip to content

Commit

Permalink
add isBlockGroupPositionEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdodo committed Jan 7, 2025
1 parent 3a61655 commit f6d5f52
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockwise",
"version": "2.11.1",
"version": "2.12.0",
"description": "Minimalistic utility lib for writing simple 2d games where everything is a block.",
"main": "dist/index.js",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { isBlockColliding } from "./is-block-colliding";
export { isBlockEqual } from "./is-block-equal";
export { isBlockGroupColliding } from "./is-block-group-colliding";
export { isBlockGroupCollidingBlockGroup } from "./is-block-group-colliding-block-group";
export { isBlockGroupPositionEqual } from "./is-block-group-position-equal";
export { isBlockIncluding } from "./is-block-including";
export { isBlockNotEqual } from "./is-block-not-equal";
export { isBlockPositionEqual } from "./is-block-position-equal";
Expand Down
8 changes: 8 additions & 0 deletions src/is-block-group-position-equal.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Block, isBlockGroupPositionEqual } from "blockwise";

const a: Block[] = [{ x: 0, y: 0, w: 2, h: 2 }, { x: 0, y: 0, w: 1, h: 1 }];
const b: Block = { x: 0, y: 0, w: 1, h: 1 };
const c: Block = { x: 0, y: 1, w: 3, h: 3 };

console.log(isBlockGroupPositionEqual(a, b)); // true
console.log(isBlockGroupPositionEqual(a, c)); // false
21 changes: 21 additions & 0 deletions src/is-block-group-position-equal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test, expect } from "vitest";
import type { Block } from "./block";
import { isBlockGroupPositionEqual } from "./is-block-group-position-equal";

test("should return true when block group is same position as block", function() {
const a: Block[] = [{ x: 0, y: 0, w: 2, h: 2 }, { x: 0, y: 0, w: 1, h: 1 }];
const b: Block = { x: 0, y: 0, w: 1, h: 1 };
expect(isBlockGroupPositionEqual(a, b)).toEqual(true);
});

test("should return true when block group with some equal position is same position as block", function() {
const a: Block[] = [{ x: 0, y: 0, w: 2, h: 2 }, { x: 0, y: 1, w: 1, h: 1 }];
const b: Block = { x: 0, y: 0, w: 1, h: 1 };
expect(isBlockGroupPositionEqual(a, b)).toEqual(true);
});

test("should return false when block group is not the same position as block", function() {
const a: Block[] = [{ x: 0, y: 0, w: 2, h: 2 }, { x: 0, y: 0, w: 1, h: 1 }];
const b: Block = { x: 0, y: 1, w: 3, h: 3 };
expect(isBlockGroupPositionEqual(a, b)).toEqual(false);
});
10 changes: 10 additions & 0 deletions src/is-block-group-position-equal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Block, isBlockPositionEqual } from "blockwise";

/**
* Check if a group of block is the same position as a block
*
* @includeExample ./src/is-block-group-position-equal.example.ts
*/
export function isBlockGroupPositionEqual(a: Block[], b: Block): boolean {
return a.some((block) => isBlockPositionEqual(b, block));
}

0 comments on commit f6d5f52

Please sign in to comment.