import { Mesh } from "./Mesh";
import { MeshBuilder } from "../builders/MeshBuilder";

/**
 * Cylinder - 圆柱体
 *
 * 用于创建圆柱体模型,支持上下不同半径(可制作圆台)、高度和分段数。
 * @class Cylinder
 * @memberof THING
 * @extends THING.Mesh
 * @public
 * @example
 * const cylinder = new THING.Cylinder({
 *   radiusTop: 0.5,
 *   radiusBottom: 1,
 *   height: 2,
 *   radialSegments: 32,
 *   position: [0, 1, 0],
 * });
 */
class Cylinder extends Mesh {

	/**
	 * @public
	 * 圆柱体
	 * @param {CylinderParam} param The initial parameters.
	 */
	constructor(param = {}) {
		param['data'] = MeshBuilder.createCylinder(param);
		param['instanceGroupName'] = param['instanceGroupName'] || 'Cylinder';
		super(param);
	}

	/**
	 * 获取圆柱体的顶部半径
	 * @type {number}
	 * @public
	 */
	get radiusTop() {
		return this.options.radiusTop !== undefined ? this.options.radiusTop : 1;
	}

	/**
	 * 获取圆柱体的底部半径
	 * @type {number}
	 * @public
	 */
	get radiusBottom() {
		return this.options.radiusBottom !== undefined ? this.options.radiusBottom : 1;
	}

	/**
	 * 获取圆柱体的高度
	 * @type {number}
	 * @public
	 */
	get height() {
		return this.options.height !== undefined ? this.options.height : 2;
	}

	/**
	 * 获取圆柱体的径向分段数
	 * @type {number}
	 * @public
	 */
	get radialSegments() {
		return this.options.radialSegments !== undefined ? this.options.radialSegments : 64;
	}

	/**
	 * 获取圆柱体的高度分段数
	 * @type {number}
	 * @public
	 */
	get heightSegments() {
		return this.options.heightSegments !== undefined ? this.options.heightSegments : 1;
	}

	/**
	 * 获取圆柱体是否为开放式
	 * @type {boolean}
	 * @public
	 */
	get openEnded() {
		return this.options.openEnded !== undefined ? this.options.openEnded : false;
	}

	/**
	 * 获取圆柱体的起始角度
	 * @type {number}
	 * @public
	 */
	get thetaStart() {
		return this.options.thetaStart !== undefined ? this.options.thetaStart : 0;
	}

	/**
	 * 获取圆柱体的角度长度
	 * @type {number}
	 * @public
	 */
	get thetaLength() {
		return this.options.thetaLength !== undefined ? this.options.thetaLength : MathUtils.PI * 2;
	}

	/**
	 * 获取圆柱体的位置长度
	 * @type {number}
	 * @public
	 */
	get poslength() {
		return this.options.poslength !== undefined ? this.options.poslength : 0;
	}

}

export {
	Cylinder
}