package shape;

import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

public class Circle implements Shape {

    private double radius, x, y;
    private Color fillColor;

    public Circle(double x, double y, double radius) {
        this.x = x;
        this.y = y;
        this.radius = radius;
        this.fillColor = Color.GREEN;
    }


    @Override
    public void paint(GraphicsContext graphicsContext) {
        graphicsContext.setStroke(Color.BLACK);
        if(isFinished) {
            graphicsContext.setFill(Color.GREEN);
            graphicsContext.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
        }
        graphicsContext.strokeOval(x-radius, y-radius, 2 * radius, 2 * radius);
    }

    @Override
    public boolean contains(double x, double y) {
        double dx = x - this.x;
        double dy = y - this.y;
        return Math.sqrt(dx*dx + dy*dy) <= radius;
    }

    @Override
    public void translate(double dx, double dy) {
        this.x += dx;
        this.y += dy;
    }

    @Override
    public boolean isFinished() {
        return true;
    }

    public void updateRadius(double newX, double newY) {
        this.radius = Math.sqrt(Math.pow(newX - this.x, 2) + Math.pow(newY - this.y, 2));
    }

    public void setFillColor(Color fillColor) {
        this.fillColor = fillColor;
    }
}