@timohausmann/quadtree-ts
    Preparing search index...

    Class Circle<CustomDataType>

    Class representing a Circle.

    const circle = new Circle({
    x: 100,
    y: 100,
    r: 32,
    });
    const circle = new Circle({
    x: 100,
    y: 100,
    r: 32,
    data: {
    name: 'Jane',
    health: 100,
    },
    });
    interface ObjectData {
    name: string;
    health: number;
    }
    const entity: ObjectData = {
    name: 'Jane',
    health: 100,
    };

    // Typescript will infer the type of the data property
    const circle1 = new Circle({
    x: 100,
    y: 100,
    r: 32,
    data: entity,
    });

    // You can also pass in a generic type for the data property
    const circle2 = new Circle<ObjectData>({
    x: 100,
    y: 100,
    r: 32,
    });
    circle2.data = entity;
    // extending inherits the geometry's properties and the qtIndex method
    class Bomb extends Circle {

    constructor(countdown, x, y, r) {
    super({ x, y, r });
    this.countdown = countdown;
    }
    }

    const bomb = new Bomb(5, 10, 20, 30);
    // no need to extend if you don't implement CircleGeometry
    class Bomb {

    constructor(countdown) {
    this.countdown = countdown;
    this.position = [10, 20];
    this.radius = 30;
    }

    // add a qtIndex method to your class
    qtIndex(node) {
    // map your properties to CircleGeometry
    return Circle.prototype.qtIndex.call({
    x: this.position[0],
    y: this.position[1],
    r: this.radius,
    }, node);
    }
    }

    const bomb = new Bomb(5);
    const player = {
    health: 100,
    x: 10,
    y: 20,
    r: 30,
    qtIndex: Circle.prototype.qtIndex,
    });
    // Note: this is not recommended but possible.
    // Using this technique, each object would have it's own qtIndex method.
    // Rather add qtIndex to your prototype, e.g. by using classes like shown above.
    const player = {
    name: 'Jane',
    health: 100,
    position: [10, 20],
    radius: 30,
    qtIndex: function(node) {
    return Circle.prototype.qtIndex.call({
    x: this.position[0],
    y: this.position[1],
    r: this.radius,
    }, node);
    },
    });

    Type Parameters

    • CustomDataType = void

      Type of the custom data property (optional, inferred automatically).

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    Custom data.

    r: number

    Radius of the circle.

    x: number

    X center of the circle.

    y: number

    Y center of the circle.

    Methods

    • Determine which quadrant this circle belongs to.

      Parameters

      Returns number[]

      Array containing indexes of intersecting subnodes (0-3 = top-right, top-left, bottom-left, bottom-right)

    • Beta

      Check if a circle intersects an axis aligned rectangle.

      Parameters

      • x: number

        circle center X

      • y: number

        circle center Y

      • r: number

        circle radius

      • minX: number

        rectangle start X

      • minY: number

        rectangle start Y

      • maxX: number

        rectangle end X

      • maxY: number

        rectangle end Y

      Returns boolean

      true if circle intersects rectangle

      const circ = { x: 10, y: 20, r: 30 };
      const rect = { x: 40, y: 50, width: 60, height: 70 };
      const intersect = Circle.intersectRect(
      circ.x,
      circ.y,
      circ.r,
      rect.x,
      rect.y,
      rect.x + rect.width,
      rect.y + rect.height,
      );
      console.log(circle, rect, 'intersect?', intersect);