Created
February 26, 2016 20:19
-
-
Save kreshikhin/aba99253cfdf36d61e89 to your computer and use it in GitHub Desktop.
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
function rescale(rect, border){ | |
var a = rect[0], b = rect[1], c = rect[2], d = rect[3]; | |
var ab = {x: b.x - a.x, y: b.y - a.y}; | |
var ad = {x: d.x - a.x, y: d.y - a.y}; | |
var lab = Math.sqrt(ab.x*ab.x+ab.y*ab.y); | |
var lad = Math.sqrt(ad.x*ad.x+ad.y*ad.y); | |
var ab1 = {x: ab.x * (lab + border) / lab, y: ab.y * (lab + border) / lab}; | |
var ad1 = {x: ad.x * (lad + border) / lad, y: ad.y * (lad + border) / lad}; | |
var a1b1 = {x: ab.x * (lab + 2*border) / lab, y: ab.y * (lab + 2*border) / lab}; | |
var a1d1 = {x: ad.x * (lad + 2*border) / lad, y: ad.y * (lad + 2*border) / lad}; | |
var c1 = {x: a.x + (ab1.x + ad1.x), y: a.y + (ab1.y + ad1.y)}; | |
var a1 = {x: c.x - (ab1.x + ad1.x), y: c.y - (ab1.y + ad1.y)}; | |
var b1 = {x: a1.x + a1b1.x, y: a1.y + a1b1.y}; | |
var d1 = {x: a1.x + a1d1.x, y: a1.y + a1d1.y}; | |
return [a1, b1, c1, d1]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment