Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • revert-d81c9d6d
2 results

Circle.java

Blame
  • Forked from COUETOUX Basile / graphic-2020
    4 commits ahead of the upstream repository.
    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));
        }
    
    }