/*
 * [CalcSize.java]
 *
 * Summary: Calculate dimensions of a screen.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2012-12-15
 */
package com.mindprod.example;

import java.text.DecimalFormat;

import static java.lang.System.*;

/**
 * Calculate dimensions of a screen.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2012-12-15
 * @since 2012-12-15
 */
public final class CalcSize
    {
    private static final DecimalFormat DF1 = new DecimalFormat( "###,##0.0" );

    private static final DecimalFormat DF2 = new DecimalFormat( "###,##0.00" );

    /**
     * Calculate dimensions of a screen.
     *
     * @param args diagonal in inches, width is pixels, height in pixels.
     */
    public static void main( String[] args )
        {
        final double diagonalIn = Double.parseDouble( args[ 0 ] );
        final double diagonalCm = diagonalIn * 2.54;
        final int widthPx = Integer.parseInt( args[ 1 ] );
        final int heightPx = Integer.parseInt( args[ 2 ] );
        final double widthIn = Math.sqrt( ( diagonalIn * diagonalIn )
                                          / ( 1. + ( ( double ) heightPx * heightPx )
                                                   / ( ( double ) widthPx * widthPx ) ) );
        final double heightIn = Math.sqrt( ( diagonalIn * diagonalIn )
                                           / ( 1. + ( ( double ) widthPx * widthPx )
                                                    / ( ( double ) heightPx * heightPx ) ) );
        final double widthCm = widthIn * 2.54;
        final double heightCm = heightIn * 2.54;
        out.println( "diagonal: " + DF2.format( diagonalIn ) + " inches " + DF1.format( diagonalCm ) + " cm" );
        out.println( "width x height "
                     + widthPx + " x " + heightPx + " pixels "
                     + DF2.format( widthIn ) + " x " + DF2.format( heightIn ) + " inches "
                     + DF1.format( widthCm ) + " x " + DF1.format( heightCm ) + " cm" );
        out.println( "\ndiagonal: <span class=\"metric\">"
                     + DF1.format( diagonalCm )
                     + " cm</span>, <span class=\"imperial\">"
                     + DF2.format( diagonalIn )
                     + " inches</span>,\n"
                     + "width &times; height <span class=\"times\">"
                     + widthPx
                     + " &times; "
                     + heightPx
                     + "</span> pixels,\n<span class=\"metric\">"
                     + DF1.format( widthCm )
                     + " &times; "
                     + DF1.format( heightCm )
                     + " cm</span>,\n"
                     + "<span class=\"imperial\">("
                     + DF2.format( widthIn )
                     + " &times; "
                     + DF2.format( heightIn )
                     + " inches)</span>"
        );
        }
    }