xrvg 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +34 -0
- data/README +2 -2
- data/Rakefile +111 -29
- data/examples/bezierbasic.rb +7 -0
- data/examples/bezierbasicvector.rb +7 -0
- data/examples/foreach.rb +1 -1
- data/examples/geodash.rb +8 -0
- data/examples/geodash2.rb +8 -0
- data/examples/hellocrown.rb +1 -1
- data/examples/hellocrown2.rb +1 -1
- data/examples/hellocrownrecurse.rb +1 -1
- data/examples/multibezierbasic.rb +8 -0
- data/examples/randomdash.rb +8 -0
- data/examples/range_examples.rb +16 -0
- data/examples/range_examples2.rb +10 -0
- data/examples/sample.rb +4 -2
- data/examples/simpledash.rb +8 -0
- data/examples/uplets.rb +1 -1
- data/lib/bezier.rb +461 -0
- data/lib/bezierspline.rb +266 -0
- data/lib/color.rb +44 -5
- data/lib/geometry2D.rb +116 -90
- data/lib/interpolation.rb +4 -2
- data/lib/samplation.rb +16 -10
- data/lib/shape.rb +101 -53
- data/lib/style.rb +13 -12
- data/lib/utils.rb +4 -3
- data/lib/xrvg.rb +2 -3
- data/test/test_bezier.rb +151 -0
- data/test/test_geometry2D.rb +38 -25
- data/test/test_shape.rb +67 -0
- data/test/test_utils.rb +45 -0
- metadata +28 -14
- data/examples/helloworld.rb +0 -5
    
        data/test/test_geometry2D.rb
    CHANGED
    
    | @@ -2,75 +2,88 @@ require 'test/unit' | |
| 2 2 | 
             
            require 'geometry2D.rb'
         | 
| 3 3 |  | 
| 4 4 | 
             
            # Test class
         | 
| 5 | 
            -
            class  | 
| 5 | 
            +
            class V2DTest < Test::Unit::TestCase
         | 
| 6 6 |  | 
| 7 7 | 
             
              def test_indice
         | 
| 8 | 
            -
                s =  | 
