2017-04-04 01:24:46 +02:00
|
|
|
/*
|
|
|
|
========================================================================
|
2022-04-28 12:41:19 +02:00
|
|
|
The 2022 r/place Atlas
|
2022-04-09 04:45:47 +02:00
|
|
|
|
2022-04-29 07:31:12 +02:00
|
|
|
An atlas of Reddit's 2022 r/place, with information to each
|
2017-04-04 01:24:46 +02:00
|
|
|
artwork of the canvas provided by the community.
|
2022-04-09 04:45:47 +02:00
|
|
|
|
|
|
|
Copyright (c) 2017 Roland Rytz <roland@draemm.li>
|
2022-04-23 15:30:48 +02:00
|
|
|
Copyright (c) 2022 Place Atlas contributors
|
2022-04-09 04:45:47 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
Licensed under the GNU Affero General Public License Version 3
|
2022-04-09 03:23:55 +02:00
|
|
|
https://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) {
|
2022-05-06 09:41:22 +02:00
|
|
|
console.error(e)
|
|
|
|
let errorMessage = "<h4 class=\"mb-3\">An error has occurred:</h4>"
|
|
|
|
errorMessage += "<p class=\"text-danger\">" + e.message + "</p>"
|
|
|
|
errorMessage += "<p class=\"text-danger\">on line " + e.lineno + "</p>"
|
|
|
|
errorMessage += "<p>If this keeps happening, feel free to tell us on <a href=\"https://discord.gg/pJkm23b2nA\">our Discord server</a>.</p>"
|
|
|
|
document.getElementById("loadingContent").innerHTML = errorMessage
|
|
|
|
})
|
2017-04-10 17:57:13 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function getPositionOfEntry(entry) {
|
2023-03-19 07:03:49 +01:00
|
|
|
let startX = canvasSize.x, startY = canvasSize.y
|
2022-04-16 14:44:50 +02:00
|
|
|
for (const [x, y] of entry.path) {
|
2022-05-06 09:41:22 +02:00
|
|
|
startX = Math.min(x, startX)
|
2022-04-06 15:29:40 +02:00
|
|
|
startY = Math.min(y, startY)
|
2017-04-10 14:40:01 +02:00
|
|
|
}
|
2023-03-19 07:03:49 +01:00
|
|
|
if (startX === canvasSize.x || startY === canvasSize.y) return null
|
2022-05-06 09:41:22 +02:00
|
|
|
return [parseInt(startX), parseInt(startY)]
|
2017-04-10 14:40:01 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
const areaMap = new Map()
|
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) {
|
2022-05-06 09:41:22 +02:00
|
|
|
const hit = areaMap.get(vertices)
|
2023-03-17 18:30:33 +01:00
|
|
|
if (hit !== null) {
|
2022-05-06 09:41:22 +02:00
|
|
|
return hit
|
2022-04-06 21:31:21 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
let total = 0
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
for (let i = 0, l = vertices.length; i < l; i++) {
|
2022-05-06 09:41:22 +02:00
|
|
|
const addX = vertices[i][0]
|
2023-03-17 18:30:33 +01:00
|
|
|
const addY = vertices[i === vertices.length - 1 ? 0 : i + 1][1]
|
|
|
|
const subX = vertices[i === vertices.length - 1 ? 0 : i + 1][0]
|
2022-05-06 09:41:22 +02:00
|
|
|
const subY = vertices[i][1]
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
total += (addX * addY * 0.5)
|
|
|
|
total -= (subX * subY * 0.5)
|
2022-04-16 14:44:50 +02:00
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
const area = Math.floor(Math.abs(total))
|
|
|
|
areaMap.set(vertices, area)
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
return area
|
2022-04-06 15:29:40 +02:00
|
|
|
}
|