Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<div id="app"></div>
<script src="https://code.createjs.com/1.0.0/tweenjs.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/5.2.4/pixi.min.js"></script>
<script>
var app = new PIXI.Application({
width: window.innerWidth,
height: window.innerHeight,
backgroundColor: 0x003300,
resolution: window.devicePixelRatio || 1,
@manix
manix / calculate geometric euclidean distance
Last active October 3, 2023 18:44
Distance between points simplified
getDistanceFromLatLonInM(lat1, lon1, lat2, lon2) {
var deg2rad = deg => deg * 0.017453293;
var a =
Math.pow(Math.sin(deg2rad(lat2 - lat1) / 2), 2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.pow(Math.sin(deg2rad(lon2 - lon1) / 2), 2);
return 12742000 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}
@manix
manix / sample.js
Last active March 1, 2024 23:51
Improved "fieldSorter"
function fieldSorterOptimized(fields) {
var dir = [], i, l = fields.length;
fields = fields.map(function(o, i) {
if (o[0] === "-") {
dir[i] = -1;
o = o.substring(1);
} else {
dir[i] = 1;
}
return o;