Skip to content

Commit

Permalink
Fix Constraint.#compute
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed Aug 16, 2023
1 parent 55da070 commit c8b6745
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"email": "[email protected]"
}
],
"version": "1.0.0",
"version": "1.0.1",
"compatibility": {
"minimum": "11",
"verified": "11"
Expand Down Expand Up @@ -36,8 +36,8 @@
},
"url": "https://github.com/dev7355608/limits",
"manifest": "https://github.com/dev7355608/limits/releases/latest/download/module.json",
"download": "https://github.com/dev7355608/limits/releases/download/v1.0.0/module.zip",
"changelog": "https://github.com/dev7355608/limits/releases/tag/v1.0.0",
"download": "https://github.com/dev7355608/limits/releases/download/v1.0.1/module.zip",
"changelog": "https://github.com/dev7355608/limits/releases/tag/v1.0.1",
"bugs": "https://github.com/dev7355608/limits/issues",
"readme": "https://raw.githubusercontent.com/dev7355608/limits/main/README.md",
"license": "https://raw.githubusercontent.com/dev7355608/limits/main/LICENSE"
Expand Down
31 changes: 20 additions & 11 deletions scripts/constraint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class Constraint extends PIXI.Polygon {
constructor(polygon, sense) {
super();

const origin = polygon.origin;
const config = polygon.config;
const source = config.source;

Expand All @@ -49,9 +50,9 @@ export class Constraint extends PIXI.Polygon {
* @readonly
*/
this.origin = {
x: source.x,
y: source.y,
z: source.elevation * canvas.dimensions.distancePixels
x: origin.x,
y: origin.y,
z: source ? source.elevation * canvas.dimensions.distancePixels : 0
};
/**
* @type {number}
Expand Down Expand Up @@ -252,28 +253,28 @@ export class Constraint extends PIXI.Polygon {
} else {
switch (q2) {
case 0:
if (x1 !== ox) {
if (x1 !== ox || x2 !== ox) {
px0 = Math.max(px0, x2);
py0 = Math.max(py0, y2);
}

break;
case 1:
if (y1 !== oy) {
if (y1 !== oy || y2 !== oy) {
px1 = Math.min(px1, x2);
py1 = Math.max(py1, y2);
}

break;
case 2:
if (x1 !== ox) {
if (x1 !== ox || x2 !== ox) {
px2 = Math.min(px2, x2);
py2 = Math.min(py2, y2);
}

break;
case 3:
if (y1 !== oy) {
if (y1 !== oy || y2 !== oy) {
px3 = Math.max(px3, x2);
py3 = Math.min(py3, y2);
}
Expand Down Expand Up @@ -303,7 +304,7 @@ export class Constraint extends PIXI.Polygon {
py2 = Math.max(py2, minY);
py3 = Math.max(py3, minY);

{
if (ox < px0 && oy < py0) {
const rayCaster1 = this.#rayCaster1 = rayCaster0.crop(ox, oy, minZ, px0, py0, maxZ);
const { minD, maxD } = rayCaster1;

Expand All @@ -323,9 +324,11 @@ export class Constraint extends PIXI.Polygon {
this.#castRays(rayCaster1, px0, oy, px0, py0);
this.#castRays(rayCaster1, px0, py0, ox, py0);
}
} else {
this.#rayCaster1 = null;
}

{
if (px1 < ox && oy < py1) {
const rayCaster2 = this.#rayCaster2 = rayCaster0.crop(px1, oy, minZ, ox, py1, maxZ);
const { minD, maxD } = rayCaster2;

Expand All @@ -345,9 +348,11 @@ export class Constraint extends PIXI.Polygon {
this.#castRays(rayCaster2, ox, py1, px1, py1);
this.#castRays(rayCaster2, px1, py1, px1, oy);
}
} else {
this.#rayCaster2 = null;
}

{
if (px2 < ox && py2 < oy) {
const rayCaster3 = this.#rayCaster3 = rayCaster0.crop(px2, py2, minZ, ox, oy, maxZ);
const { minD, maxD } = rayCaster3;

Expand All @@ -367,9 +372,11 @@ export class Constraint extends PIXI.Polygon {
this.#castRays(rayCaster3, px2, oy, px2, py2);
this.#castRays(rayCaster3, px2, py2, ox, py2);
}
} else {
this.#rayCaster3 = null;
}

{
if (ox < px3 && py3 < oy) {
const rayCaster4 = this.#rayCaster4 = rayCaster0.crop(ox, py3, minZ, px3, oy, maxZ);
const { minD, maxD } = rayCaster4;

Expand All @@ -389,6 +396,8 @@ export class Constraint extends PIXI.Polygon {
this.#castRays(rayCaster4, ox, py3, px3, py3);
this.#castRays(rayCaster4, px3, py3, px3, oy);
}
} else {
this.#rayCaster4 = null;
}
}

Expand Down

0 comments on commit c8b6745

Please sign in to comment.