gl3n.aabb

  • Declaration

    struct AABBT(type, uint dimension_ = 3);

    Base template for all AABB-types.

    Parameters

    type

    all values get stored as this type

    • at

      Declaration

      alias at = type;

      Holds the internal type of the AABB.

    • vec

      Declaration

      alias vec = Vector!(at, dimension_);

      Convenience alias to the corresponding vector type.

    • min

      Declaration

      vec min;

      The minimum of the AABB (e.g. vec(0, 0, 0)).

    • max

      Declaration

      vec max;

      The maximum of the AABB (e.g. vec(1, 1, 1)).

    • Declaration

      this(vec min, vec max);

      Constructs the AABB.

      Parameters

      vec min

      minimum of the AABB

      vec max

      maximum of the AABB

    • Declaration

      static AABBT from_points(vec[] points);

      Constructs the AABB around N points (all points will be part of the AABB).

    • Declaration

      void expand(AABBT b);

      Expands the AABB by another AABB.

    • Declaration

      void expand(vec v);

      Expands the AABB, so that v is part of the AABB.

    • Declaration

      const bool intersects(AABBT box);

      Returns true if the AABBs intersect. This also returns true if one AABB lies inside another.

    • Declaration

      const @property vec extent();

      Returns the extent of the AABB (also sometimes called size).

    • Declaration

      const @property vec half_extent();

      Returns the half extent.

    • Declaration

      const @property real area();

      Returns the area of the AABB.

      Examples

      Returns the area of the AABB.

      1. alias AABB = AABBT!(at, dimension); AABB a = AABB(sizedVec([0.0, 0.0, 0.0, 0.0]), sizedVec([1.0, 1.0, 1.0, 1.0])); switch (dimension) { case 1: assert(a.area == 0); break; case 2: assert(a.area == 1); break; case 3: assert(a.area == 6); break; default: assert(0); } AABB b = AABB(sizedVec([2.0, 2.0, 2.0, 2.0]), sizedVec([10.0, 10.0, 10.0, 10.0])); switch (dimension) { case 1: assert(b.area == 0); break; case 2: assert(b.area == 64); break; case 3: assert(b.area == 384); break; default: assert(0); } AABB c = AABB(sizedVec([2.0, 4.0, 6.0, 6.0]), sizedVec([10.0, 10.0, 10.0, 10.0])); switch (dimension) { case 1: assert(c.area == 0); break; case 2: assert(almost_equal(c.area, 48.0)); break; case 3: assert(almost_equal(c.area, 208.0)); break; default: assert(0); }

    • Declaration

      const @property vec center();

      Returns the center of the AABB.

    • Declaration

      const @property vec[] vertices();

      Returns all vertices of the AABB, basically one vec per corner.