@itwin/core-common
Version:
iTwin.js components common to frontend and backend
49 lines • 2.37 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Geometry
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BoundingSphere = void 0;
const core_geometry_1 = require("@itwin/core-geometry");
/** Describes a spherical volume of space as an approximation of the shape of some more complex geometric entity fully contained within that volume.
* When performing tests for intersection or containment, the approximation can be used as a first, quick check.
* @see [[FrustumPlanes.computeContainment]], for example.
* @public
*/
class BoundingSphere {
/** The point at the center of the sphere. */
center;
/** The radius of the sphere. */
radius;
/** Create a new bounding sphere with the specified center and radius. */
constructor(center = core_geometry_1.Point3d.createZero(), radius = 0) {
this.center = center;
this.radius = radius;
}
/** Change the center and radius of the sphere. */
init(center, radius) {
this.center = center;
this.radius = radius;
}
/** Applies the specified transformation matrix to produce a new bounding sphere.
* @param transform The transformation matrix to apply.
* @param result An optional preallocated object to hold the result, to avoid allocating a new object. May be the same object as `this`.
* @returns A bounding sphere equivalent to `this` with the specified transform applied.
*/
transformBy(transform, result) {
result = result ?? new BoundingSphere();
transform.multiplyPoint3d(this.center, result.center);
result.radius = this.radius * Math.max(transform.matrix.columnXMagnitude(), Math.max(transform.matrix.columnYMagnitude(), (transform.matrix.columnZMagnitude())));
return result;
}
/** Apply the specified transform to this bounding sphere. */
transformInPlace(transform) {
this.transformBy(transform, this);
}
}
exports.BoundingSphere = BoundingSphere;
//# sourceMappingURL=BoundingSphere.js.map