mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-11-15 14:33:36 +01:00
Cleaned up calculateCenter function
While I still don't understand what it's doing exactly, I noticed that the 2 iterations of the loop are unnecessary, and afterwards found out that the change to area is equal to f. Furthermore I replaced the `~~` flooring with Math.floor for better readability, since this function get's executed once per submission and the speed benefits of `~~` are neglectable.
This commit is contained in:
parent
733decc20f
commit
bf834a6565
1 changed files with 17 additions and 25 deletions
|
@ -234,17 +234,8 @@ function initDraw(){
|
|||
i,
|
||||
j,
|
||||
point1,
|
||||
point2;
|
||||
|
||||
for (i = 0, j = path.length - 1; i < path.length; j=i,i++) {
|
||||
point1 = path[i];
|
||||
point2 = path[j];
|
||||
area += point1[0] * point2[1];
|
||||
area -= point1[1] * point2[0];
|
||||
}
|
||||
area *= 3;
|
||||
|
||||
var x = 0,
|
||||
point2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
f;
|
||||
|
||||
|
@ -252,12 +243,13 @@ function initDraw(){
|
|||
point1 = path[i];
|
||||
point2 = path[j];
|
||||
f = point1[0] * point2[1] - point2[0] * point1[1];
|
||||
area += f;
|
||||
x += (point1[0] + point2[0]) * f;
|
||||
y += (point1[1] + point2[1]) * f;
|
||||
}
|
||||
area *= 3;
|
||||
|
||||
return [~~(x / area)+0.5, ~~(y / area)+0.5];
|
||||
|
||||
return [Math.min(x / area)+0.5, Math.max(y / area)+0.5];
|
||||
}
|
||||
|
||||
function undo(){
|
||||
|
|
Loading…
Reference in a new issue