四叉树形状改变重置包围盒

This commit is contained in:
gongxh 2025-05-28 11:19:40 +08:00
parent 1b73738c39
commit 8758ea570f
3 changed files with 20 additions and 7 deletions

View File

@ -31,9 +31,9 @@ export { ReadNetFile } from "./net/nettools/ReadNetFile";
/** 四叉树 */ /** 四叉树 */
export { Box } from "./quadtree/Box"; export { Box } from "./quadtree/Box";
export { Circle } from "./quadtree/Circle"; export { Circle } from "./quadtree/Circle";
export { IShape } from "./quadtree/IShape";
export { Polygon } from "./quadtree/Polygon"; export { Polygon } from "./quadtree/Polygon";
export { QTConfig, QuadTree } from "./quadtree/QuadTree"; export { QTConfig, QuadTree } from "./quadtree/QuadTree";
export { Shape } from "./quadtree/Shape";
/** 行为树 */ /** 行为树 */
export { Agent as BTAgent } from "./behaviortree/Agent"; export { Agent as BTAgent } from "./behaviortree/Agent";

View File

@ -9,7 +9,7 @@ import { ShapeType } from "./IShape";
import { Shape } from "./Shape"; import { Shape } from "./Shape";
export class Circle extends Shape { export class Circle extends Shape {
public radius: number; // 半径 private _radius: number; // 半径
public get shapeType(): ShapeType { public get shapeType(): ShapeType {
return ShapeType.CIRCLE; return ShapeType.CIRCLE;
@ -17,14 +17,26 @@ export class Circle extends Shape {
constructor(radius: number, tag: number = -1) { constructor(radius: number, tag: number = -1) {
super(tag); super(tag);
this.radius = radius; this._radius = radius;
this._boundingBox.x = -this.radius; this._boundingBox.x = -this._radius;
this._boundingBox.y = -this.radius; this._boundingBox.y = -this._radius;
this._boundingBox.width = this.radius * 2; this._boundingBox.width = this._radius * 2;
this._boundingBox.height = this.radius * 2; this._boundingBox.height = this._radius * 2;
} }
public getBoundingBox(): Rect { public getBoundingBox(): Rect {
return this._boundingBox; return this._boundingBox;
} }
public get radius(): number {
return this._radius;
}
public set radius(value: number) {
this._radius = value;
this._boundingBox.x = -this._radius;
this._boundingBox.y = -this._radius;
this._boundingBox.width = this._radius * 2;
this._boundingBox.height = this._radius * 2;
}
} }

View File

@ -87,5 +87,6 @@ export class Polygon extends Shape {
for (let i = 0, len = pts.length; i < len; i++) { for (let i = 0, len = pts.length; i < len; i++) {
this._realPoints[i] = v2(pts[i].x, pts[i].y); this._realPoints[i] = v2(pts[i].x, pts[i].y);
} }
this._isDirty = true;
} }
} }