mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-12-26 05:54:09 +01:00
Merge pull request #783 from Tonny2442/area-feature
add sort by area (largest to smallest)
This commit is contained in:
commit
ece70714e6
3 changed files with 16 additions and 1 deletions
|
@ -39,9 +39,15 @@ function getPositionOfEntry(entry){
|
|||
return [parseInt(startX), parseInt(startY)];
|
||||
}
|
||||
|
||||
const areaMap = new Map();
|
||||
|
||||
// Modified from https://stackoverflow.com/a/33670691
|
||||
function calcPolygonArea(vertices) {
|
||||
var hit = areaMap.get(vertices);
|
||||
if (hit != null) {
|
||||
return hit;
|
||||
}
|
||||
|
||||
var total = 0;
|
||||
|
||||
for (var i = 0, l = vertices.length; i < l; i++) {
|
||||
|
@ -54,5 +60,8 @@ function calcPolygonArea(vertices) {
|
|||
total -= (subX * subY * 0.5);
|
||||
}
|
||||
|
||||
return Math.floor(Math.abs(total));
|
||||
var area = Math.floor(Math.abs(total));
|
||||
areaMap.set(vertices, area);
|
||||
|
||||
return area;
|
||||
}
|
|
@ -449,6 +449,11 @@ function initView(){
|
|||
return 0;
|
||||
}
|
||||
break;
|
||||
case "area":
|
||||
sortFunction = function(a, b){
|
||||
return calcPolygonArea(b.path) - calcPolygonArea(a.path);
|
||||
}
|
||||
break;
|
||||
case "relevant":
|
||||
sortFunction = function(a, b){
|
||||
if(a.name.toLowerCase().indexOf(filter) !== -1 && b.name.toLowerCase().indexOf(filter) !== -1){
|
||||
|
|
|
@ -126,6 +126,7 @@ <h1 id="title">The 2022 /r/place Atlas</h1>
|
|||
<option value="alphaDesc">↑ Alphabetical</option>
|
||||
<option value="newest">Newest</option>
|
||||
<option value="oldest">Oldest</option>
|
||||
<option value="area">Area</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue