Created
April 15, 2019 09:52
-
-
Save idkiller/18fadbd9aeb79bc386b4d8fabc59e1f8 to your computer and use it in GitHub Desktop.
Revisions
-
idkiller created this gist
Apr 15, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ const RAD = Math.PI / 180; function bound(x: number, y: number, w: number, h: number, deg: number) { const rcos = Math.cos(deg * RAD); const rsin = Math.sin(deg * RAD); let left = 0; let top = 0; let right = 0; let bottom = 0; if (rcos >= 0 && rsin >= 0) { // top, right left = x - h * rsin; top = y; right = x + w * rcos; bottom = y + w * rsin + h * rcos; } else if (rcos < 0 && rsin >= 0) { // bottom, right left = x - h * rsin + w * rcos; top = y + h * rcos; right = x; bottom = y + w * rsin; } else if (rcos < 0 && rsin < 0) { // bottom, left left = x + w * rcos; top = y + w * rsin + h * rcos; right = x - h * rsin; bottom = y; } else { // top, left left = x; top = y + w * rsin; right = x + w * rcos - h * rsin; bottom = y + h * rcos; } return { left, top, right, bottom }; }