import { assert } from "../../../assert.js";

export class PointSet {
    /**
     *
     * @param {number} size number of points
     * @param {number} dimensions number of dimensions per point
     * @param {Array|Float32Array|Float64Array} data
     * @constructor
     */
    constructor(size, dimensions, data) {
        assert.isNonNegativeInteger(size, 'size');
        assert.isNonNegativeInteger(dimensions, 'dimensions');
        assert.isArrayLike(data, 'data');

        /**
         *
         * @type {Array|Float32Array|Float64Array}
         * @private
         */
        this.__data = data;
        /**
         *
         * @type {number}
         * @private
         */
        this.__size = size;
        /**
         *
         * @type {number}
         * @private
         */
        this.__dimensions = dimensions;
    }

    /**
     * Number of points in the set
     * @returns {number}
     */
    size() {
        return this.__size;
    }

    /**
     * Number of dimensions for each point
     * @returns {number}
     */
    dimension() {
        return this.__dimensions;
    }

    /**
     * get coordinate for a point
     * @param {number} i point index
     * @param {number} j dimension
     * @returns {number}
     */
    coord(i, j) {
        return this.__data[i * this.__dimensions + j];
    }
}