| 9 | 
            -
                assert_equal(1, s | 
| 10 | 
            -
                assert_equal(0, s | 
| 8 | 
            +
                s = V2D[0,1]
         | 
| 9 | 
            +
                assert_equal(1, s.y)
         | 
| 10 | 
            +
                assert_equal(0, s.x)
         | 
| 11 11 | 
             
              end
         | 
| 12 12 |  | 
| 13 13 | 
             
              def test_add
         | 
| 14 | 
            -
                s =  | 
| 15 | 
            -
                t =  | 
| 16 | 
            -
                assert_equal( | 
| 14 | 
            +
                s = V2D[0,1]
         | 
| 15 | 
            +
                t = V2D[2,3]
         | 
| 16 | 
            +
                assert_equal(V2D[2,4], s + t)
         | 
| 17 17 | 
             
              end
         | 
| 18 18 |  | 
| 19 19 | 
             
              def test_norm
         | 
| 20 | 
            -
                assert_equal( | 
| 20 | 
            +
                assert_equal(V2D[0,1], V2D[0,2].norm)
         | 
| 21 21 | 
             
              end
         | 
| 22 22 |  | 
| 23 23 | 
             
              def test_angle
         | 
| 24 | 
            -
                assert_equal(0.0,   | 
| 25 | 
            -
                assert_equal(0.0,   | 
| 26 | 
            -
                assert_equal(Math::PI * 0.5,  | 
| 27 | 
            -
                assert_equal(-Math::PI * 0.5,  | 
| 24 | 
            +
                assert_equal(0.0,  V2D[0,0].angle)
         | 
| 25 | 
            +
                assert_equal(0.0,  V2D[1,0].angle)
         | 
| 26 | 
            +
                assert_equal(Math::PI * 0.5, V2D[0,1].angle)
         | 
| 27 | 
            +
                assert_equal(-Math::PI * 0.5, V2D[0,-1].angle)
         | 
| 28 28 | 
             
              end
         | 
| 29 29 |  | 
| 30 30 | 
             
              def test_mean
         | 
| 31 | 
            -
                assert_equal( | 
| 31 | 
            +
                assert_equal(V2D[0,1], (V2D[0,0]..V2D[0,2]).middle)
         | 
| 32 32 | 
             
              end
         | 
| 33 33 |  | 
| 34 34 | 
             
              def test_length
         | 
| 35 | 
            -
                assert_equal(1, | 
| 35 | 
            +
                assert_equal(1,V2D[0,1].length)
         | 
| 36 36 | 
             
              end
         | 
| 37 37 |  | 
| 38 38 | 
             
              def test_interpol
         | 
| 39 | 
            -
                assert_equal( | 
| 39 | 
            +
                assert_equal(V2D[0.2,1.4], (V2D[0.0, 1.0]..V2D[1.0, 3.0]).sample( 0.2 ))
         | 
| 40 40 | 
             
              end
         | 
| 41 41 |  | 
| 42 42 | 
             
              def test_createwithpoints
         | 
| 43 43 |  | 
| 44 | 
            -
                assert_equal( | 
| 44 | 
            +
                assert_equal(V2D[1,1], V2D[1,1] - V2D[0,0])
         | 
| 45 45 |  | 
| 46 46 | 
             
              end
         | 
| 47 47 |  | 
| 48 48 | 
             
              def test_ortho
         | 
| 49 | 
            -
                assert_equal( | 
| 50 | 
            -
            		  | 
| 49 | 
            +
                assert_equal(V2D[-0.6,0.5],
         | 
| 50 | 
            +
            		 V2D[0.5,0.6].ortho)
         | 
| 51 51 | 
             
              end
         | 
| 52 52 |  | 
| 53 53 | 
             
              def test_reverse
         | 
| 54 | 
            -
                assert_equal( | 
| 55 | 
            -
            		  | 
| 54 | 
            +
                assert_equal(V2D[-0.6,-0.5],
         | 
| 55 | 
            +
            		 V2D[0.6,0.5].reverse)
         | 
| 56 56 | 
             
              end
         | 
| 57 57 |  | 
| 58 58 | 
             
              def test_viewbox
         | 
| 59 59 | 
             
                assert_equal( [1.0, 1.0, 2.0, 2.0],
         | 
| 60 | 
            -
            		  | 
| 60 | 
            +
            		 V2D.viewbox( [V2D[1.0, 2.0], V2D[2.0, 1.0]] ))
         | 
| 61 61 | 
             
              end
         | 
| 62 62 |  | 
| 63 63 | 
             
              def test_size
         | 
| 64 64 | 
             
                assert_equal( [1.0, 1.0],
         | 
| 65 | 
            -
            		  | 
| 65 | 
            +
            		 V2D.size( [V2D[1.0, 2.0], V2D[2.0, 1.0]] ))
         | 
| 66 66 | 
             
              end
         | 
| 67 67 |  | 
| 68 68 | 
             
              def test_operation_sequences
         | 
| 69 | 
            -
                assert_equal( | 
| 70 | 
            -
            		  | 
| 69 | 
            +
                assert_equal(V2D[0.0,1.0],
         | 
| 70 | 
            +
            		 V2D[1.0,0.0].norm.ortho)
         | 
| 71 71 | 
             
              end
         | 
| 72 72 |  | 
| 73 73 | 
             
              def test_inner_product
         | 
| 74 | 
            -
                assert_equal( 1.0,  | 
| 74 | 
            +
                assert_equal( 1.0, V2D[1.0, 0.0].inner_product( V2D[1.0,1.0] ) )
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              def test_vequal
         | 
| 78 | 
            +
                assert( V2D.vequal?( V2D::O, V2D::X * 0.0 ) ) 
         | 
| 79 | 
            +
                assert( V2D.vequal?( V2D::O, V2D::O + V2D::X * 0.01, 0.1 ) )
         | 
| 80 | 
            +
                assert_equal( false, V2D.vequal?( V2D::O, V2D::O + V2D::X * 0.01, 0.001 ) )
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              def test_pointer
         | 
| 84 | 
            +
                v = V2D[1.0,2.0]
         | 
| 85 | 
            +
                a = v
         | 
| 86 | 
            +
                a.x = 3.0
         | 
| 87 | 
            +
                assert_equal( 3.0, v.x )
         | 
| 75 88 | 
             
              end
         | 
| 76 89 | 
             
            end
         | 
    
        data/test/test_shape.rb
    ADDED
    
    | @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            require 'shape'
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class ShapeTest < Test::Unit::TestCase
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def test_abstract
         | 
| 7 | 
            +
                # Shape.new.svg
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
             | 
| 13 | 
            +
            class LineTest <  Test::Unit::TestCase
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def test_point
         | 
| 16 | 
            +
                line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0] ] ]
         | 
| 17 | 
            +
                # puts Line.instance_methods(false)
         | 
| 18 | 
            +
                assert_equal( V2D[0.0, 0.3], line.point( 0.3 ) )
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def test_tangent
         | 
| 22 | 
            +
                line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 2.0] ] ]
         | 
| 23 | 
            +
                assert_equal( V2D[0.0, 1.0], line.tangent( 0.3 ) )
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def test_frame
         | 
| 27 | 
            +
                line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0] ] ]
         | 
| 28 | 
            +
                result = Frame[ :center, V2D[0.0,0.5], :vector,  V2D[0.0,0.0], :rotation,  0.0, :scale, 1.0 ]
         | 
| 29 | 
            +
                assert_equal( result, line.frame( 0.5 ) )
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
             | 
| 33 | 
            +
              def test_svg
         | 
| 34 | 
            +
                line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0], V2D[ 0.0, 2.0] ] ]
         | 
| 35 | 
            +
                assert_equal( '<path d="M 0.0 0.0 L 0.0 1.0L 0.0 2.0"/>', line.svg )
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              def test_samples
         | 
| 39 | 
            +
                [Line[].samples(3), [V2D[0.0,0.0], V2D[0.5,0.5], V2D[1.0,1.0]] ].forzip do |v1, v2|
         | 
| 40 | 
            +
                  assert( V2D.vequal?( v1, v2 ) )
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
            end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            class CircleTest < Test::Unit::TestCase
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              def test_default
         | 
| 48 | 
            +
                circle = Circle[]
         | 
| 49 | 
            +
                assert_equal( '<circle cx="0.0" cy="0.0" r="1.0"/>', circle.svg )
         | 
| 50 | 
            +
              end    
         | 
| 51 | 
            +
             | 
| 52 | 
            +
              def test_svg
         | 
| 53 | 
            +
                circle = Circle[ :center, V2D[ 0.0, 0.0 ], :radius, 1.0 ]
         | 
| 54 | 
            +
                assert_equal( '<circle cx="0.0" cy="0.0" r="1.0"/>', circle.svg )
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              def test_viewbox
         | 
| 58 | 
            +
                circle = Circle[ :center, V2D[ 0.0, 0.0 ], :radius, 1.0 ]
         | 
| 59 | 
            +
                assert_equal( [-1.0, -1.0, 1.0, 1.0], circle.viewbox )
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              def test_samples
         | 
| 63 | 
            +
                [Circle[].samples(3), [V2D[1.0,0.0], V2D[-1.0,0.0], V2D[1.0,0.0]] ].forzip do |v1, v2|
         | 
| 64 | 
            +
                  assert( V2D.vequal?( v1, v2 ) )
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
            end
         | 
    
        data/test/test_utils.rb
    CHANGED
    
    | @@ -58,6 +58,17 @@ end | |
| 58 58 |  | 
| 59 59 | 
             
            class ArrayTest < Test::Unit::TestCase
         | 
| 60 60 |  | 
| 61 | 
            +
              def test_samples
         | 
| 62 | 
            +
                assert_equal( [0.0, 1.0, 0.5, 0.5, 1.0, 0.0], [(0.0..1.0), (1.0..0.0)].samples(3))
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              def test_samples2
         | 
| 66 | 
            +
                result = []
         | 
| 67 | 
            +
                [(0.0..1.0), (1.0..0.0)].samples(3) {|v1,v2| result += [v1,v2] }
         | 
| 68 | 
            +
                assert_equal( [0.0, 1.0, 0.5, 0.5, 1.0, 0.0], result )
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
              
         | 
| 71 | 
            +
             | 
| 61 72 | 
             
              def test_pairs
         | 
| 62 73 | 
             
                a = [ 1, 2, 3]
         | 
| 63 74 | 
             
                b = Array.new
         | 
| @@ -81,6 +92,12 @@ class ArrayTest < Test::Unit::TestCase | |
| 81 92 | 
             
                assert_equal( [1, 2, 3], [0, 1, 2, 3].[](1..-1) )
         | 
| 82 93 | 
             
              end
         | 
| 83 94 |  | 
| 95 | 
            +
              def test_slice2
         | 
| 96 | 
            +
                a = [0, 1, 2, 3]
         | 
| 97 | 
            +
                assert_equal( [1, 2, 3], a[1..-1] )
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
             | 
| 84 101 | 
             
              def test_uplets
         | 
| 85 102 | 
             
                assert_equal( [[1, 2], [2, 3]], [1, 2, 3].uplets(2) )
         | 
| 86 103 | 
             
                result = [];     [1, 2, 3].uplets {|i,j| result.push( [i,j] )}
         | 
| @@ -170,6 +187,34 @@ class RangeTest  < Test::Unit::TestCase | |
| 170 187 | 
             
                # assert_equal( [0.0, 0.5, 1.0], (0.0..1.0).bisamples([0.5, 0.5]) )
         | 
| 171 188 | 
             
                # assert_equal( [0.0, 0.4, 0.5, 0.9, 1.0], (0.0..1.0).bisamples([0.4, 0.1]) )
         | 
| 172 189 | 
             
              end
         | 
| 190 | 
            +
             | 
| 191 | 
            +
              def test_ranges
         | 
| 192 | 
            +
                # Samplable module
         | 
| 193 | 
            +
                assert_equal( 1.5, (1.0..2.0).sample(0.5) )
         | 
| 194 | 
            +
                assert_equal( [1.0, 1.5, 2.0], (1.0..2.0).samples( 3 ) )
         | 
| 195 | 
            +
                assert_equal( 1.5, (1.0..2.0).mean )
         | 
| 196 | 
            +
                assert_equal( 1.5, (1.0..2.0).middle )
         | 
| 197 | 
            +
                assert( (1.0..2.0).rand >= 1.0 )
         | 
| 198 | 
            +
                assert( (1.0..2.0).rand <= 2.0 )
         | 
| 199 | 
            +
                assert_equal( 2, (1.0..2.0).rand( 2 ).length )
         | 
| 200 | 
            +
                assert_equal( 1.8, (1.0..2.0).complement(1.2) )
         | 
| 201 | 
            +
                assert_equal( 0.5, (1.0..2.0).abscissa(1.5) )
         | 
| 202 | 
            +
             | 
| 203 | 
            +
                # Splittable module
         | 
| 204 | 
            +
                assert_equal( (1.2..1.3), (1.0..2.0).split(0.2,0.3) )
         | 
| 205 | 
            +
                assert_equal( [(1.0..1.5),(1.5..2.0)], (1.0..2.0).splits( 2 ) )
         | 
| 206 | 
            +
              end
         | 
| 207 | 
            +
             | 
| 208 | 
            +
              def test_ranges2
         | 
| 209 | 
            +
                assert_equal( (0.0..1.0), Range.O  )
         | 
| 210 | 
            +
                assert_equal( (0.0..2.0*Math::PI), Range.Angle  )
         | 
| 211 | 
            +
                assert_equal( (2.0..1.0), (1.0..2.0).reverse  )
         | 
| 212 | 
            +
                assert_equal( (0.0..2.0), (1.0..2.0).sym  )
         | 
| 213 | 
            +
                assert_equal( (1.0..3.0), (1.0..2.0).symend  )
         | 
| 214 | 
            +
                assert_equal( 1.0, (1.0..2.0).size  )
         | 
| 215 | 
            +
                assert_equal( (1.3..2.3), (1.0..2.0).translate(0.3)  )
         | 
| 216 | 
            +
              end
         | 
| 217 | 
            +
             | 
| 173 218 | 
             
            end
         | 
| 174 219 |  | 
| 175 220 | 
             
            class SampleClass
         | 
    
        metadata
    CHANGED
    
    | @@ -3,8 +3,8 @@ rubygems_version: 0.9.0 | |
| 3 3 | 
             
            specification_version: 1
         | 
| 4 4 | 
             
            name: xrvg
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 0.0. | 
| 7 | 
            -
            date: 2008-02- | 
| 6 | 
            +
              version: 0.0.2
         | 
| 7 | 
            +
            date: 2008-02-10 00:00:00 +01:00
         | 
| 8 8 | 
             
            summary: Ruby vector graphics library
         | 
| 9 9 | 
             
            require_paths: 
         | 
| 10 10 | 
             
            - lib
         | 
| @@ -29,18 +29,12 @@ post_install_message: | |
| 29 29 | 
             
            authors: 
         | 
| 30 30 | 
             
            - "Julien L\xE9onard"
         | 
| 31 31 | 
             
            files: 
         | 
| 32 | 
            -
            -  | 
| 33 | 
            -
            -  | 
| 34 | 
            -
            - ./examples/hellocrown2.rb
         | 
| 35 | 
            -
            - ./examples/hellocrownrecurse.rb
         | 
| 36 | 
            -
            - ./examples/helloworld.rb
         | 
| 37 | 
            -
            - ./examples/helloworldcompact.rb
         | 
| 38 | 
            -
            - ./examples/helloworldexpanded.rb
         | 
| 39 | 
            -
            - ./examples/palette_circle.rb
         | 
| 40 | 
            -
            - ./examples/sample.rb
         | 
| 41 | 
            -
            - ./examples/uplets.rb
         | 
| 32 | 
            +
            - Rakefile
         | 
| 33 | 
            +
            - LICENCE
         | 
| 42 34 | 
             
            - lib/assertion.rb
         | 
| 43 35 | 
             
            - lib/attributable.rb
         | 
| 36 | 
            +
            - lib/bezier.rb
         | 
| 37 | 
            +
            - lib/bezierspline.rb
         | 
| 44 38 | 
             
            - lib/color.rb
         | 
| 45 39 | 
             
            - lib/frame.rb
         | 
| 46 40 | 
             
            - lib/geometry2D.rb
         | 
| @@ -52,15 +46,34 @@ files: | |
| 52 46 | 
             
            - lib/trace.rb
         | 
| 53 47 | 
             
            - lib/utils.rb
         | 
| 54 48 | 
             
            - lib/xrvg.rb
         | 
| 55 | 
            -
            -  | 
| 56 | 
            -
            -  | 
| 49 | 
            +
            - examples/bezierbasic.rb
         | 
| 50 | 
            +
            - examples/bezierbasicvector.rb
         | 
| 51 | 
            +
            - examples/foreach.rb
         | 
| 52 | 
            +
            - examples/geodash.rb
         | 
| 53 | 
            +
            - examples/geodash2.rb
         | 
| 54 | 
            +
            - examples/hellocrown.rb
         | 
| 55 | 
            +
            - examples/hellocrown2.rb
         | 
| 56 | 
            +
            - examples/hellocrownrecurse.rb
         | 
| 57 | 
            +
            - examples/helloworldcompact.rb
         | 
| 58 | 
            +
            - examples/helloworldexpanded.rb
         | 
| 59 | 
            +
            - examples/multibezierbasic.rb
         | 
| 60 | 
            +
            - examples/palette_circle.rb
         | 
| 61 | 
            +
            - examples/randomdash.rb
         | 
| 62 | 
            +
            - examples/range_examples.rb
         | 
| 63 | 
            +
            - examples/range_examples2.rb
         | 
| 64 | 
            +
            - examples/sample.rb
         | 
| 65 | 
            +
            - examples/simpledash.rb
         | 
| 66 | 
            +
            - examples/uplets.rb
         | 
| 57 67 | 
             
            - README
         | 
| 68 | 
            +
            - CHANGES
         | 
| 58 69 | 
             
            test_files: 
         | 
| 59 70 | 
             
            - test/test_attributable.rb
         | 
| 71 | 
            +
            - test/test_bezier.rb
         | 
| 60 72 | 
             
            - test/test_color.rb
         | 
| 61 73 | 
             
            - test/test_frame.rb
         | 
| 62 74 | 
             
            - test/test_geometry2D.rb
         | 
| 63 75 | 
             
            - test/test_render.rb
         | 
| 76 | 
            +
            - test/test_shape.rb
         | 
| 64 77 | 
             
            - test/test_style.rb
         | 
| 65 78 | 
             
            - test/test_utils.rb
         | 
| 66 79 | 
             
            rdoc_options: 
         | 
| @@ -70,6 +83,7 @@ rdoc_options: | |
| 70 83 | 
             
            - README
         | 
| 71 84 | 
             
            extra_rdoc_files: 
         | 
| 72 85 | 
             
            - README
         | 
| 86 | 
            +
            - CHANGES
         | 
| 73 87 | 
             
            executables: []
         | 
| 74 88 |  | 
| 75 89 | 
             
            extensions: []
         |