-
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
7 changed files
with
92 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Block, isBlockGroupCollidingBlockGroup } from "blockwise"; | ||
|
||
const blocksA: Block[] = [ | ||
{ x: 0, y: 0, w: 10, h: 10 }, | ||
{ x: 20, y: 20, w: 10, h: 10 }, | ||
{ x: 10, y: 10, w: 10, h: 10 } | ||
]; | ||
|
||
const blocksB: Block[] = [ | ||
{ x: 5, y: 5, w: 10, h: 10 }, | ||
{ x: 25, y: 25, w: 10, h: 10 }, | ||
{ x: 15, y: 15, w: 10, h: 10 } | ||
]; | ||
|
||
console.log(isBlockGroupCollidingBlockGroup(blocksA, blocksB)); // true |
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,30 @@ | ||
import { test, expect } from "vitest"; | ||
import { isBlockGroupCollidingBlockGroup } from "./is-block-group-colliding-block-group"; | ||
|
||
test("should return true when block group collides block group", function() { | ||
const blocksA = [ | ||
{ x: 0, y: 0, w: 10, h: 10 }, | ||
{ x: 20, y: 20, w: 10, h: 10 }, | ||
{ x: 10, y: 10, w: 10, h: 10 } | ||
]; | ||
|
||
const blocksB = [ | ||
{ x: 5, y: 5, w: 10, h: 10 } | ||
]; | ||
|
||
expect(isBlockGroupCollidingBlockGroup(blocksA, blocksB)).toEqual(true); | ||
}); | ||
|
||
test("should return false when block group does not collide block group", function() { | ||
const blocksA = [ | ||
{ x: 0, y: 0, w: 10, h: 10 }, | ||
{ x: 20, y: 20, w: 10, h: 10 }, | ||
{ x: 10, y: 10, w: 10, h: 10 } | ||
]; | ||
|
||
const blocksB = [ | ||
{ x: 30, y: 30, w: 10, h: 10 } | ||
]; | ||
|
||
expect(isBlockGroupCollidingBlockGroup(blocksA, blocksB)).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, isBlockGroupColliding } from "blockwise"; | ||
|
||
/** | ||
* Check if a group of block is colliding with a group of blocks. | ||
* | ||
* @includeExample ./src/is-block-group-colliding-block-group.example.ts | ||
*/ | ||
export function isBlockGroupCollidingBlockGroup(a: Block[], b: Block[]): boolean { | ||
return a.some((block) => isBlockGroupColliding(b, block)); | ||
} |
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,11 @@ | ||
import { Block, isBlockGroupColliding } from "blockwise"; | ||
|
||
const blocks: Block[] = [ | ||
{ x: 0, y: 0, w: 10, h: 10 }, | ||
{ x: 20, y: 20, w: 10, h: 10 }, | ||
{ x: 10, y: 10, w: 10, h: 10 } | ||
]; | ||
|
||
const block: Block = { x: 5, y: 5, w: 10, h: 10 }; | ||
|
||
console.log(isBlockGroupColliding(blocks, block)); // true |
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,14 @@ | ||
import { test, expect } from "vitest"; | ||
import { isBlockGroupColliding } from "./is-block-group-colliding"; | ||
|
||
test("should return true when block group collides some of block group", function() { | ||
const blocksA = [ | ||
{ x: 0, y: 0, w: 10, h: 10 }, | ||
{ x: 20, y: 20, w: 10, h: 10 }, | ||
{ x: 10, y: 10, w: 10, h: 10 } | ||
]; | ||
|
||
const blocksB = { x: 5, y: 5, w: 10, h: 10 }; | ||
|
||
expect(isBlockGroupColliding(blocksA, blocksB)).toEqual(true); | ||
}); |
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, isBlockColliding } from "blockwise"; | ||
|
||
/** | ||
* Check if a block is colliding with any block in a group of blocks. | ||
* | ||
* @includeExample ./src/is-block-group-colliding.example.ts | ||
*/ | ||
export function isBlockGroupColliding(blocks: Block[], block: Block): boolean { | ||
return blocks.some((b) => isBlockColliding(b, block)); | ||
} |