1.0.10 • Published 10 months ago

nearby-points v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

nearby-points

A package for finding data points within a region.

Full API reference

sample usage

import { PositionalDB, PointData } from "nearby-points";

// create subclass PointData 
class Restaurant extends PointData {
    
    foodCategory: string;
    rating: number;

    constructor(x: number, y: number, foodCategory: string, rating: number) {
        super(x, y);
        
        this.foodCategory = foodCategory;
        this.rating = rating;
    }
}

// initialize db
const foodDB = new PositionalDB("filename.db", 
                                "foodCategory TEXT, rating REAL");

// insert data
foodDB.add(new Restaurant(10, 10, "fried chicken", 3.6));
foodDB.add(new Restaurant(13, 76, "sandwiches", 4.1));
foodDB.add(new Restaurant(90, 45, "smoothies", 4.7));

// find restaurants within 100 units of (50, 50)
const foodNearby = foodDB.getWithinRadius(50, 50, 100);

performance

nearby-points is much faster then dumping all points into one SQL table. However, .db files will take more disk space.

Tests for finding points within 20 units of (50, 50):

n - number of points, randomly generated between (0,0) and (100, 100)

plain db - SQLite3 database where all data points are put into 1 table

positional db - SQLite3 database created using PositionalDB class

speed (ms)

n1001,00010,000100,000
plain db0.17591.652112.062147.9294
positional db0.26630.34842.62517.2353

disk space (bytes)

n1001,00010,000100,000
plain db4096122880125747212984320
positional db4096208896151552013004800

The code that ran these tests can be found here

diagram of grid created by PositionalDB

1.0.9

10 months ago

1.0.8

10 months ago

1.0.10

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago