mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-12-25 18:44:25 +01:00
Merge remote-tracking branch 'up/cleanup' into cleanup
This commit is contained in:
commit
6bd8972af1
5 changed files with 783 additions and 582 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,3 +13,4 @@ combined.js
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
.vscode/
|
.vscode/
|
||||||
web/atlas-before-ids-migration.json
|
web/atlas-before-ids-migration.json
|
||||||
|
*.pyc
|
||||||
|
|
|
@ -189,6 +189,48 @@ def convert_subreddit_to_website(entry: dict):
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
def calculate_center(path: list):
|
||||||
|
"""
|
||||||
|
Caluclates the center of a polygon
|
||||||
|
|
||||||
|
adapted from /web/_js/draw.js:calucalteCenter()
|
||||||
|
"""
|
||||||
|
area = 0
|
||||||
|
x = 0
|
||||||
|
y = 0
|
||||||
|
|
||||||
|
for i in range(len(path)):
|
||||||
|
point1 = path[i]
|
||||||
|
point2 = path[i-1 if i != 0 else len(path)-1]
|
||||||
|
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
|
||||||
|
|
||||||
|
if area != 0:
|
||||||
|
return [x // area + 0.5, y // area + 0.5]
|
||||||
|
else:
|
||||||
|
# get the center of a straight line
|
||||||
|
max_x = max(i[0] for i in path)
|
||||||
|
min_x = min(i[0] for i in path)
|
||||||
|
max_y = max(i[1] for i in path)
|
||||||
|
min_y = min(i[1] for i in path)
|
||||||
|
return [(max_x + min_x) // 2 + 0.5, (max_y + min_y) // 2 + 0.5]
|
||||||
|
|
||||||
|
def update_center(entry: dict):
|
||||||
|
"""
|
||||||
|
checks if the center of a entry is up to date, and updates it if it's either missing or outdated
|
||||||
|
"""
|
||||||
|
if 'path' not in entry:
|
||||||
|
return entry
|
||||||
|
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
|
||||||
|
return entry
|
||||||
|
|
||||||
def validate(entry: dict):
|
def validate(entry: dict):
|
||||||
"""
|
"""
|
||||||
|
@ -256,6 +298,8 @@ def print_(*args, **kwargs):
|
||||||
entry = fix_no_protocol_urls(entry)
|
entry = fix_no_protocol_urls(entry)
|
||||||
print_("Removing extras...")
|
print_("Removing extras...")
|
||||||
entry = remove_extras(entry)
|
entry = remove_extras(entry)
|
||||||
|
print_("Updating center")
|
||||||
|
entry = update_center(entry)
|
||||||
print_("Validating...")
|
print_("Validating...")
|
||||||
status_code = validate(entry)
|
status_code = validate(entry)
|
||||||
print_("Completed!")
|
print_("Completed!")
|
||||||
|
|
|
@ -234,17 +234,8 @@ function initDraw(){
|
||||||
i,
|
i,
|
||||||
j,
|
j,
|
||||||
point1,
|
point1,
|
||||||
point2;
|
point2,
|
||||||
|
x = 0,
|
||||||
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,
|
|
||||||
y = 0,
|
y = 0,
|
||||||
f;
|
f;
|
||||||
|
|
||||||
|
@ -252,12 +243,13 @@ function initDraw(){
|
||||||
point1 = path[i];
|
point1 = path[i];
|
||||||
point2 = path[j];
|
point2 = path[j];
|
||||||
f = point1[0] * point2[1] - point2[0] * point1[1];
|
f = point1[0] * point2[1] - point2[0] * point1[1];
|
||||||
|
area += f;
|
||||||
x += (point1[0] + point2[0]) * f;
|
x += (point1[0] + point2[0]) * f;
|
||||||
y += (point1[1] + point2[1]) * f;
|
y += (point1[1] + point2[1]) * f;
|
||||||
}
|
}
|
||||||
|
area *= 3;
|
||||||
|
|
||||||
return [~~(x / area)+0.5, ~~(y / area)+0.5];
|
return [Math.floor(x / area)+0.5, Math.floor(y / area)+0.5];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function undo(){
|
function undo(){
|
||||||
|
|
|
@ -285,6 +285,7 @@ function buildObjectsList(filter, sort){
|
||||||
value.name.toLowerCase().indexOf(filter) !== -1
|
value.name.toLowerCase().indexOf(filter) !== -1
|
||||||
|| value.description.toLowerCase().indexOf(filter) !== -1
|
|| value.description.toLowerCase().indexOf(filter) !== -1
|
||||||
|| value.subreddit && value.subreddit.toLowerCase().indexOf(filter) !== -1
|
|| value.subreddit && value.subreddit.toLowerCase().indexOf(filter) !== -1
|
||||||
|
|| value.id === filter
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
document.getElementById("atlasSize").innerHTML = "Found "+sortedAtlas.length+" entries.";
|
document.getElementById("atlasSize").innerHTML = "Found "+sortedAtlas.length+" entries.";
|
||||||
|
|
1269
web/atlas.json
1269
web/atlas.json
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue