dyi 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -119,8 +119,7 @@ module DYI #:nodoc:
119
119
  end
120
120
 
121
121
  def write_path(shape, io)
122
- # attrs = {:d => shape.concise_path_data}
123
- attrs = {:d => shape.compatible_path_data.to_concise_syntax}
122
+ attrs = {:d => shape.concise_path_data}
124
123
  attrs.merge!(common_attributes(shape))
125
124
  create_leaf_node(io, 'path', attrs)
126
125
  end
data/lib/dyi/shape.rb CHANGED
@@ -117,7 +117,7 @@ module DYI #:nodoc:
117
117
  end
118
118
 
119
119
  def set_clipping_shapes(*shapes)
120
- @clipping = Drawing::Compositing::Clip.new(*shapes)
120
+ @clipping = Drawing::Clipping.new(*shapes)
121
121
  end
122
122
 
123
123
  private
@@ -852,7 +852,7 @@ module DYI #:nodoc:
852
852
  end
853
853
 
854
854
  def last_point
855
- (relative? && preceding_command.nil?) ? preceding_command : super
855
+ (relative? && preceding_command.nil?) ? point : super
856
856
  end
857
857
 
858
858
  def relative?
@@ -1135,11 +1135,16 @@ module DYI #:nodoc:
1135
1135
  @relative = relative
1136
1136
  @preceding_command = preceding_command
1137
1137
  @point = Coordinate.new(point)
1138
- @rx = Length.new(rx)
1139
- @ry = Length.new(ry)
1140
1138
  @rotation = rotation
1141
1139
  @is_large_arc = is_large_arc
1142
1140
  @is_clockwise = is_clockwise
1141
+ @rx = Length.new(rx).abs
1142
+ @ry = Length.new(ry).abs
1143
+ l = (modified_mid_point.x.to_f / @rx.to_f) ** 2 + (modified_mid_point.y.to_f / @ry.to_f) ** 2
1144
+ if 1 < l
1145
+ @rx *= Math.sqrt(l)
1146
+ @ry *= Math.sqrt(l)
1147
+ end
1143
1148
  end
1144
1149
 
1145
1150
  def large_arc?
@@ -1151,6 +1156,7 @@ module DYI #:nodoc:
1151
1156
  end
1152
1157
 
1153
1158
  def to_compatible_commands(preceding_command)
1159
+ return LineCommand.new(relative?, preceding_command, point) if rx.zero? || ry.zero?
1154
1160
  division_count = (center_angle / 30.0).ceil
1155
1161
  division_angle = center_angle / division_count * (clockwise? ? 1 : -1)
1156
1162
  current_point = start_angle_point
@@ -1163,12 +1169,16 @@ module DYI #:nodoc:
1163
1169
  end
1164
1170
  control_point1 = control_point_of_curve(current_point, division_angle, true)
1165
1171
  control_point2 = control_point_of_curve(end_point, division_angle, false)
1166
- preceding_command = CurveCommand.new(relative?,
1167
- preceding_command,
1168
- control_point1,
1169
- control_point2,
1170
- (i == division_count - 1) ?
1171
- point : transform_orginal_shape(end_point))
1172
+ path_point = (i == division_count - 1) ? point : transform_orginal_shape(end_point)
1173
+ if relative?
1174
+ control_point1 += preceding_point
1175
+ control_point2 += preceding_point
1176
+ path_point += preceding_point
1177
+ end
1178
+ preceding_command = CurveCommand.absolute_commands(preceding_command,
1179
+ control_point1,
1180
+ control_point2,
1181
+ path_point).first
1172
1182
  compat_commands << preceding_command
1173
1183
  current_point = end_point
1174
1184
  end
@@ -1185,13 +1195,15 @@ module DYI #:nodoc:
1185
1195
  end
1186
1196
 
1187
1197
  def center_point
1188
- Matrix.rotate(rotation).transform(modified_center_point) + (preceding_point + point) * 0.5
1198
+ st_pt = relative? ? Coordinate::ZERO : preceding_point
1199
+ Matrix.rotate(rotation).transform(modified_center_point) + (st_pt + point) * 0.5
1189
1200
  end
1190
1201
 
1191
1202
  private
1192
1203
 
1193
1204
  def modified_mid_point
1194
- Matrix.rotate(-rotation).transform((preceding_point - point) * 0.5)
1205
+ st_pt = relative? ? Coordinate::ZERO : preceding_point
1206
+ Matrix.rotate(-rotation).transform((st_pt - point) * 0.5)
1195
1207
  end
1196
1208
 
1197
1209
  def modified_center_point
@@ -1234,7 +1246,15 @@ module DYI #:nodoc:
1234
1246
 
1235
1247
  class << self
1236
1248
  def commands(relative, preceding_command, *args)
1237
- new(relative, preceding_command, *args)
1249
+ raise ArgumentError, "number of arguments must be a multipule of 6" if args.size % 6 != 0
1250
+ cmd = preceding_command
1251
+ args.each_slice(6).inject([]) do |cmds, ars|
1252
+ if ars[0].zero? || ars[1].zero?
1253
+ cmds << (cmd = LineCommand.new(relative, cmd, ars.last))
1254
+ else
1255
+ cmds << (cmd = new(relative, cmd, *ars))
1256
+ end
1257
+ end
1238
1258
  end
1239
1259
  end
1240
1260
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yuo
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-30 00:00:00 Z
18
+ date: 2011-07-15 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: " DYI is a 2D graphics library, very rich and expressive.\n DYI have been optimized for SVG format, but it is also possible\n to output other format; for example, EPS.\n"