forked from gyaikhom/dbscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbscan.min.js
1 lines (1 loc) · 1023 Bytes
/
dbscan.min.js
1
/* Copyright 2015 Gagarine Yaikhom (MIT License) */(function(){var h=-1,a=-2,e=1,g=0,b=0;if(typeof dbscan==="undefined"){dbscan={}}dbscan.run=function(n,j,q,m,o){var l,k=0;for(l=0;l<j;++l){if(n[l].cluster_id===h){if(d(l,k,n,j,q,m,o)===e){++k}}}};function f(l,n,j,r,q){var m,k=[],o;for(m=0;m<j;++m){if(m===l){continue}o=q(n[l],n[m]);if(o>r){continue}else{k.push(m)}}return k}function d(k,o,r,m,t,l,n){var j,s=g,q=f(k,r,m,t,n);if(q.length<l){r[k].cluster_id=a}else{r[k].cluster_id=o;for(j=0;j<q.length;++j){r[q[j]].cluster_id=o}for(j=0;j<q.length;++j){c(q[j],q,o,r,m,t,l,n)}s=e}return s}function c(k,u,s,v,m,w,l,r){var j,q,o,t,n=f(k,v,m,w,r);q=n.length;if(q>=l){for(j=0;j<q;++j){t=n[j];o=v[t];if(o.cluster_id===a||o.cluster_id===h){if(o.cluster_id===h){u.push(t)}o.cluster_id=s}}}return b}dbscan.euclidean_dist=function(j,i){return Math.sqrt(Math.pow(j.x-i.x,2)+Math.pow(j.y-i.y,2))};dbscan.print_points=function(l,j){var k=0;console.log("Number of points: "+j);while(k<j){p=l[k];console.log(p.x,p.y,p.cluster_id);++k}}})();