class Rect { constructor(w, h, x1=0, y1=0, alpha=0, text = "", fontSize = 20){ this.w = Math.abs(w); this.h = Math.abs(h); this.x1 = x1; this.y1 = y1; this.alpha = alpha; this.alphaRad = this.alpha*Math.PI/180; this.text = text; this.fontSize = fontSize; this.initBoundingBox(); } refresh(){ this.w = Math.abs(this.w); this.h = Math.abs(this.h); this.alphaRad = this.alpha*Math.PI/180; this.initBoundingBox(); } getQuadrant(){ if(0<=this.alphaRad' : ""; let textCoordsHtml = ' x="'+this.x1+'" y="'+(this.y1+2/3*this.h)+'"'; toRet = '' + rectsHtml + '' + this.text + '' + '' } else{ toRet = ''; } return toRet; } } function rotate(rect, angle, x0, y0){ let alpha1 = rect.alpha+angle; let angleRad = angle*Math.PI/180; let x1Temp = rect.x1-x0; let y1Temp= rect.y1-y0; let x11 = Math.cos(angleRad)*x1Temp - Math.sin(angleRad)*y1Temp + x0; let y11 = Math.sin(angleRad)*x1Temp + Math.cos(angleRad)*y1Temp + y0; return new Rect(rect.w, rect.h, x11, y11, alpha1, rect.text, rect.fontSize); } function rotoTranslate(rect, angle, x0, y0){ let alpha1 = rect.alpha+angle; let angleRad = angle*Math.PI/180; let x1Temp = rect.x1-x0; let y1Temp= rect.y1-y0; let x11 = Math.cos(angleRad)*x1Temp - Math.sin(angleRad)*y1Temp; let y11 = Math.sin(angleRad)*x1Temp + Math.cos(angleRad)*y1Temp; return new Rect(rect.w, rect.h, x11, y11, alpha1); } function checkColl(r1, r2){ // 1. Check bounding box collision: if( r1.minX>r2.maxX || r1.maxXr2.maxY || r1.maxYr2.w || newR1.maxX<0 || newR1.minY>r2.h || newR1.maxY<0 ) return false; let newR2 = rotoTranslate(r2, -r1.alpha, r1.x1, r1.y1); if( newR2.minX>r1.w || newR2.maxX<0 || newR2.minY>r1.h || newR2.maxY<0 ) return false; // A Rectangle has a parametric description through s and t: // (x1, y1) + t*(cAlpha, sAlpha ) + s*(-sAlpha, cAlphs) // 0 <= t <= w, 0 <= s <= h. // // Start by limiting s through t range check return true; }