package Ui;

import java.awt.*;

public class ControlPoint extends Point {

    public static final int PT_SIZE = 4;

    public double weight = 1.0;

    public int multiplicity ;


    public ControlPoint(int a, int b) { 

	super(a, b);

	weight = 1.0;

	multiplicity = 1;

    }

    public ControlPoint(int a, int b, double weight, int mult) {

	super(a, b);

	this.weight = weight;

	this.multiplicity = mult;
    } 


    public void ChangeMultiplicity(int change){

	 multiplicity = Math.max(multiplicity+change,1);//the minimal multiplicity is one

    }


    public void ChangeWeight(double change){

	 weight = Math.max(weight+change,-1);

	 if ( weight == 0 ){weight+=0.001;}
    }


    public boolean within(int a, int b) {
	/* checks if the given coordinates (a,b) lie within the square that
	   represents the controlpoint */


        if (a >= this.x - PT_SIZE &&

            b >= this.y - PT_SIZE &&

            a <= this.x + PT_SIZE &&

            b <= this.y + PT_SIZE)

            return true; 

        else 

            return false; 

    } 

   public boolean Coincides(ControlPoint point){
	/* checks if the coordinates of the given controlpoint 'point' lie within the square
	   that represents the controlpoint */

	if ( this.within(point.x, point.y) ) {return true;}

	else return false;

   }


   public ControlPoint Clone(){

	return new ControlPoint(this.x, this.y, this.weight, this.multiplicity);

   }

}


