Mirror.java

package com.varnernet.gerb4j;

/**
 * Mirror transformation options for apertures and blocks. Defined by the Load Mirroring (LM)
 * command in the Gerber specification.
 */
public enum Mirror {
    /**
     * No mirroring applied.
     */
    NONE("N"),
    /**
     * Mirror about X-axis.
     */
    X("X"),
    /**
     * Mirror about Y-axis.
     */
    Y("Y"),
    /**
     * Mirror about both X and Y axes.
     */
    XY("XY");

    private final String code;

    Mirror(final String code) {
        this.code = code;
    }

    /**
     * Get the Gerber specification code for this mirror value.
     *
     * @return the code (N, X, Y, or XY)
     */
    public String getCode() {
        return code;
    }

    /**
     * Parse a mirror value from the Gerber specification code.
     *
     * @param code the Gerber code (N, X, Y, or XY)
     * @return the corresponding Mirror enum value
     * @throws IllegalArgumentException if the code is not recognized
     */
    public static Mirror fromCode(final String code) {
        return switch (code) {
            case "N" -> NONE;
            case "X" -> X;
            case "Y" -> Y;
            case "XY" -> XY;
            default -> throw new IllegalArgumentException("Invalid mirror code: " + code);
        };
    }
}