mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-12-26 19:34:08 +01:00
Fix bugs of new center algorithm to make it work
This commit is contained in:
parent
3cd92178a2
commit
91465afda1
4 changed files with 5 additions and 31 deletions
|
@ -1,4 +1,3 @@
|
||||||
import polylabel from './polylabel.js';
|
|
||||||
/*
|
/*
|
||||||
========================================================================
|
========================================================================
|
||||||
The 2022 /r/place Atlas
|
The 2022 /r/place Atlas
|
||||||
|
@ -13,6 +12,7 @@ import polylabel from './polylabel.js';
|
||||||
https://place-atlas.stefanocoding.me/license.txt
|
https://place-atlas.stefanocoding.me/license.txt
|
||||||
========================================================================
|
========================================================================
|
||||||
*/
|
*/
|
||||||
|
import polylabel from './polylabel.js';
|
||||||
|
|
||||||
const finishButton = document.getElementById("finishButton");
|
const finishButton = document.getElementById("finishButton");
|
||||||
const resetButton = document.getElementById("resetButton");
|
const resetButton = document.getElementById("resetButton");
|
||||||
|
@ -256,9 +256,6 @@ function initDraw() {
|
||||||
|
|
||||||
// calculateCenter(path)
|
// calculateCenter(path)
|
||||||
|
|
||||||
function calculateCenter(path){
|
|
||||||
let result = polylabel(path)
|
|
||||||
return [Math.floor(result[0]) + 0.5, Math.floor(result[1]) + 0.5]
|
|
||||||
for (let i = pathWithPeriodsTemp.length - 1; i > 0; i--) {
|
for (let i = pathWithPeriodsTemp.length - 1; i > 0; i--) {
|
||||||
for (let j = 0; j < i; j++) {
|
for (let j = 0; j < i; j++) {
|
||||||
if (JSON.stringify(pathWithPeriodsTemp[i][1]) === JSON.stringify(pathWithPeriodsTemp[j][1])) {
|
if (JSON.stringify(pathWithPeriodsTemp[i][1]) === JSON.stringify(pathWithPeriodsTemp[j][1])) {
|
||||||
|
@ -496,27 +493,8 @@ function initDraw() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateCenter(path) {
|
function calculateCenter(path) {
|
||||||
|
let result = polylabel(path)
|
||||||
let area = 0,
|
return [Math.floor(result[0]) + 0.5, Math.floor(result[1]) + 0.5]
|
||||||
i,
|
|
||||||
j,
|
|
||||||
point1,
|
|
||||||
point2,
|
|
||||||
x = 0,
|
|
||||||
y = 0,
|
|
||||||
f;
|
|
||||||
|
|
||||||
for (i = 0, j = path.length - 1; i < path.length; j = i, i++) {
|
|
||||||
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 [Math.floor(x / area) + 0.5, Math.floor(y / area) + 0.5];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initPeriodGroups() {
|
function initPeriodGroups() {
|
||||||
|
|
|
@ -130,9 +130,6 @@ async function init() {
|
||||||
initGlobal()
|
initGlobal()
|
||||||
if (mode !== "draw") initViewGlobal()
|
if (mode !== "draw") initViewGlobal()
|
||||||
|
|
||||||
if(mode === "draw"){
|
|
||||||
window.initDraw();
|
|
||||||
} else if(mode === "about"){
|
|
||||||
if (mode === "draw") {
|
if (mode === "draw") {
|
||||||
initDraw();
|
initDraw();
|
||||||
} else if (mode === "about") {
|
} else if (mode === "about") {
|
||||||
|
|
|
@ -56,8 +56,8 @@ export default function polylabel(polygon, precision, debug) {
|
||||||
|
|
||||||
// update the best cell if we found a better one
|
// update the best cell if we found a better one
|
||||||
if (cell.d > bestCell.d || (
|
if (cell.d > bestCell.d || (
|
||||||
cell.centerDist < bestCell.centerDist &&
|
cell.centerDist < bestCell.centerDist &&
|
||||||
cell.d > bestCell.d - threshold
|
cell.d > bestCell.d - threshold
|
||||||
)) {
|
)) {
|
||||||
bestCell = cell;
|
bestCell = cell;
|
||||||
if (debug) console.log('found best %f after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
|
if (debug) console.log('found best %f after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
|
||||||
|
|
|
@ -305,7 +305,6 @@ <h2>Donation Links</h2>
|
||||||
<button id="closeDonateButton">Close</button>
|
<button id="closeDonateButton">Close</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template id="period-group">
|
<template id="period-group">
|
||||||
|
|
Loading…
Reference in a new issue