jenncad 1.0.0.pre.alpha13 → 1.0.0.pre.alpha14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4383fe5f1fe2d17d69eccd66bd28db4678281fd542bd13434064d4051044727
4
- data.tar.gz: 0eb4435e845c47ec9b75d113c04b7beae9ce762a2dfa57b598412a243ded0163
3
+ metadata.gz: beb1887d6ae1d3fc87da9c816de1cd2cb54ea5fb3ce7f1277ca6af8bcfc4e687
4
+ data.tar.gz: 5cc6fd0fc52de9b8b9087dfadd0387122014b157c9573b091aa7c4570a5f2c6a
5
5
  SHA512:
6
- metadata.gz: 35001c199911e59f66a2ef3ce3b8c6193e5654ebc5463f52add3cb11a5aa3c1684c51dbaad7a3edaf4c0042cf2b2d35410ea01bfdce45e5adc72a96f30ec002b
7
- data.tar.gz: 163e8e50aa1dd6ba930fd41e93075aca9f8bed93c6650f3a9984fbc86ddb34f0ae4a499d7fc981a38dfe9bdb1f56a0667a4cec018a530b701f4707141d79233c
6
+ metadata.gz: 8f86a697557b258219756ba02c0bb0e478d1c240c05fd53ecb1221749caedd4e7bf7c3395c439f9c0d426e33366d104e71c20a89bca894ee8e0c843733a0446d
7
+ data.tar.gz: 4ee555b106f36751024a876ece4880b3cea9138e606c541457a809828645f399f3a417cc0f40256e7363bf20f2b212a20f27166429337062a297caddb21931e1
@@ -16,6 +16,18 @@ module JennCad
16
16
  )
17
17
  end
18
18
 
19
+ # By default, jenncad will add coordinates of subsequent moves in the output
20
+ # i.e.
21
+ # .move(x: 10, y: 20).move(x: 10) would result depending on the value of this option:
22
+ #
23
+ # true = translate([10,20, 0])translate([10, 0, 0])
24
+ # false = translate([20, 20, 0])
25
+ #
26
+ # defaults to false
27
+ def chain_moves
28
+ false
29
+ end
30
+
19
31
  def colors
20
32
  case @colors
21
33
  when nil, []
@@ -45,11 +45,11 @@ module JennCad::Exporters
45
45
  def handle_command(i=1)
46
46
  case @children.size
47
47
  when 0
48
- "#{@modifier}#{@command}(#{handle_args});"
48
+ "#{@modifier}#{@command}(#{handle_args(@args)});"
49
49
  when 1
50
- "#{@modifier}#{@command}(#{handle_args})#{@children.first.handle_command(i+1)}"
50
+ "#{@modifier}#{@command}(#{handle_args(@args)})#{@children.first.handle_command(i+1)}"
51
51
  when (1..)
52
- res = "#{@modifier}#{@command}(#{handle_args}){"
52
+ res = "#{@modifier}#{@command}(#{handle_args(@args)}){"
53
53
  res += nl
54
54
  inner = @children.map do |c|
55
55
  next if c == nil
@@ -68,17 +68,19 @@ module JennCad::Exporters
68
68
  }.join(nl)
69
69
  end
70
70
 
71
- def handle_args
72
- case @args
71
+ def handle_args(args)
72
+ case args
73
73
  when String, Symbol
74
- return "\"#{@args}\""
74
+ return "\"#{args}\""
75
75
  when Array
76
- return @args.map do |l|
76
+ return args.map do |l|
77
77
  if l == nil
78
78
  0
79
79
  elsif l.kind_of? Array
80
80
  l # skipping check of 2-dmin Arrays for now (used in multmatrix)
81
- elsif l.to_i == l.to_f
81
+ elsif l == 0
82
+ 0
83
+ elsif l == l.to_i
82
84
  l.to_i
83
85
  else
84
86
  l.to_f
@@ -86,15 +88,19 @@ module JennCad::Exporters
86
88
  end
87
89
  when Hash
88
90
  res = []
89
- @args.each do |k,v|
91
+ args.each do |k,v|
90
92
  if k.to_s == "fn"
91
93
  k = "$fn"
