feat(utils): add findNearest function to calculate closest point
This commit is contained in:
parent
4f463c27e6
commit
abaa315b24
@ -12,4 +12,15 @@ function detailedCurrentDate() {
|
||||
second: '2-digit',
|
||||
timeZoneName: 'shortOffset'
|
||||
}).format();
|
||||
}
|
||||
|
||||
function findNearest(origin, getX, getY, ...dests) {
|
||||
const distanceToOrigin = (point) => Math.sqrt((getX(origin) - getX(point))**2 + (getY(origin) - getY(point))**2);
|
||||
return dests.reduce(
|
||||
(nearest, dest) => {
|
||||
const dist = distanceToOrigin(dest);
|
||||
return dist < nearest.dist ? {dist, dest} : nearest;
|
||||
},
|
||||
{dist: Infinity, dest: null}
|
||||
).dest;
|
||||
}
|
||||
2
EnvelopeGenerator.Web/wwwroot/js/util.min.js
vendored
2
EnvelopeGenerator.Web/wwwroot/js/util.min.js
vendored
@ -1 +1 @@
|
||||
function detailedCurrentDate(){return new Intl.DateTimeFormat("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"shortOffset"}).format()}const B64ToBuff=n=>new Uint8Array(Array.from(atob(n),n=>n.charCodeAt(0))).buffer,getLocaleDateString=()=>(new Date).toLocaleDateString("de-DE");
|
||||
function detailedCurrentDate(){return new Intl.DateTimeFormat("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"shortOffset"}).format()}function findNearest(n,t,i,...r){const u=r=>Math.sqrt((t(n)-t(r))**2+(i(n)-i(r))**2);return r.reduce((n,t)=>{const i=u(t);return i<n.dist?{dist:i,dest:t}:n},{dist:Infinity,dest:null}).dest}const B64ToBuff=n=>new Uint8Array(Array.from(atob(n),n=>n.charCodeAt(0))).buffer,getLocaleDateString=()=>(new Date).toLocaleDateString("de-DE");
|
||||
Loading…
x
Reference in New Issue
Block a user