2017-04-04 01:24:46 +02:00
|
|
|
/*
|
|
|
|
========================================================================
|
|
|
|
The /r/place Atlas
|
|
|
|
|
|
|
|
An Atlas of Reddit's /r/place, with information to each
|
|
|
|
artwork of the canvas provided by the community.
|
|
|
|
|
|
|
|
Copyright (C) 2017 Roland Rytz <roland@draemm.li>
|
|
|
|
Licensed under the GNU Affero General Public License Version 3
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
For more information, see:
|
2022-04-03 11:08:52 +02:00
|
|
|
http://place-atlas.stefanocoding.me/license.txt
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
========================================================================
|
|
|
|
*/
|
|
|
|
|
2022-04-03 11:08:52 +02:00
|
|
|
window.addEventListener("error", function (e) {
|
2017-04-10 17:57:13 +02:00
|
|
|
console.log(e);
|
|
|
|
var errorMessage = "<p class=\"error\">An error has occurred:</p>";
|
2022-04-03 11:08:52 +02:00
|
|
|
errorMessage += "<p class=\"errorBody\">" + e.message + "</p>";
|
|
|
|
errorMessage += "<p class=\"errorBody\">on line " + e.lineno + "</p>";
|
2017-04-10 17:57:13 +02:00
|
|
|
errorMessage += "<p class=\"error\">If this keeps happening, feel free to send me a <a href=\"mailto:roland.rytz@gmail.com\">mail</a>.</p>";
|
|
|
|
document.getElementById("loadingContent").innerHTML = errorMessage;
|
|
|
|
});
|
|
|
|
|
2022-04-06 15:29:40 +02:00
|
|
|
function getPositionOfEntry(entry){
|
|
|
|
let startX = 2000, startY = 2000;
|
|
|
|
for(let [x, y] of entry.path){
|
|
|
|
startX = Math.min(x, startX);
|
|
|
|
startY = Math.min(y, startY)
|
2017-04-10 14:40:01 +02:00
|
|
|
}
|
2022-04-06 15:29:40 +02:00
|
|
|
if(startX === 2000 || startY === 2000) return null;
|
|
|
|
return [parseInt(startX), parseInt(startY)];
|
2017-04-10 14:40:01 +02:00
|
|
|
}
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-06 15:29:40 +02:00
|
|
|
// Modified from https://stackoverflow.com/a/33670691
|
|
|
|
function calcPolygonArea(vertices) {
|
|
|
|
var total = 0;
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-06 15:29:40 +02:00
|
|
|
for (var i = 0, l = vertices.length; i < l; i++) {
|
|
|
|
var addX = vertices[i][0];
|
|
|
|
var addY = vertices[i == vertices.length - 1 ? 0 : i + 1][1];
|
|
|
|
var subX = vertices[i == vertices.length - 1 ? 0 : i + 1][0];
|
|
|
|
var subY = vertices[i][1];
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-06 15:29:40 +02:00
|
|
|
total += (addX * addY * 0.5);
|
|
|
|
total -= (subX * subY * 0.5);
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-06 15:29:40 +02:00
|
|
|
return Math.floor(Math.abs(total));
|
|
|
|
}
|