Optimize new center algo a little bit

incl. Don't use modules
This commit is contained in:
Hans5958 2022-04-17 14:10:06 +07:00
parent 91465afda1
commit 2f417e433a
5 changed files with 17 additions and 25 deletions

View File

@ -326,16 +326,12 @@ def update_center(entry: dict):
if isinstance(entry['path'], list):
path = entry['path']
if len(path) > 1:
calculated_center = calculate_center(path)
if 'center' not in entry or entry['center'] != calculated_center:
entry['center'] = calculated_center
entry['center'] = calculate_center(path)
else:
for key in entry['path']:
path = entry['path'][key]
if len(path) > 1:
calculated_center = calculate_center(path)
if 'center' not in entry or key not in entry['center'] or entry['center'][key] != calculated_center:
entry['center'][key] = calculated_center
entry['center'][key] = calculate_center(path)
return entry

View File

@ -12,8 +12,6 @@
https://place-atlas.stefanocoding.me/license.txt
========================================================================
*/
import polylabel from './polylabel.js';
const finishButton = document.getElementById("finishButton");
const resetButton = document.getElementById("resetButton");
const undoButton = document.getElementById("undoButton");
@ -53,6 +51,8 @@ let periodGroupElements = []
let disableDrawingOverride = false
let drawing = true;
let undoHistory = [];
const periodClipboard = {
"index": null,
"path": null
@ -65,6 +65,7 @@ const periodClipboard = {
})
})
window.initDraw = initDraw
function initDraw() {
wrapper.classList.remove('listHidden')
@ -88,8 +89,6 @@ function initDraw() {
container.style.cursor = "crosshair";
let undoHistory = [];
render(path);
container.addEventListener("mousedown", function (e) {
@ -250,7 +249,7 @@ function initDraw() {
path: {},
};
pathWithPeriodsTemp = pathWithPeriods.concat()
const pathWithPeriodsTemp = pathWithPeriods.concat()
// console.log(pathWithPeriodsTemp)
@ -442,7 +441,7 @@ function initDraw() {
const params = new URLSearchParams(document.location.search)
if (params.has('id')) {
entry = getEntry(params.get('id'))
const entry = getEntry(params.get('id'))
nameField.value = entry.name
descriptionField.value = entry.description
websiteField.value = entry.links.website.join('\n')

View File

@ -1,10 +1,14 @@
'use strict';
import TinyQueue from './tinyqueue.min.js';
/**
* Minified by jsDelivr using Terser v5.10.0.
* Original file: /npm/tinyqueue@2.0.3/index.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
class TinyQueue{constructor(t=[],h=defaultCompare){if(this.data=t,this.length=this.data.length,this.compare=h,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],h=this.data.pop();return this.length--,this.length>0&&(this.data[0]=h,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:h,compare:s}=this,e=h[t];for(;t>0;){const a=t-1>>1,i=h[a];if(s(e,i)>=0)break;h[t]=i,t=a}h[t]=e}_down(t){const{data:h,compare:s}=this,e=this.length>>1,a=h[t];for(;t<e;){let e=1+(t<<1),i=h[e];const n=e+1;if(n<this.length&&s(h[n],i)<0&&(e=n,i=h[n]),s(i,a)>=0)break;h[t]=i,t=e}h[t]=a}}function defaultCompare(t,h){return t<h?-1:t>h?1:0}
if (TinyQueue.default) TinyQueue = TinyQueue.default; // temporary webpack fix
export default function polylabel(polygon, precision, debug) {
function polylabel(polygon, precision, debug) {
precision = precision || 0.5;
// find the bounding box of the outer ring

View File

@ -1,8 +0,0 @@
/**
* Minified by jsDelivr using Terser v5.10.0.
* Original file: /npm/tinyqueue@2.0.3/index.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
export default class TinyQueue{constructor(t=[],h=defaultCompare){if(this.data=t,this.length=this.data.length,this.compare=h,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],h=this.data.pop();return this.length--,this.length>0&&(this.data[0]=h,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:h,compare:s}=this,e=h[t];for(;t>0;){const a=t-1>>1,i=h[a];if(s(e,i)>=0)break;h[t]=i,t=a}h[t]=e}_down(t){const{data:h,compare:s}=this,e=this.length>>1,a=h[t];for(;t<e;){let e=1+(t<<1),i=h[e];const n=e+1;if(n<this.length&&s(h[n],i)<0&&(e=n,i=h[n]),s(i,a)>=0)break;h[t]=i,t=e}h[t]=a}}function defaultCompare(t,h){return t<h?-1:t>h?1:0}
//# sourceMappingURL=/sm/d66cdc801e31ad5c6f6a7e415184d6559e4e641efd692cca125432b4ff9c4b6e.map

View File

@ -329,7 +329,8 @@
<script type="text/javascript" src="./_js/atlas.js"></script>
<script type="text/javascript" src="./_js/view.js"></script>
<script type="text/javascript" src="./_js/overlap.js"></script>
<script type="module" src="./_js/draw.js"></script>
<script type="text/javascript" src="./_js/polylabel.js"></script>
<script type="text/javascript" src="./_js/draw.js"></script>
<script type="text/javascript" src="./_js/main.js"></script>
<!-- <script type="text/javascript" src="./_js/stats.js"></script>
<script type="text/javascript" src="./_js/minified.js"></script> -->