From 8758ea570f55bda04716707c69ee084b0954eb22 Mon Sep 17 00:00:00 2001 From: gongxh Date: Wed, 28 May 2025 11:19:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9B=E5=8F=89=E6=A0=91=E5=BD=A2=E7=8A=B6?= =?UTF-8?q?=E6=94=B9=E5=8F=98=E9=87=8D=E7=BD=AE=E5=8C=85=E5=9B=B4=E7=9B=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kunpocc.ts | 2 +- src/quadtree/Circle.ts | 24 ++++++++++++++++++------ src/quadtree/Polygon.ts | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/kunpocc.ts b/src/kunpocc.ts index 1f53b0f..db79336 100644 --- a/src/kunpocc.ts +++ b/src/kunpocc.ts @@ -31,9 +31,9 @@ export { ReadNetFile } from "./net/nettools/ReadNetFile"; /** 四叉树 */ export { Box } from "./quadtree/Box"; export { Circle } from "./quadtree/Circle"; +export { IShape } from "./quadtree/IShape"; export { Polygon } from "./quadtree/Polygon"; export { QTConfig, QuadTree } from "./quadtree/QuadTree"; -export { Shape } from "./quadtree/Shape"; /** 行为树 */ export { Agent as BTAgent } from "./behaviortree/Agent"; diff --git a/src/quadtree/Circle.ts b/src/quadtree/Circle.ts index 76d1d6a..9a65e1d 100644 --- a/src/quadtree/Circle.ts +++ b/src/quadtree/Circle.ts @@ -9,7 +9,7 @@ import { ShapeType } from "./IShape"; import { Shape } from "./Shape"; export class Circle extends Shape { - public radius: number; // 半径 + private _radius: number; // 半径 public get shapeType(): ShapeType { return ShapeType.CIRCLE; @@ -17,14 +17,26 @@ export class Circle extends Shape { constructor(radius: number, tag: number = -1) { super(tag); - this.radius = radius; - this._boundingBox.x = -this.radius; - this._boundingBox.y = -this.radius; - this._boundingBox.width = this.radius * 2; - this._boundingBox.height = this.radius * 2; + this._radius = radius; + this._boundingBox.x = -this._radius; + this._boundingBox.y = -this._radius; + this._boundingBox.width = this._radius * 2; + this._boundingBox.height = this._radius * 2; } public getBoundingBox(): Rect { 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; + } } \ No newline at end of file diff --git a/src/quadtree/Polygon.ts b/src/quadtree/Polygon.ts index 7066dea..d3266d4 100644 --- a/src/quadtree/Polygon.ts +++ b/src/quadtree/Polygon.ts @@ -87,5 +87,6 @@ export class Polygon extends Shape { for (let i = 0, len = pts.length; i < len; i++) { this._realPoints[i] = v2(pts[i].x, pts[i].y); } + this._isDirty = true; } } \ No newline at end of file