package org.glencross.raytrace;

public class Colour {

    public static final Colour WHITE = new Colour(1, 1, 1);
    public static final Colour RED = new Colour(1, 0, 0);
    public static final Colour BLACK = new Colour(0, 0, 0);
    public static final Colour GREEN = new Colour(0, 1, 0);
    public static final Colour GREY = new Colour(0.7, 0.7, 0.7);
    public static final Colour BLUE = new Colour(0, 0, 1);
    public static final Colour CYAN = new Colour(0, 1, 1);
    public static final Colour YELLOW = new Colour(1, 1, 0);
    public static final Colour ORANGE = new Colour(1, 153d/256, 0);


    private double r;
    private double g;
    private double b;

    public Colour(double r, double g, double b) {
        this.r = Math.min(1d, r);
        this.g = Math.min(1d, g);
        this.b = Math.min(1d, b);
    }

    public double getR() {
        return r;
    }

    public double getG() {
        return g;
    }

    public double getB() {
        return b;
    }

    public int toInt() {
        return (Math.min(255, (int)(r*255)) << 16) +
               (Math.min(255, (int)(g*255)) << 8) +
               (Math.min(255, (int)(b*255)));
    }

    public Colour times(Colour other) {
        return new Colour(other.r*r, other.g*g, other.b*b);
    }

    public Colour times(double factor) {
        return new Colour(r*factor, g*factor, b*factor);
    }

    public Colour add(Colour other) {
        return new Colour(
                Math.min(1, other.r+this.r),
                Math.min(1, other.g+this.g),
                Math.min(1, other.b+this.b));
    }
}

@@ -144,11 +144,12 @@
 our 
+G
 RE
-D
+Y
  = n
@@ -162,15 +162,21 @@
 our(
-1
+0.7
 , 0
+.7
 , 0
+.7
 );%0A 
@@ -269,13 +269,11 @@
 our 
-G
 RE
-EN
+D
  = n
@@ -282,20 +282,20 @@
  Colour(
-0, 1
+1, 0
 , 0);%0A  
@@ -315,36 +315,38 @@
 ic final Colour 
-GREY
+ORANGE
  = new Colour(0.
@@ -339,37 +339,38 @@
  new Colour(
-0.7, 0.7
+1, 153d/256
 , 0
-.7
 );%0A    publi
@@ -395,12 +395,14 @@
 our 
-BLUE
+YELLOW
  = n
@@ -415,15 +415,15 @@
 our(
-0, 0, 1
+1, 1, 0
 );%0A 
@@ -456,11 +456,12 @@
 our 
-CYA
+GREE
 N = 
@@ -473,25 +473,25 @@
 olour(0, 1, 
-1
+0
 );%0A    publi
@@ -504,38 +504,36 @@
 ic final Colour 
-YELLOW
+BLUE
  = new Colour(1,
@@ -522,39 +522,98 @@
 UE = new Colour(
-1
+0, 0, 1);%0A    public static final Colour CYAN = new Colour(0
 , 1, 
-0
+1
 );%0A    public st
@@ -622,38 +622,39 @@
 ic final Colour 
-ORANGE
+MAGENTA
  = new Colour(1,
@@ -658,24 +658,16 @@
 (1, 
-153d/256, 0
+0, 1
 );%0A%0A
-%0A
     
@@ -1085,30 +1085,17 @@
 return (
-Math.min(255, 
+(
 (int)(r*
@@ -1121,38 +1121,25 @@
            (
-Math.min(255, 
+(
 (int)(g*255)
@@ -1168,22 +1168,8 @@
    (
-Math.min(255, 
 (int
@@ -1177,17 +1177,16 @@
 (b*255))
-)
 ;%0A    %7D%0A
@@ -1474,36 +1474,24 @@
             
- Math.min(1,
  other.r+thi
@@ -1493,17 +1493,16 @@
 r+this.r
-)
 ,%0A      
@@ -1506,36 +1506,24 @@
             
- Math.min(1,
  other.g+thi
@@ -1525,17 +1525,16 @@
 g+this.g
-)
 ,%0A      
@@ -1546,20 +1546,8 @@
     
- Math.min(1,
  oth
@@ -1558,17 +1558,16 @@
 +this.b)
-)
 ;%0A    %7D%0A

Remove some redundant Math.min() calls.