import { Utils } from '../common/Utils';
import { MathUtils } from '../math/MathUtils';
import { BaseLine } from './BaseLine';
/**
* @class FatLine
* The fat line object.
* @memberof THING
* @extends THING.BaseLine
* @public
*/
class FatLine extends BaseLine {
_width = 1;
_cornerThreshold = 0.4;
static defaultTagArray = ['Line'];
/**
* The fat line object in scene.
* @param {Object} param The initial parameters.
*/
constructor(param = {}) {
super(param);
this._syncOptions(param);
}
// #region Private Functions
_syncOptions(param) {
this.begin();
{
super.onSyncOptions(param);
Utils.syncOptions(this, [
'width',
'cornerThreshold'
], param, param['extras'] || param['external']);
}
this.end();
}
// #endregion
// #region Overrides
onBeforeSetup(param) {
param['renderableNode'] = param['renderableNode'] || Utils.createObject('FatLine');
super.onBeforeSetup(param);
}
onAfterSetup(param) {
super.onAfterSetup(param);
}
onRefreshAttributes() {
let bodyNode = this.bodyNode;
bodyNode.setWidth(this._width);
bodyNode.setCornerThreshold(this._cornerThreshold);
}
onImportExternalData(external, options) {
super.onImportExternalData(external, options);
if (external) {
this._syncOptions(external);
}
}
onExportExternalData() {
let external = Object.assign({}, super.onExportExternalData());
Utils.setAttributeIfExist(external, 'width', this);
Utils.setAttributeIfExist(external, 'cornerThreshold', this);
return external;
}
// #endregion
// #region Accessor
/**
* Get/Set width.
* @type {Number}
* @public
*/
get width() {
return this._width;
}
set width(value) {
this._width = value;
this.bodyNode.setWidth(this._width);
}
/**
* Get/Set corner threshold in (0, 1].
* @type {Number}
* @public
*/
get cornerThreshold() {
return this._cornerThreshold;
}
set cornerThreshold(value) {
this._cornerThreshold = MathUtils.clamp(value, 0.1, 1);
this.bodyNode.setCornerThreshold(this._cornerThreshold);
}
// #endregion
get isFatLine() {
return true;
}
}
export { FatLine }