xtorcga
Version:
Xtor Compute Geometry Algorithm Libary 计算几何算法库
110 lines (109 loc) • 3.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Box = void 0;
var Vec3_1 = require("../../math/Vec3");
var _vector = new Vec3_1.Vec3();
var Box = /** @class */ (function () {
function Box(min, max) {
if (min === void 0) { min = Vec3_1.v3(Infinity, Infinity, Infinity); }
if (max === void 0) { max = Vec3_1.v3(-Infinity, -Infinity, -Infinity); }
this._center = Vec3_1.v3();
this.min = min;
this.max = max;
// if (points) {
// this.setFromPoints(points);
// }
}
Object.defineProperty(Box.prototype, "center", {
get: function () {
return this._center.add(this.min, this.max).multiplyScalar(0.5);
},
enumerable: false,
configurable: true
});
/**
*
* @param {Array<Vec3>} points
*/
Box.prototype.setFromPoints = function (points) {
this.min.set(Infinity, Infinity, Infinity);
this.max.set(-Infinity, -Infinity, -Infinity);
this.expand.apply(this, points);
};
Box.prototype.expand = function () {
var points = [];
for (var _i = 0; _i < arguments.length; _i++) {
points[_i] = arguments[_i];
}
for (var i = 0; i < points.length; i++) {
var point = points[i];
this.min.min(point);
this.max.max(point);
}
this.center.addVecs(this.min, this.max).multiplyScalar(0.5);
};
Box.prototype.makeEmpty = function () {
this.min.x = this.min.y = this.min.z = +Infinity;
this.max.x = this.max.y = this.max.z = -Infinity;
return this;
};
Box.prototype.clone = function () {
return new Box().copy(this);
};
Box.prototype.copy = function (box) {
this.min.copy(box.min);
this.max.copy(box.max);
return this;
};
Box.prototype.setFromCenterAndSize = function (center, size) {
var halfSize = _vector.copy(size).multiplyScalar(0.5);
this.min.copy(center).sub(halfSize);
this.max.copy(center).add(halfSize);
return this;
};
Box.prototype.setFromBufferAttribute = function (attribute) {
var minX = +Infinity;
var minY = +Infinity;
var minZ = +Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
var maxZ = -Infinity;
for (var i = 0, l = attribute.count; i < l; i++) {
var x = attribute.getX(i);
var y = attribute.getY(i);
var z = attribute.getZ(i);
if (x < minX)
minX = x;
if (y < minY)
minY = y;
if (z < minZ)
minZ = z;
if (x > maxX)
maxX = x;
if (y > maxY)
maxY = y;
if (z > maxZ)
maxZ = z;
}
this.min.set(minX, minY, minZ);
this.max.set(maxX, maxY, maxZ);
return this;
};
Box.prototype.expandByPoint = function (point) {
this.min.min(point);
this.max.max(point);
return this;
};
Box.prototype.isEmpty = function () {
return (this.max.x < this.min.x) || (this.max.y < this.min.y) || (this.max.z < this.min.z);
};
Box.prototype.getCenter = function (target) {
if (target === undefined) {
console.warn('THREE.Box3: .getCenter() target is now required');
target = new Vec3_1.Vec3();
}
return this.isEmpty() ? target.set(0, 0, 0) : target.addVecs(this.min, this.max).multiplyScalar(0.5);
};
return Box;
}());
exports.Box = Box;