@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
191 lines • 5.32 kB
TypeScript
/**
* Computes the miniball of the given point set.
*
* Based on paper "Fast Smallest-Enclosing-Ball Computation in High Dimensions" by "Kaspar Fischer" et. al.
* @copyright Company Named Limited (c) 2025
*/
export class Miniball {
/**
* Notice that the point set `points` is assumed to be immutable during the computation.
* That is, if you add, remove, or change points in the point set, you have to create a new instance of {@link Miniball}.
*
* @param {PointSet} points the point set
*/
constructor(points: PointSet);
/**
*
* @type {number}
*/
iteration: number;
/**
*
* @type {number}
*/
distToAff: number;
/**
*
* @type {number}
*/
distToAffSquare: number;
/**
*
* The squared radius of the miniball.
*
* This is equivalent to `radius() * radius()`.
*
* Precondition: `!isEmpty()`
*
* @type {number}
* @private
*/
private __squaredRadius;
/**
*
* @type {number}
* @private
*/
private __radius;
/**
*
* @type {number}
*/
stopper: number;
/**
* @type {PointSet}
*/
S: PointSet;
/**
*
* @type {number}
* @private
*/
private __size;
/**
* Number of dimensions (2 for 2d, 3 for 3d etc.)
* @type {number}
*/
dim: number;
/**
*
* @type {number[]|Float64Array}
* @private
*/
private __center;
/**
*
* @type {number[]|Float64Array}
*/
centerToAff: number[] | Float64Array;
/**
*
* @type {number[]|Float64Array}
*/
centerToPoint: number[] | Float64Array;
/**
*
* @type {number[]|Float64Array}
*/
lambdas: number[] | Float64Array;
/**
*
* @type {Subspan}
* @private
*/
private __support;
/**
* Whether the miniball is the empty set, equivalently, whether `points.size() == 0`
* was true when this miniball instance was constructed.
*
* Notice that the miniball of a point set <i>S</i> is empty if and only if <i>S={}</i>.
*
* @return {boolean} true iff
*/
isEmpty(): boolean;
/**
* The radius of the miniball.
*
* Precondition: `!isEmpty()`
*
* @return {number} the radius of the miniball, a number ≥ 0
*/
radius(): number;
/**
* The Euclidean coordinates of the center of the miniball.
*
* Precondition: `!isEmpty()`
*
* @return {number[]} an array holding the coordinates of the center of the miniball
*/
center(): number[];
/**
*
* @returns {Subspan}
*/
get support(): Subspan;
/**
* The number of input points.
*
* @return {number} the number of points in the original point set, i.e., `pts.size()` where
* `pts` was the {@link PointSet} instance passed to the constructor of this
* instance
*/
size(): number;
/**
* Sets up the search ball with an arbitrary point of <i>S</i> as center and with exactly one of
* the points farthest from center in the support. So the current ball contains all points of
* <i>S</i> and has radius at most twice as large as the minball.
*
* Precondition: `size > 0`
* @return {Subspan}
* @private
*/
private initBall;
/**
* @private
*/
private computeDistToAff;
/**
* @private
*/
private updateRadius;
/**
* The main function containing the main loop.
*
* Iteratively, we compute the point in support that is closest to the current center and then
* walk towards this target as far as we can, i.e., we move until some new point touches the
* boundary of the ball and must thus be inserted into support.
*
* In each of these two alternating phases, we always have to check whether some point must be dropped from support,
* which is the case when the center lies in <i>aff(support)</i>.
* If such an attempt to drop fails, we are done; because then the center lies even <i>conv(support)</i>.
* @private
*/
private compute;
/**
* If center doesn't already lie in <i>conv(support)</i> and is thus not optimal yet,
* {@link successfulDrop()} elects a suitable point <i>k</i> to be removed from the support and
* returns true. If the center lies in the convex hull, however, false is returned (and the
* support remains unaltered).
*
* Precondition: center lies in <i>aff(support)</i>.
* @return {boolean}
*/
successfulDrop(): boolean;
/**
* Given the center of the current enclosing ball and the walking direction `centerToAff`,
* determine how much we can walk into this direction without losing a point from <i>S</i>.
*
* The (positive) factor by which we can walk along `centerToAff` is returned.
* Further, `stopper` is set to the index of the most restricting point and to -1 if no such point was found.
* @return {number}
* @private
*/
private findStopFraction;
/**
* Outputs information about the Miniball
* @return {string}
*/
toString(): string;
}
import { Subspan } from "./Subspan.js";
//# sourceMappingURL=Miniball.d.ts.map