/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package colorsegmentation;

import baseclasses.Point;
import java.util.ArrayList;

/**
 *
 * @author Alex
 */
public class Cluster {
    
    /**
     * Points assigned to this cluster.
     */
    private final ArrayList<Point> points;
    
    /**
     * Centroid of the cluster.
     */
    private final Point centroid;
    
    /**
     * Cluster object for holding points.
     * @param cent Point for this cluster.
     */
    public Cluster(Point cent) {
        this.points = new ArrayList<Point>();
        this.centroid = cent;
    } 
    
    /**
     * Add a point to the cluster.
     * @param pt point to be added.
     */
    public void addPoint(Point pt) {
        this.points.add(pt);
    }
    
    /**
     * Get the points in this cluster.
     * @return an array of clusters.
     */
    public Point[] getPoints() {
        Point[] a = this.points.toArray(new Point[this.points.size()]);
        return a;
    }
    
    /**
     * Return the distance to the centroid of this cluster.
     * @param pt Point to calculate distance for. 
     * @return the distance.
     */
    public double distance(Point pt) {
        return Point.distance(this.centroid, pt);
    }
    
    /**
     * Check if cluster contains a Point.
     * @param pt point to check.
     * @return true if in Cluster.
     */
    public boolean contains(Point pt) {
        return this.points.contains(pt);
    }
    
    public Point newCent() {
        return Point.calculateAvgPt(this.getPoints());
    }
}
