Skip to content

michalsanger/php-quadtree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quadtree Build Status

An easy-to-modify Quadtree with standard 2D implementation.

Usage

Standard 2D collision detection supports points and bounds (rectangular regions):

use \Quadtree\Quadtree;
use \Quadtree\Geometry\Bounds;
use \Quadtree\Geometry\Point;

$qtBounds = new Bounds(1024, 1024);
$qt = new Quadtree($qtBounds);

$qt->insert(new Bounds(300, 200)); // TRUE
$qt->insert(new Bounds(100, 50, 20, 10)); // FALSE
$qt->insert(new Point(250, 100)); // FALSE
$qt->insert(new Point(2000, 500)); // FALSE
$qt->insert(new Point(299, 199)); // TRUE

Need more logic for collision detection? Create your own ICollisionDetector. Need to insert other objects then points and bounds? Implement Insertable interface.

API

See the docs

Installation

Use Composer:

composer require michalsanger/quadtree

Tests

Due to Nette Tester tests are simple and readable. Run:

> vendor/bin/tester tests/