GithubHelp home page GithubHelp logo

j05u3 / spatial-hash-table Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 75 KB

2D hash table for fast edges-or-points-touching-circle retrieval

PHP 100.00%
spatial hash table php in-memory-storage in-memory-database 2d-tile 2d-hash-table nearby nearby-locations spatial-index spatial-functions

spatial-hash-table's Introduction

Installation

Using Composer, just add it to your composer.json by running:

composer require josue/spatial-hash-table

Description

You can throw edges and points at it and than make fast proximity queries in a fixed radius (set in the constructor).

Usage

Example

Alt Test case graph

<?php

use SpatialHashTable\BiHashTable;
use SpatialHashTable\SupportedGeometries\Edge;
use SpatialHashTable\SupportedGeometries\Point;

$b = new BiHashTable(1);

$b->addElement(new Edge(new Point(-1.5, -1), new Point( -0.5, -0.5), 100));
$b->addElement(new Edge(new Point(1.25, 1.5), new Point( 0.5, 0.75), 200));
$b->addElement(new Edge(new Point(1.75, 1.75), new Point( 1.75, 1.25), 300));
$b->addElement(new Point(0.5, 0.5, 400));


echo json_encode($b->getAllElementsInCircle(new Point(0,0)));

And the output is:

{
  "100": {
    "id": 100,
    "p1": {
      "id": 0,
      "x": -1.5,
      "y": -1
    },
    "p2": {
      "id": 0,
      "x": -0.5,
      "y": -0.5
    }
  },
  "200": {
    "id": 200,
    "p1": {
      "id": 0,
      "x": 1.25,
      "y": 1.5
    },
    "p2": {
      "id": 0,
      "x": 0.5,
      "y": 0.75
    }
  },
  "400": {
    "id": 400,
    "x": 0.5,
    "y": 0.5
  }
}

spatial-hash-table's People

Contributors

j05u3 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.