Skip to content
Snippets Groups Projects
Coordinate.java 3.14 KiB
Newer Older
  • Learn to ignore specific revisions
  • Guyslain's avatar
    Guyslain committed
    package matrix;
    
    Guyslain's avatar
    Guyslain committed
    
    import java.util.List;
    
    
    /**
     * Represents a 2D integer coordinate used to specify positions in a grid.
     */
    
    Guyslain's avatar
    Guyslain committed
    public record Coordinate(int x, int y) {
    
    
        /**
         * Creates a new {@link Coordinate} instance with the given {@code x} and {@code y} values.
         *
         * @param x The x-coordinate value.
         * @param y The y-coordinate value.
         * @return A new {@link Coordinate} instance.
         */
    
    Guyslain's avatar
    Guyslain committed
        public static Coordinate of(int x, int y) {
    
    Guyslain's avatar
    Guyslain committed
            // TODO: compléter ce fabriquant
            return null;
    
    Guyslain's avatar
    Guyslain committed
        }
    
    
        /**
         * Computes and returns the {@link Coordinate} to the left of this one.
         *
         * @return The left adjacent {@link Coordinate}.
         */
    
    Guyslain's avatar
    Guyslain committed
        public Coordinate left() {
    
    Guyslain's avatar
    Guyslain committed
            // TODO: à compléter
            return null;
    
    Guyslain's avatar
    Guyslain committed
        }
    
    
        /**
         * Computes and returns the {@link Coordinate} to the right of this one.
         *
         * @return The right adjacent {@link Coordinate}.
         */
    
    Guyslain's avatar
    Guyslain committed
        public Coordinate right() {
    
    Guyslain's avatar
    Guyslain committed
            // TODO: à compléter
            return null;
    
    Guyslain's avatar
    Guyslain committed
        }
    
    
        /**
         * Computes and returns the {@link Coordinate} above this one.
         *
         * @return The above adjacent {@link Coordinate}.
         */
    
    Guyslain's avatar
    Guyslain committed
        public Coordinate above() {
    
    Guyslain's avatar
    Guyslain committed
            // TODO: à compléter
            return null;
    
    Guyslain's avatar
    Guyslain committed
        }
    
    
        /**
         * Computes and returns the {@link Coordinate} below this one.
         *
         * @return The below adjacent {@link Coordinate}.
         */
    
    Guyslain's avatar
    Guyslain committed
        public Coordinate below() {
    
    Guyslain's avatar
    Guyslain committed
            // TODO: à compléter
            return null;
    
    Guyslain's avatar
    Guyslain committed
        }
    
    
        /**
         * Computes and returns a list of orthogonal (adjacent in horizontal or vertical direction) neighbors.
    
    Guyslain's avatar
    Guyslain committed
         *  | | | |
         * ---------
         *  | |X| |
         * ---------
         *  |X|O|X|
         * ---------
         *  | |X| |
         * ---------
         * | | | |
    
         * @return A list of orthogonal neighboring {@link Coordinate}s.
         */
    
    Guyslain's avatar
    Guyslain committed
        public List<Coordinate> orthogonalNeighbours() {
    
    Guyslain's avatar
    Guyslain committed
            // TODO: à compléter
            return List.of();
    
    Guyslain's avatar
    Guyslain committed
        }
    
    
        /**
         * Computes and returns a list of diagonal (adjacent in diagonal direction) neighbors.
    
    Guyslain's avatar
    Guyslain committed
         *  | | | |
         * ---------
         *  |X| |X|
         * ---------
         *  | |O| |
         * ---------
         *  |X| |X|
         * ---------
         * | | | |
    
         *
         * @return A list of diagonal neighboring {@link Coordinate}s.
         */
    
    Guyslain's avatar
    Guyslain committed
        public List<Coordinate> diagonalNeighbours() {
    
    Guyslain's avatar
    Guyslain committed
            // TODO: à compléter
            return List.of();
    
    Guyslain's avatar
    Guyslain committed
        }
    
    
        /**
         * Computes and returns a list of all orthogonal and diagonal neighbors.
    
    Guyslain's avatar
    Guyslain committed
         *      *  | | | |
         *      * ---------
         *      *  |X|X|X|
         *      * ---------
         *      *  |X|O|X|
         *      * ---------
         *      *  |X|X|X|
         *      * ---------
         *      * | | | |
    
         *
         * @return A list of all neighboring {@link Coordinate}s.
         */
    
    Guyslain's avatar
    Guyslain committed
        public List<Coordinate> orthodiagonalNeighbours() {
    
    Guyslain's avatar
    Guyslain committed
            // TODO: à compléter
            return List.of();
    
    Guyslain's avatar
    Guyslain committed
        }
    
    
        @Override
        public String toString() {
            return "(" + this.x + "," + this.y + ")";
        }
    
    Guyslain's avatar
    Guyslain committed
    
      public Coordinate minus(Coordinate corner) {
        return new Coordinate(this.x - corner.x, this.y - corner.y);
      }
    
      public Coordinate plus(Coordinate corner) {
          return new Coordinate(this.x + corner.x, this.y + corner.y);
      }