/*
File: swSquare.js
Date: 2026-02-20
Author: klp
Workspace: SketchWaveTNT2026-02-19-Stg4
Purpose: SWSquare class for SketchWaveJS
Comment(s):

This class represents a square with equal width and height, extending SWRectangle.
It is designed to be compatible with p5.js, SWColor, SWPoint, and SWGrid.
Dependencies: SWRectangle, SWPoint, SWColor, SWGrid, p5.js

*/  

console.log("[swSquare.js] SWSquare class loaded.");

class SWSquare extends SWRectangle {
    /**
     * @param {SWPoint} center - Center point of the square (SWPoint)
     * @param {number} size - Side length of the square
     * @param {SWColor} fillColor - Fill color (SWColor instance)
     * @param {Object} [options] - Optional: {strokeColor, strokeWeight, showVertices, showCenter, rotation}
     *   strokeColor: SWColor for border (optional)
     *   strokeWeight: number for border thickness (optional, default 2)
     *   showVertices: boolean (default false) - show corner points
     *   showCenter: boolean (default false) - show center point
     *   rotation: number (default 0) - initial rotation in degrees (CCW)
     */
    constructor(center, size, fillColor, options = {}) {
        // Call parent constructor with size for both width and height
        super(center, size, size, fillColor, options);
        
        // Store size for convenience
        this.size = size;
    }//end constructor

    /**
     * Getter for side length (alias for size)
     * @returns {number} Side length
     */
    get sideLength() {
        return this.size;
    }//end sideLength

    /**
     * Getter for diagonal length of the square
     * @returns {number} Diagonal = size × √2
     */
    get diagonal() {
        return this.size * Math.sqrt(2);
    }//end diagonal

    /**
     * Getter for inscribed circle radius (incircle)
     * @returns {number} Radius = size / 2
     */
    get inscribedCircleRadius() {
        return this.size / 2;
    }//end inscribedCircleRadius

    /**
     * Getter for circumscribed circle radius (circumcircle)
     * @returns {number} Radius = size × √2 / 2
     */
    get circumscribedCircleRadius() {
        return this.size * Math.sqrt(2) / 2;
    }//end circumscribedCircleRadius

    /**
     * Converts the square to a rhombus by rotating 45 degrees
     * Returns a new SWSquare rotated 45°
     * @returns {SWSquare} New square rotated 45° (appears as a diamond)
     */
    toRhombus() {
        const rhombusRotation = (this.rotation + 45) % 360;
        return new SWSquare(
            new SWPoint(this.rCenter.x, this.rCenter.y, undefined, this.rCenter.strokeWeight, this.rCenter.strokeColor),
            this.size,
            this.fillColor,
            {
                strokeColor: this.strokeColor,
                strokeWeight: this.strokeWeight,
                showVertices: this.showVertices,
                showCenter: this.showCenter,
                rotation: rhombusRotation
            }
        );
    }//end toRhombus

    /**
     * String representation
     */
    toString() {
        return `SWSquare(center: ${this.rCenter.toString()}, size: ${this.size.toFixed(2)}, area: ${this.area.toFixed(2)}, rotation: ${this.rotation}°)`;
    }//end toString
}//end class SWSquare

// Export for module use (if needed)
// export default SWSquare;
