RegionPath.java

package com.varnernet.gerb4j.render;

import com.varnernet.gerb4j.ApertureTransform;
import com.varnernet.gerb4j.Mirror;
import com.varnernet.gerb4j.Polarity;

import java.awt.geom.Path2D;

/**
 * Represents a region path from G36/G37 (region boundary statements). Captures the region path and
 * the graphics-state snapshot at the time it was closed.
 *
 * <p>All fields are immutable (final). The graphics-state snapshot is grouped into an {@link
 * ApertureTransform}.
 */
public final class RegionPath implements GerberOperation {

    private final Path2D.Double path;
    private final Polarity polarity;
    private final ApertureTransform transform;

    /**
     * Constructs a RegionPath with separate transform components.
     *
     * @param path      the region path
     * @param polarity  the polarity
     * @param mirroring the mirroring
     * @param rotation  the rotation
     * @param scaling   the scaling
     */
    public RegionPath(
            final Path2D.Double path, final Polarity polarity, final Mirror mirroring, final Double rotation, final Double scaling) {
        this(path, polarity, new ApertureTransform(mirroring, rotation, scaling));
    }

    /**
     * Primary constructor.
     *
     * @param path      the region path
     * @param polarity  the polarity
     * @param transform the aperture transform
     */
    public RegionPath(final Path2D.Double path, final Polarity polarity, final ApertureTransform transform) {
        this.path = path;
        this.polarity = polarity;
        this.transform = transform != null ? transform : ApertureTransform.IDENTITY;
    }

    // ── Accessors ─────────────────────────────────────────────────────────────

    /**
     * Returns the region path.
     *
     * @return the path
     */
    public Path2D.Double getPath() {
        return path;
    }

    /**
     * Returns the polarity.
     *
     * @return the polarity
     */
    public Polarity getPolarity() {
        return polarity;
    }

    /**
     * Returns the full aperture-transform snapshot for this region.
     *
     * @return the aperture transform
     */
    public ApertureTransform getApertureTransform() {
        return transform;
    }

    // ── Legacy accessors ──────────────────────────────────────────────────────

    /**
     * Returns the mirroring.
     *
     * @return the mirroring
     */
    public Mirror getMirroring() {
        return transform.mirroring();
    }

    /**
     * Returns the rotation.
     *
     * @return the rotation
     */
    public Double getRotation() {
        return transform.rotation();
    }

    /**
     * Returns the scaling.
     *
     * @return the scaling
     */
    public Double getScaling() {
        return transform.scaling();
    }
}