92
94
  end
93
95
  if v == nil
94
96
  next
95
97
  end
96
- if !v.kind_of?(Array) && !v.kind_of?(TrueClass) && !v.kind_of?(FalseClass) && v == v.to_i
98
+ if v.kind_of?(Array)
99
+ v = handle_args(v)
100
+ elsif !v.kind_of?(TrueClass) && !v.kind_of?(FalseClass) && v == v.to_i
97
101
  v = v.to_i
102
+ elsif v.kind_of? BigDecimal
103
+ v = v.to_f
98
104
  end
99
105
  if v.kind_of? String
100
106
  q = "\""
@@ -64,7 +64,7 @@ module JennCad::Extras
64
64
  if show
65
65
  res.color("Gainsboro")
66
66
  thread_length=Data[@size][:thread_length]
67
- if total_length.to_f <= thread_length
67
+ if total_length.to_d <= thread_length
68
68
  res+= cylinder(d:@size+addtional_diameter, h:total_length).color("DarkGray")
69
69
  else
70
70
  res+= cylinder(d:@size+addtional_diameter, h:total_length-thread_length)
@@ -48,7 +48,7 @@ module JennCad::Extras
48
48
  14=> {head_side_to_side:22,head_length:9},
49
49
  16=> {head_side_to_side:24,head_length:10},
50
50
  }
51
- head_dia = chart[@size][:head_side_to_side].to_f + head_margin.to_f
51
+ head_dia = chart[@size][:head_side_to_side].to_d + head_margin.to_d
52
52
  res = cylinder(d:(head_dia/Math.sqrt(3))*2,fn:6,h:chart[@size][:head_length]).move(z:-chart[@size][:head_length])
53
53
  total_length = @length + additional_length
54
54
  res+= cylinder(d:@size+addtional_diameter, h:total_length)
@@ -36,7 +36,7 @@ module JennCad::Extras
36
36
 
37
37
  # ISO 7380
38
38
  def bolt_7380(additional_length=0, addtional_diameter=0, head_margin=0)
39
- if head_margin.to_f != 0
39
+ if head_margin.to_d != 0
40
40
  puts "[warning] :head_margin is not implemented for 7380 bolts"
41
41
  end
