import { MathUtils } from '../math/MathUtils';
import { BaseHelper } from './BaseHelper';
/**
* @class BaseBoxHelper
* The box helper object.
* @memberof THING
*/
class BaseBoxHelper extends BaseHelper {
// #region Override
onGetTopPoints(points) {
let top = {
lt: points[0],
rt: points[1],
rb: points[2],
lb: points[3],
};
return top;
}
onGetBottomPoints(points) {
let bottom = {
lt: points[4],
rt: points[5],
rb: points[6],
lb: points[7],
};
return bottom;
}
buildBox(boxPoints) {
let top = this.onGetTopPoints(boxPoints);
let bottom = this.onGetBottomPoints(boxPoints);
this._insertLine(top.lt, top.rt);
this._insertLine(top.rt, top.rb);
this._insertLine(top.rb, top.lb);
this._insertLine(top.lb, top.lt);
this._insertLine(bottom.lt, bottom.rt);
this._insertLine(bottom.rt, bottom.rb);
this._insertLine(bottom.rb, bottom.lb);
this._insertLine(bottom.lb, bottom.lt);
this._insertLine(top.lt, bottom.lt);
this._insertLine(top.rt, bottom.rt);
this._insertLine(top.rb, bottom.rb);
this._insertLine(top.lb, bottom.lb);
}
end() {
let _private = this.private;
// Update line
let lines = _private.lines;
lines.setSize(_private.points.length);
// Let line's position is center of points
let center = MathUtils.getCenterFromPoints(_private.points);
lines.setPosition(center);
// Make points to relative position
let relativePoints = _private.points.map(point => {
return MathUtils.subVector(point, center);
});
lines.setPoints(relativePoints);
lines.setColors(_private.colors);
}
// #endregion
}
export { BaseBoxHelper }