import { Utils } from '../common/Utils'
import { BasePoints } from './BasePoints';

/**
 * PixelLineSegments - 像素线段
 * 
 * 场景中带有点和颜色的像素线段,可用于多点间的像素级线段绘制。
 * 
 * @class PixelLineSegments
 * @memberof THING
 * @extends THING.BasePoints
 * @public
 * 
 * @example
 * const segs = new THING.PixelLineSegments({
 *   points: [[0, 0, 0], [3, 0, 0], [3, 0, 3]],
 * });
 */
class PixelLineSegments extends BasePoints {

	static defaultTagArray = ['Line'];

	/**
	 * 场景中带有点和颜色的像素线段。
	 * @param {object} param 初始参数。
	 * 参数与 {@link THING.BasePoints} 的构造函数相同。
	 * 请在 {@link THING.BasePoints} 的文档中查看构造函数部分以获取详细参数列表。
	 * @constructor
	 * @public
	 */
	constructor(param = {}) {
		super(param);
	}

	// #region Private Functions

	_updateSize(bodyNode, points) {
		if (bodyNode.getSize() < points.length) {
			bodyNode.setSize(points.length * 2);
		}
	}

	// #endregion

	// #region Overrides

	onCreateBodyNode(param) {
		const node = Utils.createObject('LineSegments', { app: this.app });
		return node;
	}

	onSetupBodyNode(node) {
		this._updateSize(node, this._selfPoints);
		node.setPoints(this._selfPoints);
	}

	onGetSelfPoints(selfPoints) {
		this._updateSize(this.bodyNode, selfPoints);

		return selfPoints;
	}

	onRefreshPoints() {
		let points = super.onRefreshPoints();

		this._updateSize(this.bodyNode, points);

		this.bodyNode.setColors(points.map(point => { return [1, 1, 1]; }));
	}

	// #endregion

	// #region Accessor

	// #endregion

	/**
	 * 检查是否为PixelLineSegments类型或继承自该类型。
	 * @type {boolean}
	 */
	get isPixelLineSegments() {
		return true;
	}

}

export { PixelLineSegments }