25 lines
659 B
TypeScript
25 lines
659 B
TypeScript
import Vector2 from '$lib/vector';
|
|
import Rigidbody2D from '../rigidbody/rigidbody2d';
|
|
|
|
export class AABB {
|
|
private size: Vector2 = new Vector2();
|
|
private halfSize: Vector2 = new Vector2();
|
|
private rigidbody: Rigidbody2D = new Rigidbody2D();
|
|
|
|
constructor(min?: Vector2, max?: Vector2) {
|
|
if (min !== undefined && max !== undefined) this.size = new Vector2(max).sub(min);
|
|
|
|
this.halfSize = new Vector2(this.size.mul(0.5));
|
|
}
|
|
|
|
public get getMin(): Vector2 {
|
|
return new Vector2(this.rigidbody.Position).sub(this.halfSize);
|
|
}
|
|
|
|
public get getMax(): Vector2 {
|
|
return new Vector2(this.rigidbody.Position).add(this.halfSize);
|
|
}
|
|
}
|
|
|
|
export default AABB;
|