Select Git revision
Circle.java
Forked from
COUETOUX Basile / graphic-2020
4 commits ahead of the upstream repository.
-
MANSOUR Chadi authored
Tested and is working
MANSOUR Chadi authoredTested and is working
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Circle.java 993 B
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;
public Circle(double x, double y, double radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
@Override
public void paint(GraphicsContext graphicsContext) {
graphicsContext.setStroke(Color.RED);
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;
}
public void updateRadius(double newX, double newY) {
this.radius = Math.sqrt(Math.pow(newX - this.x, 2) + Math.pow(newY - this.y, 2));
}
}