Created
March 30, 2020 13:14
-
-
Save theAlgorithmist/fcd56980c47fd5d64ad689d412c2b999 to your computer and use it in GitHub Desktop.
Advance a point-in-circle simulation one step
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public next(): void | |
{ | |
let circ: TSMT$Circle; | |
let g: PIXI.Graphics; | |
// first, redraw any circles previously marked as containing the point with the default stroke color | |
while (this._identifiedDO.length > 0) | |
{ | |
g = this._identifiedDO.pop(); | |
circ = this._identified.pop(); | |
canvasRenderCircle(g, circ, this.strokeWidth, this.strokeColor.toString()); | |
} | |
/* | |
random walk the point (realize that it could eventually 'walk' off the visible area; whether or not | |
that is something that should be tested and compensated for is up to you | |
*/ | |
[this._px, this._py] = pointRandomWalk(this._px, this._py, CircleService.LOW_RADIUS, CircleService.HIGH_RADIUS); | |
// draw the point and update the quadrant | |
this.__drawPoint(); | |
this._curQuad = TSMT$getQuadrant(this._px, this._py, 0, 0, this._width, this._height); | |
this.__drawQuadrants(); | |
// Only check circles in the quad in which the point is located | |
if (this._curQuad > 0 && this._curQuad < 5) | |
{ | |
// only update the id list if the quadrant changed | |
if (this._curQuad != this._prevQuad) | |
{ | |
this._prevQuad = this._curQuad; | |
this._check = Object.keys(this[`_quad${this._curQuad}`]); | |
} | |
this._check.forEach( (id: string): void => | |
{ | |
circ = this._circleRefs[+id]; | |
g = this._circleDO[+id]; | |
if (TSMT$PointInCircle(this._px, this._py, circ.x, circ.y, circ.radius)) | |
{ | |
this._identified.push(circ); | |
this._identifiedDO.push(g); | |
g.clear(); | |
g.lineStyle(this.strokeWidth, '0xff0000'); | |
g.drawCircle(circ.x, circ.y, circ.radius); | |
this.onIntersect.emit(id); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment