Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
No results found
Select Git revision
  • master
1 result
Show changes

Commits on Source 2

5 files
+ 99
7
Compare changes
  • Side-by-side
  • Inline

Files

Original line number Original line Diff line number Diff line
package shape;

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

public class BorderDecorator extends Decorator {
    private double radius;

    public BorderDecorator(Shape decoratedShape, double radius) {
        super(decoratedShape);
        this.radius = radius;
    }

    @Override
    protected void drawDecoration(GraphicsContext context) {
        context.setStroke(Color.RED);  // Couleur de la bordure
        for (int i = 0; i < decoratedShape.pointsCount(); i++) {
            Point2D point = decoratedShape.point(i);
            context.strokeOval(point.getX() - radius, point.getY() - radius, radius * 2, radius * 2);
        }
    }
}
Original line number Original line Diff line number Diff line
package shape;

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

public class CenterDecorator extends Decorator {
    private double radius;

    public CenterDecorator(Shape decoratedShape, double radius) {
        super(decoratedShape);
        this.radius = radius;
    }

    @Override
    protected void drawDecoration(GraphicsContext context) {
        context.setStroke(Color.BLUE);  // Couleur du cercle du centre
        // Calculer le centre de la forme
        Point2D center = calculateCenter();
        context.strokeOval(center.getX() - radius, center.getY() - radius, radius * 2, radius * 2);
    }

    // Méthode pour calculer le centre d'une forme
    private Point2D calculateCenter() {
        double sumX = 0, sumY = 0;
        for (int i = 0; i < decoratedShape.pointsCount(); i++) {
            Point2D point = decoratedShape.point(i);
            sumX += point.getX();
            sumY += point.getY();
        }
        return new Point2D(sumX / decoratedShape.pointsCount(), sumY / decoratedShape.pointsCount());
    }
}
+30 −0
Original line number Original line Diff line number Diff line
package shape;

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

public abstract class Decorator implements Shape {
    protected Shape decoratedShape;

    public Decorator(Shape decoratedShape) {
        this.decoratedShape = decoratedShape;
    }

    @Override
    public int pointsCount() {
        return decoratedShape.pointsCount();
    }

    @Override
    public Point2D point(int index) {
        return decoratedShape.point(index);
    }

    @Override
    public void draw(GraphicsContext context) {
        decoratedShape.draw(context);
        drawDecoration(context);  // Ajoute la décoration
    }

    protected abstract void drawDecoration(GraphicsContext context);  // Méthode abstraite pour la décoration
}
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@ import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.canvas.GraphicsContext;


public interface Shape {
public interface Shape {

    int pointsCount();
    int pointsCount();
    Point2D point(int index);
    Point2D point(int index);
    void draw(GraphicsContext context);
    void draw(GraphicsContext context);
Original line number Original line Diff line number Diff line
package shape;
package shape;


import javafx.scene.canvas.GraphicsContext;
import javafx.scene.canvas.GraphicsContext;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;


public class ShapeContainer {
public class ShapeContainer {

    // Liste pour stocker les formes
    private List<Shape> shapes = new ArrayList<>();
    private List<Shape> shapes = new ArrayList<>();


    public void addShape(Shape shape){}
    // Méthode pour ajouter une forme dans le conteneur
    public void add(Shape shape) {
        shapes.add(shape);  // Ajoute la forme à la liste
    }


    // Méthode pour dessiner toutes les formes
    public void draw(GraphicsContext context) {
    public void draw(GraphicsContext context) {
        for(Shape shape : shapes)
        for (Shape shape : shapes) {
            shape.draw(context);
            shape.draw(context);  // Appelle la méthode draw de chaque forme
        }
    }
    }
}
}