diff --git a/CHANGELOG.md b/CHANGELOG.md index 732944acf..83f0c3229 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -213,6 +213,7 @@ are doing mtv adjustments during precollision. ### Updates +- Perf improve PolygonCollider.contains(...) perf by keeping geometry tests in local space. - Perf improvement to image rendering! with ImageRendererV2! Roughly doubles the performance of image rendering - Perf improvement to retrieving components with `ex.Entity.get()` which widely improves engine performance - Non-breaking parameters that reference `delta` to `elapsedMs` to better communicate intent and units diff --git a/src/engine/Collision/Colliders/PolygonCollider.ts b/src/engine/Collision/Colliders/PolygonCollider.ts index 91167064b..caae1cc5f 100644 --- a/src/engine/Collision/Colliders/PolygonCollider.ts +++ b/src/engine/Collision/Colliders/PolygonCollider.ts @@ -524,13 +524,17 @@ export class PolygonCollider extends Collider { public contains(point: Vector): boolean { // Always cast to the right, as long as we cast in a consistent fixed direction we // will be fine - const testRay = new Ray(point, new Vector(1, 0)); - const intersectCount = this.getSides().reduce(function (accum, side) { + const localPoint = this._transform.applyInverse(point); + const testRay = new Ray(localPoint, new Vector(1, 0)); + + let intersectCount = 0; + const sides = this.getLocalSides(); + for (let sideIndex = 0; sideIndex < sides.length; sideIndex++) { + const side = sides[sideIndex]; if (testRay.intersect(side) >= 0) { - return accum + 1; + intersectCount++; } - return accum; - }, 0); + } if (intersectCount % 2 === 0) { return false;