42
42
  chart_iso7380 = {
@@ -31,7 +31,7 @@ module JennCad::Features
31
31
  steps = @opts[:steps]
32
32
  (z / steps).floor
33
33
  else
34
- step.to_f
34
+ step.to_d
35
35
  end
36
36
  end
37
37
 
@@ -62,8 +62,8 @@ module JennCad::Features
62
62
 
63
63
  offset = get_offset(ref_z)
64
64
 
65
- lo = (ref_z-offset*2).to_f % step.to_f
66
- unless lo.to_f == 0.0
65
+ lo = (ref_z-offset*2).to_d % step.to_d
66
+ unless lo.to_d == 0.0
67
67
  puts "[Warning]: climb has leftover offset #{lo}"
68
68
  end
69
69
 
@@ -16,12 +16,12 @@ module JennCad::Features
16
16
 
17
17
  def prepare_cut(l, r, &block)
18
18
  part = block.call
19
- if part.z.to_f > 0.0
19
+ if part.z.to_d > 0.0
20
20
  part.opts[:margins][:z] = 0.2
21
21
  if l == 0.0
22
22
  part.mz(r+0.1)
23
23
  else
24
- part.mz(l+part.z.to_f-0.2)
24
+ part.mz(l+part.z.to_d-0.2)
25
25
  end
26
26
  else
27
27
  part.opts[:margins][:z] = 0.2
@@ -12,7 +12,7 @@ class Array
12
12
  else
13
13
  res = part
14
14
  end
15
- res, z = res.mz(z), z + res.z.to_f unless skip_z
15
+ res, z = res.mz(z), z + res.z.to_d unless skip_z
16
16
  res
17
17
  end
18
18
  .union
@@ -44,25 +44,25 @@ module JennCad::Primitives
44
44
  end
45
45
 
46
46
  def inherit_z
47
- heights = @parts.map{|l| l.calc_z.to_f}.uniq
47
+ heights = @parts.map{|l| l.calc_z.to_d}.uniq
48
48
  if heights.size > 1
49
49
  total_heights = []
50
50
  @parts.each do |p|
51
- total_heights << p.z.to_f + p.calc_z.to_f
51
+ total_heights << p.z.to_d + p.calc_z.to_d
52
52
  end
53
53
  @z = total_heights.max
54
54
  @calc_z = heights.min
55
55
  else
56
- @calc_z = heights.first.to_f
56
+ @calc_z = heights.first.to_d
57
57
  @z = @parts.map(&:z).compact.max
58
58
  end
59
59
  end
60
60
 
61
61
  def inherit_zref
62
62
  return if @parts.first == nil
63
- #return if @parts.first.z.to_f == 0.0
63
+ #return if @parts.first.z.to_d == 0.0
64
64
  get_primitives(@parts[1..-1]).flatten.each do |part|
65
- if part.z.to_f == 0.0
65
+ if part.z.to_d == 0.0
66
66
  part.set_option :zref, @parts.first
67
67
  end
68
68
  end
@@ -67,13 +67,13 @@ module JennCad::Primitives
67
67
  def handle_fn
68
68
  case @opts[:fn]
69
69
  when nil, 0
70
- $fn = auto_fn!
70
+ $fn = auto_dn!
71
71
  else
72
72
  @fn = @opts[:fn]
73
73
  end
74
74
  end
75
75
 
76
- def auto_fn!
76
+ def auto_dn!
77
77
  case @d
78
78
  when (16..)
79
79
  @fn = (@d*4).ceil
@@ -85,25 +85,25 @@ module JennCad::Primitives
85
85
  def handle_radius_diameter
86
86
  case @opts[:d]
87
87
  when 0, nil
88
- @r = @opts[:r].to_f + @opts[:margins][:r].to_f
88
+ @r = @opts[:r].to_d + @opts[:margins][:r].to_d
89
89
  @d = @r * 2.0
90
90
  else
91
- @d = @opts[:d].to_f + @opts[:margins][:d].to_f
91
+ @d = @opts[:d].to_d + @opts[:margins][:d].to_d
92
92
  @r = @d / 2.0
93
93
  end
94
94
 
95
95
  case @opts[:d1]
96
96
  when 0, nil
97
97
  else
98
- @d1 = @opts[:d1].to_f + @opts[:margins][:d].to_f
99
- @d2 = @opts[:d2].to_f + @opts[:margins][:d].to_f
98
+ @d1 = @opts[:d1].to_d + @opts[:margins][:d].to_d
99
+ @d2 = @opts[:d2].to_d + @opts[:margins][:d].to_d
100
100
  end
101
101
 
102
102
  case @opts[:r1]
103
103
  when 0, nil
104
104
  else
105
- @d1 = 2 * @opts[:r1].to_f + @opts[:margins][:d].to_f
106
- @d2 = 2 * @opts[:r2].to_f + @opts[:margins][:d].to_f
105
+ @d1 = 2 * @opts[:r1].to_d + @opts[:margins][:d].to_d
106
+ @d2 = 2 * @opts[:r2].to_d + @opts[:margins][:d].to_d
107
107
  end
108
108
  end
109
109
 
@@ -5,14 +5,14 @@ module JennCad::Primitives
5
5
  end
6
6
 
7
7
  def handle_margins
8
- @x = @opts[:x] + @opts[:margins][:x]
9
- @y = @opts[:y] + @opts[:margins][:y]
10
- @z = @opts[:z] + @opts[:margins][:z]
8
+ @x = @opts[:x].to_d + @opts[:margins][:x].to_d
9
+ @y = @opts[:y].to_d + @opts[:margins][:y].to_d
10
+ @z = @opts[:z].to_d + @opts[:margins][:z].to_d
11
11
  end
12
12
 
13
13
  def handle_diameter
14
- @d = opts[:d]
15
- @r = opts[:r]
14
+ @d = opts[:d].to_d
15
+ @r = opts[:r].to_d
16
16
  if @d
17
17
  @r = @d/2.0
18
18
  elsif @r
@@ -79,16 +79,16 @@ module JennCad::Primitives
79
79
  end
80
80
 
81
81
  def end_vector
82
- if @a.to_f == 0.0
82
+ if @a.to_d == 0.0
83
83
  return [@len_x, 0] if @len_x
84
84
  return [0, @len_y] if @len_y
85
85
  end
86
86
  if @len_x
87
- x = cos(PI*@a/180.0)*@len_x.to_f
88
- y = sin(PI*@a/180.0)*@len_x.to_f
87
+ x = cos(PI*@a/180.0)*@len_x.to_d
88
+ y = sin(PI*@a/180.0)*@len_x.to_d
89
89
  else
90
- x = -1* sin(PI*@a/180.0)*@len_y.to_f
91
- y = cos(PI*@a/180.0)*@len_y.to_f
90
+ x = -1* sin(PI*@a/180.0)*@len_y.to_d
91
+ y = cos(PI*@a/180.0)*@len_y.to_d
92
92
  end
93
93
  [x,y]
94
94
  end
@@ -2,13 +2,13 @@ module JennCad::Primitives
2
2
  class SubtractObject < BooleanObject
3
3
  def inherit_z
4
4
  @z = 0
5
- @calc_z = parts.first.calc_z.to_f
5
+ @calc_z = parts.first.calc_z.to_d
6
6
 
7
7
  only_additives_of(@parts).each do |p|
8
8
  if option(:debug)
9
9
  $log.debug "inherit_z checks for: #{p}"
10
10
  end
11
- z = p.z.to_f
11
+ z = p.z.to_d
12
12
  @z = z if z > @z
13
13
  end
14
14
  $log.debug "inherit_z called, biggest z found: #{@z}" if option(:debug)
@@ -80,7 +80,7 @@ module JennCad::Primitives
80
80
  part.opts[:margins][:z] += 0.004
81
81
  # part.z+=0.004
82
82
  part.mz(-0.002)
83
- elsif part.calc_z.to_f+part.calc_h.to_f == compare_h
83
+ elsif part.calc_z.to_d+part.calc_h.to_d == compare_h
84
84
  # puts "z fighting at top: #{compare_h}"
85
85
  #part.z+=0.004
86
86
  part.opts[:margins][:z] += 0.004
data/lib/jenncad/thing.rb CHANGED
@@ -93,7 +93,7 @@ module JennCad
93
93
  case self
94
94
  when UnionObject
95
95
  ref = self.parts.first
96
- rz = self.z.to_f + self.calc_h.to_f
96
+ rz = self.z.to_d + self.calc_h.to_d
97
97
  when BooleanObject
98
98
  ref = self.parts.first
99
99
  rz = ref.calc_z + ref.calc_h
@@ -121,7 +121,7 @@ module JennCad
121
121
  alias :fy :flip_y
122
122
 
123
123
  def radians(a)
124
- a.to_f/180.0*PI
124
+ a.to_d/180.0*PI
125
125
  end
126
126
 
127
127
  # experiment
@@ -181,21 +181,41 @@ module JennCad
181
181
  end
182
182
 
183
183
  def move(args={})
184
+ return self if args.nil? or args.empty?
185
+
184
186
  if args.kind_of? Array
185
187
  x,y,z = args
186
188
  return move(x:x, y:y, z:z)
187
189
  end
188
190
  args = parse_xyz_shortcuts(args)
189
191
 
192
+ if args[:x].to_d == 0.0 && args[:y].to_d == 0.0 && args[:z].to_d == 0.0
193
+ return self
194
+ end
195
+
190
196
  @transformations ||= []
191
197
  if args[:prepend]
192
198
  @transformations.prepend(Move.new(args))
193
199
  else
194
- @transformations << Move.new(args)
200
+ lt = @transformations.last
201
+
202
+ chain = if args[:chain]
203
+ args[:chain]
204
+ else
205
+ $jenncad_profile.chain_moves
206
+ end
207
+
208
+ if lt && lt.class == Move && chain == false
209
+ lt.x += args[:x].to_d
210
+ lt.y += args[:y].to_d
211
+ lt.z += args[:z].to_d
212
+ else
213
+ @transformations << Move.new(args)
214
+ end
195
215
  end
196
- @calc_x += args[:x].to_f
197
- @calc_y += args[:y].to_f
198
- @calc_z += args[:z].to_f
216
+ @calc_x += args[:x].to_d
217
+ @calc_y += args[:y].to_d
218
+ @calc_z += args[:z].to_d
199
219
  self
200
220
  end
201
221
  alias :translate :move
@@ -214,7 +234,12 @@ module JennCad
214
234
  end
215
235
 
216
236
  # move to anchor
217
- def movea(key, thing=nil)
237
+ def movea(key, thing=nil, args={})
238
+ if thing.kind_of? Hash # if you leave out thing, args may be interpreted as thing
239
+ args = thing
240
+ thing = nil
241
+ end
242
+
218
243
  an = anchor(key, thing)
219
244
 
220
245
  unless an
@@ -222,20 +247,26 @@ module JennCad
222
247
  $log.error "Available anchors: #{@anchors}"
223
248
  return self
224
249
  else
225
- self.move(an.dup)
250
+ m = an.dup
251
+ if args[:chain]
252
+ m[:chain] = args[:chain]
253
+ end
254
+ if args[:inverted]
255
+ self.movei(m)
256
+ else
257
+ self.move(m)
258
+ end
226
259
  end
227
260
  end
228
261
 
229
262
  # move to anchor - inverted
230
- def moveai(key, thing=nil)
231
- an = anchor(key, thing)
232
- unless an
233
- $log.error "Error: Anchor #{key} not found"
234
- $log.error "Available anchors: #{@anchors}"
235
- return self
236
- else
237
- self.movei(an.dup)
263
+ def moveai(key, thing=nil, args={})
264
+ if thing.kind_of? Hash # if you leave out thing, args may be interpreted as thing
265
+ args = thing
266
+ thing = nil
238
267
  end
268
+ args[:inverted] = true
269
+ movea(key, thing, args)
239
270
  end
240
271
 
241
272
 
@@ -272,6 +303,7 @@ module JennCad
272
303
  to[key] = args[key]*-1
273
304
  end
274
305
  end
306
+ to[:chain] = args[:chain]
275
307
  move(to)
276
308
  end
277
309
 
@@ -335,7 +367,7 @@ module JennCad
335
367
  end
336
368
 
337
369
  def top_of(other_object)
338
- self.move(z:other_object.z+other_object.calc_z.to_f)
370
+ self.move(z:other_object.z+other_object.calc_z.to_d)
339
371
  end
340
372
 
341
373
  def on_top_of(other_object)
@@ -564,7 +596,7 @@ module JennCad
564
596
  end
565
597
 
566
598
  def referenced_z
567
- return false if @z.to_f != 0.0
599
+ return false if @z.to_d != 0.0
568
600
  return option(:zref) if option(:zref)
569
601
  return false
570
602
  end
@@ -579,7 +611,7 @@ module JennCad
579
611
  when nil, false
580
612
  @z + z_margin
581
613
  else
582
- ref.z.to_f + ref.z_margin.to_f
614
+ ref.z.to_d + ref.z_margin.to_d
583
615
  end
584
616
  end
585
617
 
@@ -588,7 +620,7 @@ module JennCad
588
620
  when nil, {}
589
621
  0.0
590
622
  else
591
- m[:z].to_f
623
+ m[:z].to_d
592
624
  end
593
625
  end
594
626
 
@@ -16,7 +16,7 @@ module JennCad
16
16
 
17
17
  def self.check_color_array(a)
18
18
  if a.max > 1.0
19
- a.map{|l| l.to_f/255.0}
19
+ a.map{|l| l.to_d/255.0}
20
20
  else
21
21
  a
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha13"
2
+ VERSION = "1.0.0-alpha14"
3
3
  end
data/lib/jenncad.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "logger"
2
2
  $log = Logger.new(STDOUT)
3
3
 
4
+ require 'bigdecimal/util'
4
5
  require "geo3d"
5
6
  require "deep_merge"
6
7
  require "fileutils"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenncad
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha13
4
+ version: 1.0.0.pre.alpha14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jennifer Glauche
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-01 00:00:00.000000000 Z
11
+ date: 2022-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d