[cairo-commit] rcairo/src/lib/cairo color.rb,1.2,1.3

Kouhei Sutou commit at pdx.freedesktop.org
Sun Apr 15 22:55:50 PDT 2007


Committed by: kou

Update of /cvs/cairo/rcairo/src/lib/cairo
In directory kemper:/tmp/cvs-serv6015/src/lib/cairo

Modified Files:
	color.rb 
Log Message:
* src/lib/cairo/color.rb: added validation.


Index: color.rb
===================================================================
RCS file: /cvs/cairo/rcairo/src/lib/cairo/color.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- color.rb	16 Apr 2007 04:52:44 -0000	1.2
+++ color.rb	16 Apr 2007 05:55:41 -0000	1.3
@@ -7,8 +7,17 @@
       alias_method :a=, :alpha=
 
       def initialize(a)
+        assert_in_range(a, "alpha channel")
         @alpha = a
       end
+
+      private
+      def assert_in_range(value, description)
+        unless (0.0..1.0).include?(value)
+          raise ArgumentError,
+                "#{description} value should be in [0.0, 1.0]: #{value.inspect}"
+        end
+      end
     end
 
     class RGB < Base
@@ -23,6 +32,9 @@
 
       def initialize(r, g, b, a=1.0)
         super(a)
+        assert_in_range(r, "red")
+        assert_in_range(g, "green")
+        assert_in_range(b, "blue")
         @red = r
         @green = g
         @blue = b
@@ -65,6 +77,10 @@
 
       def initialize(c, m, y, k, a=1.0)
         super(a)
+        assert_in_range(c, "cyan")
+        assert_in_range(m, "magenta")
+        assert_in_range(y, "yellow")
+        assert_in_range(k, "key plate")
         @cyan = c
         @magenta = m
         @yellow = y



More information about the cairo-commit mailing list