// Program: 3055 // Author: Manuel J. A. Eugster ( e0126312@student.tuwien.ac.at ) // FileId: $Id: Rgb.java,v 1.1.1.1 2001/12/10 18:56:04 heder Exp $ import java.lang.*; import eprog.*; import RGBSystem; import RGBRectangle; // CLASS: // Uses class RGBSystem and RGBRectangle to calculate the // normalized distance from a real point to the redcuction // rectangle // public class Rgb extends EprogIO { // METHOD: // Reads three integer values for red, green and blue. // Checks if they are correct. // private static int [] readInput() { int [] iRGB = new int[3]; // Semantic check // try { iRGB[0] = readInt(); iRGB[1] = readInt(); iRGB[2] = readInt(); } catch ( EprogException e ) { iRGB[0] = -1; iRGB[1] = -1; iRGB[2] = -1; return( iRGB ); } // Range check // if ( ( iRGB[0] < 0 || iRGB[0] > 256 ) || ( iRGB[1] < 0 || iRGB[1] > 256 ) || ( iRGB[2] < 0 || iRGB[2] > 256 ) ) { iRGB[0] = -2; iRGB[1] = -2; iRGB[2] = -2; return( iRGB ); } return( iRGB ); } // METHOD: // Evaluates the input. If it's correct it creates a new RGBSystem with a // reduction and calculates the normalized distance between real point and // the rectangel // public static void main( String [] args ) throws EprogException { int [] iRGB = readInput(); if ( iRGB[0] == -1 ) { print( "?\n" ); } else if ( iRGB[0] == -2 ) { print( "FALSCHE EINGABE\n" ); } else { RGBSystem cRGBSpace = new RGBSystem(); // Create new color space ( 255, 255, 255 ) cRGBSpace.setReduction( 7, 7, 3 ); // Set reduction RGBRectangle cRect = cRGBSpace.createRect( iRGB[0], iRGB[1], iRGB[2] ); // Create rectangle with real point double [] dNormDist = cRect.normDistance(); // Get normalized distance // Output // for ( int i = 0; i < 8; i++ ) { printFixed( dNormDist[i] ); if ( i < 7 ) { print( " " ); } else { print( "\n" ); } } } return; } }