package com.srbenoit.geom;

import com.srbenoit.sparsearray.SparseArray;

/**
 * An array of points that supports addition and deletion of points, but will not change the index
 * of a point once added. That is, deleting points makes the array sparse, and adding new points
 * may fill in gaps left by deleting points before appending to the end of the array. Storage is
 * allocated in blocks of fixed size as needed to add points.
 */
public class Point3Array extends SparseArray<Point3Int> {

    /**
     * Constructs a new <code>Point3Array</code> with a default capacity.
     */
    public Point3Array() {

        this(16);
    }

    /**
     * Constructs a new <code>Point3Array</code> with capacity for a specified number of points.
     * Use this constructor if you know how many points will ultimately be added to the array.
     *
     * @param  initialSize  the initial capacity of array to allocate
     */
    public Point3Array(final int initialSize) {

        super(Point3Int.class, initialSize);
    }

    /**
     * Transforms the points in this list into another list using a given transformation matrix. It
     * is assumed that the target array contains the same number and arrangement of points as this
     * list.
     *
     * @param  target     the array into which to transform the points
     * @param  transform  the transformation matrix
     */
    public void transformInto(final Point3Array target, final Transform3 transform) {

        int len;

        len = capacity();

        for (int i = 0; i < len; i++) {

            if (isFilled(i)) {
                transform.transformPoint(get(i), target.get(i));
            }
        }
    }
}
