xrvg 0.0.3 → 0.0.4
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 +21 -0
- data/README +3 -3
- data/Rakefile +4 -4
- data/examples/bezierbasic.rb +1 -0
- data/examples/bezierbasicvector.rb +1 -0
- data/examples/foreach.rb +1 -0
- data/examples/geodash.rb +1 -0
- data/examples/geodash2.rb +1 -0
- data/examples/hellocrown.rb +1 -0
- data/examples/hellocrown2.rb +1 -0
- data/examples/hellocrownrecurse.rb +1 -0
- data/examples/helloworldcompact.rb +1 -0
- data/examples/helloworldexpanded.rb +1 -0
- data/examples/multibezierbasic.rb +1 -0
- data/examples/palette_circle.rb +1 -0
- data/examples/randomdash.rb +1 -0
- data/examples/range_examples.rb +1 -0
- data/examples/range_examples2.rb +1 -0
- data/examples/sample.rb +1 -0
- data/examples/simpledash.rb +1 -0
- data/examples/uplets.rb +1 -0
- data/lib/bezier.rb +21 -55
- data/lib/bezierbuilders.rb +194 -0
- data/lib/beziermotifs.rb +114 -0
- data/lib/bezierspline.rb +20 -75
- data/lib/beziertools.rb +211 -0
- data/lib/color.rb +26 -7
- data/lib/fitting.rb +203 -0
- data/lib/frame.rb +2 -1
- data/lib/geometry2D.rb +6 -5
- data/lib/interbezier.rb +87 -0
- data/lib/interpolation.rb +6 -5
- data/lib/parametriclength.rb +87 -0
- data/lib/render.rb +4 -9
- data/lib/samplation.rb +71 -82
- data/lib/shape.rb +47 -25
- data/lib/style.rb +2 -1
- data/lib/trace.rb +2 -0
- data/lib/utils.rb +111 -17
- data/lib/xrvg.rb +16 -6
- data/test/test_attributable.rb +34 -2
- data/test/test_bezier.rb +93 -2
- data/test/test_bezierbuilders.rb +92 -0
- data/test/test_beziertools.rb +97 -0
- data/test/test_color.rb +65 -24
- data/test/test_fitting.rb +47 -0
- data/test/test_frame.rb +7 -2
- data/test/test_geometry2D.rb +26 -7
- data/test/test_interbezier.rb +29 -0
- data/test/test_interpolation.rb +16 -1
- data/test/test_parametric_length.rb +15 -0
- data/test/test_render.rb +54 -6
- data/test/test_shape.rb +103 -10
- data/test/test_trace.rb +13 -0
- data/test/test_utils.rb +114 -12
- data/test/test_xrvg.rb +3 -0
- metadata +16 -5
- data/lib/assertion.rb +0 -14
- data/lib/attributable.rb +0 -152
data/test/test_xrvg.rb
ADDED
metadata
CHANGED
@@ -3,12 +3,12 @@ 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-
|
6
|
+
version: 0.0.4
|
7
|
+
date: 2008-03-16 00:00:00 +01:00
|
8
8
|
summary: Ruby vector graphics library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email:
|
11
|
+
email: julien.leonard@nospam@ensta.org
|
12
12
|
homepage: http://xrvg.rubyforge.org/
|
13
13
|
rubyforge_project: xrvg
|
14
14
|
description:
|
@@ -31,14 +31,18 @@ authors:
|
|
31
31
|
files:
|
32
32
|
- Rakefile
|
33
33
|
- LICENCE
|
34
|
-
- lib/assertion.rb
|
35
|
-
- lib/attributable.rb
|
36
34
|
- lib/bezier.rb
|
35
|
+
- lib/bezierbuilders.rb
|
36
|
+
- lib/beziermotifs.rb
|
37
37
|
- lib/bezierspline.rb
|
38
|
+
- lib/beziertools.rb
|
38
39
|
- lib/color.rb
|
40
|
+
- lib/fitting.rb
|
39
41
|
- lib/frame.rb
|
40
42
|
- lib/geometry2D.rb
|
43
|
+
- lib/interbezier.rb
|
41
44
|
- lib/interpolation.rb
|
45
|
+
- lib/parametriclength.rb
|
42
46
|
- lib/render.rb
|
43
47
|
- lib/samplation.rb
|
44
48
|
- lib/shape.rb
|
@@ -69,14 +73,21 @@ files:
|
|
69
73
|
test_files:
|
70
74
|
- test/test_attributable.rb
|
71
75
|
- test/test_bezier.rb
|
76
|
+
- test/test_bezierbuilders.rb
|
77
|
+
- test/test_beziertools.rb
|
72
78
|
- test/test_color.rb
|
79
|
+
- test/test_fitting.rb
|
73
80
|
- test/test_frame.rb
|
74
81
|
- test/test_geometry2D.rb
|
82
|
+
- test/test_interbezier.rb
|
75
83
|
- test/test_interpolation.rb
|
84
|
+
- test/test_parametric_length.rb
|
76
85
|
- test/test_render.rb
|
77
86
|
- test/test_shape.rb
|
78
87
|
- test/test_style.rb
|
88
|
+
- test/test_trace.rb
|
79
89
|
- test/test_utils.rb
|
90
|
+
- test/test_xrvg.rb
|
80
91
|
rdoc_options:
|
81
92
|
- --title
|
82
93
|
- XRVG API documentation
|
data/lib/assertion.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# assertion utility
|
2
|
-
# must be used with care, as expensive
|
3
|
-
#
|
4
|
-
class AssertionError < StandardError
|
5
|
-
end
|
6
|
-
|
7
|
-
#
|
8
|
-
# Assert method, to check for a block, and raise an error if check is not true
|
9
|
-
# Assert("1 is different from 0"){ 1 == 0}
|
10
|
-
def Assert(message=nil, &block)
|
11
|
-
unless(block.call)
|
12
|
-
raise AssertionError, (message || "Assertion failed")
|
13
|
-
end
|
14
|
-
end
|
data/lib/attributable.rb
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Module to be able to declare attribute, initializing them by default, with type checking
|
3
|
-
# also define syntaxically simpler builder
|
4
|
-
#
|
5
|
-
# See :
|
6
|
-
# - +Object+
|
7
|
-
# - +Attributable+
|
8
|
-
|
9
|
-
require 'utils'
|
10
|
-
|
11
|
-
#
|
12
|
-
# Object extension to provide the Class[] syntax for building objects, with +Attributable+ module.
|
13
|
-
#
|
14
|
-
# TODO : must be defined only for Class objects !!
|
15
|
-
class Object
|
16
|
-
|
17
|
-
# operator [] definition for shorter and more recognizable object creation syntax.
|
18
|
-
#
|
19
|
-
# Especially useful when creating Attributable dependant objects.
|
20
|
-
# c = Circle[ :center, p, :radius, 0.1 ]
|
21
|
-
def Object.[](*args)
|
22
|
-
return self.new( *args )
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
# Attribute class used by Attributable module
|
28
|
-
#
|
29
|
-
# Attribute syntax :
|
30
|
-
# attribute :attr1 default_value type
|
31
|
-
# with :
|
32
|
-
# - dvalue nil if no default_value (in that case, attribute is said to be required )
|
33
|
-
# - if type is not specified, default_value must be, and type will be the type of this default_value
|
34
|
-
# type can be an Array of types
|
35
|
-
class Attribute
|
36
|
-
attr_accessor :symbol, :default_value, :type
|
37
|
-
|
38
|
-
def initialize( symbol, default_value, type ) #:nodoc:
|
39
|
-
@symbol = symbol
|
40
|
-
@default_value = default_value
|
41
|
-
@type = type
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
# Attributable module
|
47
|
-
#
|
48
|
-
# Allows class attribute definition in a concise and effective way. Can be viewed as a :attr_accessor extension. See also +Attribute+
|
49
|
-
#
|
50
|
-
# Example :
|
51
|
-
# class A
|
52
|
-
# attribute :a 1.0; # type is then Float
|
53
|
-
# attribute :b # attribute is required
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# a = A[ :a, 10.0, :b, 2.0 ]
|
57
|
-
# a.a => 10.0
|
58
|
-
module Attributable
|
59
|
-
|
60
|
-
module ClassMethods #:nodoc:
|
61
|
-
def init_attributes
|
62
|
-
if not @attributes
|
63
|
-
@attributes = {}
|
64
|
-
newattributes = (self.superclass.ancestors.include? Attributable) ? self.superclass.attributes : {}
|
65
|
-
@attributes = @attributes.merge( newattributes )
|
66
|
-
else
|
67
|
-
# Trace("Attributable::init_attributes self #{self} already initialized")
|
68
|
-
end
|
69
|
-
# Trace("Attributable::init_attributes self #{self} superclass#{self.superclass} superclass ancestors #{self.superclass.ancestors.inspect} result #{@attributes}")
|
70
|
-
end
|
71
|
-
|
72
|
-
def add_attribute( attribute )
|
73
|
-
# Trace("Attributable::add_attribute self #{self} attribute #{attribute.inspect}")
|
74
|
-
init_attributes
|
75
|
-
@attributes[ attribute.symbol ] = attribute
|
76
|
-
end
|
77
|
-
|
78
|
-
def attributes()
|
79
|
-
init_attributes
|
80
|
-
# Trace("Attributable::attributes self #{self} attributes #{@attributes}")
|
81
|
-
return @attributes
|
82
|
-
end
|
83
|
-
|
84
|
-
def checkvaluetype( value, type )
|
85
|
-
typeOK = nil
|
86
|
-
types = type
|
87
|
-
types.each do |type|
|
88
|
-
if value.is_a? type
|
89
|
-
typeOK = true
|
90
|
-
break
|
91
|
-
end
|
92
|
-
end
|
93
|
-
if not typeOK
|
94
|
-
raise( "Attributable::checkvaluetype for class #{self} : default_value #{value.inspect} is not of type #{types.inspect}" )
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def attribute( symbol, default_value=nil, type=nil )
|
99
|
-
if (not type and default_value)
|
100
|
-
type = [default_value.class]
|
101
|
-
elsif type
|
102
|
-
if not type.is_a? Array
|
103
|
-
type = [type]
|
104
|
-
end
|
105
|
-
if default_value
|
106
|
-
checkvaluetype( default_value, type )
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
self.add_attribute( Attribute.new( symbol, default_value, type ) )
|
111
|
-
attr_accessor symbol
|
112
|
-
end
|
113
|
-
|
114
|
-
def instance_variable_set( *args )
|
115
|
-
# Trace("Attributable::instance_variable_set self #{self} args #{args}")
|
116
|
-
super( *args )
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def self.included( receiver ) #:nodoc:
|
121
|
-
# inherit_attributes; does not work because Module is not inherited by subclasses
|
122
|
-
receiver.extend( ClassMethods )
|
123
|
-
end
|
124
|
-
|
125
|
-
def initialize(*args) #:nodoc:
|
126
|
-
# first check if every specified attribute is meaningfull for the class
|
127
|
-
args.foreach do |symbol, value|
|
128
|
-
if not self.class.attributes.key? symbol
|
129
|
-
raise( "Attributable::initialize for class #{self} does not have attribute #{symbol}" )
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# then check specification coherence, and do initialization
|
134
|
-
spec = Hash[ *args ]
|
135
|
-
self.class.attributes.each_pair do |symbol, attr|
|
136
|
-
if spec.key? symbol
|
137
|
-
value = spec[ symbol ]
|
138
|
-
if attr.type
|
139
|
-
self.class.checkvaluetype( value, attr.type )
|
140
|
-
end
|
141
|
-
# do init after checking
|
142
|
-
self.method("#{symbol.to_s}=").call(value)
|
143
|
-
else
|
144
|
-
if not attr.default_value
|
145
|
-
raise( "Attributable::initialize for class #{self} : attribute #{symbol} is required : attributes #{self.class.attributes.inspect}" )
|
146
|
-
end
|
147
|
-
self.method("#{symbol.to_s}=").call(attr.default_value)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|