-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |