diff --git a/src/main/java/shape/tp5/Rectangle.java b/src/main/java/shape/tp5/Rectangle.java new file mode 100644 index 0000000000000000000000000000000000000000..a86216966de1cfea5c6426939e787ea28eb468e3 --- /dev/null +++ b/src/main/java/shape/tp5/Rectangle.java @@ -0,0 +1,29 @@ +package shape.tp5; +import javafx.scene.canvas.GraphicsContext; + +public class Rectangle implements Shape { + private double x, y, width, height; + + public Rectangle(double x, double y, double width, double height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + @Override + public void paint(GraphicsContext graphicsContext) { + graphicsContext.strokeRect(x, y, width, height); + } + + @Override + public boolean contains(double px, double py) { + return px >= x && px <= x + width && py >= y && py <= y + height; + } + + @Override + public void translate(double dx, double dy) { + this.x += dx; + this.y += dy; + } +}