jenncad 1.0.0.pre.alpha14 → 1.0.0.pre.alpha15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: beb1887d6ae1d3fc87da9c816de1cd2cb54ea5fb3ce7f1277ca6af8bcfc4e687
4
- data.tar.gz: 5cc6fd0fc52de9b8b9087dfadd0387122014b157c9573b091aa7c4570a5f2c6a
3
+ metadata.gz: 3eebd115b8e6783b61fff33f1b002f935f3d2c2023df70df9ff3b9850f12245f
4
+ data.tar.gz: 806a99e1195f98ee1e8450030f9e2809c11217af7bf19e8cac88ad9408146a40
5
5
  SHA512:
6
- metadata.gz: 8f86a697557b258219756ba02c0bb0e478d1c240c05fd53ecb1221749caedd4e7bf7c3395c439f9c0d426e33366d104e71c20a89bca894ee8e0c843733a0446d
7
- data.tar.gz: 4ee555b106f36751024a876ece4880b3cea9138e606c541457a809828645f399f3a417cc0f40256e7363bf20f2b212a20f27166429337062a297caddb21931e1
6
+ metadata.gz: a120ac12bfe18f3532560c10452ae9460d21bd8ba2e4d287669b9b23cdf903476541fed341b81ce7feb8e906ccc8087a7a0f46f5f49e63d66b6421cd8e4d0984
7
+ data.tar.gz: 06e239cea5a153ecb3b8ab1873574bc8d9a03e51d1c0d75e5fe72f393e1584971bbc2ba388d9da82ce58cc79c2f949e206962be9052da29b0a24e351c176a53d
@@ -1,6 +1,8 @@
1
1
  module JennCad::Features
2
2
  class Climb < Feature
3
3
  def initialize(opts, block)
4
+ $log.warn "DEPRECATED feature: climb. Please use x.of (multiples_of example)"
5
+
4
6
  @opts = {
5
7
  offset: :auto,
6
8
  step: nil,
@@ -0,0 +1,14 @@
1
+ class Integer
2
+ def of(part=nil, anchor=:top_face)
3
+ return nil if part.nil?
4
+ num = self - 1
5
+
6
+ res = part.fix
7
+ num.times do
8
+ res += part.movea(anchor)
9
+ end
10
+ res
11
+ end
12
+ end
13
+
14
+
@@ -1,7 +1,7 @@
1
1
  module JennCad
2
2
  class RoundCorner
3
3
  attr_accessor :start_point, :end_point, :input_a, :output_a, :a, :l, :od, :id, :thing, :angle, :current_angle, :direction, :from, :ccw
4
- def initialize(args, &thing)
4
+ def initialize(args)
5
5
  @start_point = args[:start_point]
6
6
  @end_point = args[:end_point]
7
7
  @a = args[:a]
@@ -11,7 +11,13 @@ module JennCad
11
11
  @id = args[:id]
12
12
  @input_a = args[:input_a] || 0
13
13
  @output_a = args[:output_a] || 0
14
- @thing = thing
14
+ thing = Marshal.load(args[:thing])
15
+
16
+ @thing_dia = thing.d || thing.y
17
+ unless @thing_dia
18
+ $log.error "ERROR: cannot find diameter or y of thing #{thing.inspect}"
19
+ return
20
+ end
15
21
  @angle = args[:angle]
16
22
  @current_angle = args[:current_angle]
17
23
  @direction = args[:direction]
@@ -57,11 +63,7 @@ module JennCad
57
63
  end
58
64
 
59
65
  def positions
60
- td = thing.yield.d || thing.yield.y
61
- unless td
62
- puts "ERROR: cannot find diameter or y of thing #{thing.yield.inspect}"
63
- return
64
- end
66
+ td = @thing_dia
65
67
  l = td + @id
66
68
  l2 = td / 2.0 + @id / 2.0
67
69
  r = 0
@@ -101,7 +103,7 @@ module JennCad
101
103
  end
102
104
 
103
105
  def part
104
- d = thing.yield.d
106
+ d = @thing_dia
105
107
  len = d * 2 + @id
106
108
  x = Math::sin((@a/180.0)*Math::PI)*len
107
109
  y = Math::cos((@a/180.0)*Math::PI)*len
@@ -134,15 +136,15 @@ module JennCad
134
136
  end
135
137
 
136
138
  class Line
137
- attr_accessor :start_point, :end_point, :l, :thing, :angle, :current_angle, :direction
138
- def initialize(args, &thing)
139
+ attr_accessor :start_point, :end_point, :l, :angle, :current_angle, :direction
140
+ def initialize(args)
139
141
  @start_point = args[:start_point]
140
142
  @end_point = args[:end_point]
141
143
  @angle = args[:angle]
142
144
  @current_angle = args[:current_angle]
143
145
  @direction = args[:direction]
144
146
  @l = args[:l]
145
- @thing = thing
147
+ @thing = args[:thing]
146
148
  end
147
149
 
148
150
  def sp_margin(margin)
@@ -181,8 +183,8 @@ module JennCad
181
183
 
182
184
  def part
183
185
  hull(
184
- @thing.yield.move(x: @start_point[:x], y: @start_point[:y]),
185
- @thing.yield.move(x: @end_point[:x], y: @end_point[:y])
186
+ Marshal.load(@thing).move(x: @start_point[:x], y: @start_point[:y]),
187
+ Marshal.load(@thing).move(x: @end_point[:x], y: @end_point[:y])
186
188
  )
187
189
  end
188
190
  end
@@ -191,7 +193,7 @@ module JennCad
191
193
 
192
194
  attr_accessor :elements, :lpos, :thing, :angle, :current_angle, :direction
193
195
  def initialize(args)
194
- @thing = args[:part] #// cylinder(d: @d, z: @z)
196
+ @thing = store_thing_from(args[:part])
195
197
  @part = new_thing
196
198
  @angle = args[:a] || 0
197
199
  @current_angle = args[:a] || 0
@@ -207,10 +209,14 @@ module JennCad
207
209
  super(args)
208
210
  end
209
211
 
210
- def new_thing
211
- r = @thing.clone
212
+ def store_thing_from(thing)
213
+ r = Marshal.load(Marshal.dump(thing)) # make sure we don't edit the object in memory
212
214
  r.transformations = []
213
- r
215
+ Marshal.dump(r)
216
+ end
217
+
218
+ def new_thing
219
+ Marshal.load(@thing)
214
220
  end
215
221
 
216
222
  def corner(args)
@@ -232,8 +238,9 @@ module JennCad
232
238
  from: args[:from],
233
239
  to: args[:to],
234
240
  a: args[:a],
235
- direction: @direction
236
- ){ new_thing }
241
+ direction: @direction,
242
+ thing: thing,
243
+ )
237
244
 
238
245
  _, ox, oy, x, y = rc.positions
239
246
  @lpos[:x] += x + ox
@@ -292,7 +299,7 @@ module JennCad
292
299
  return
293
300
  end
294
301
 
295
- @steps << Line.new(start_point: { x: @lpos[:x], y: @lpos[:y] }, end_point: { x: @lpos[:x] + x, y: @lpos[:y] + y }, angle: @angle, current_angle: @current_angle, direction: @direction, l: l){ new_thing }
302
+ @steps << Line.new(start_point: { x: @lpos[:x], y: @lpos[:y] }, end_point: { x: @lpos[:x] + x, y: @lpos[:y] + y }, angle: @angle, current_angle: @current_angle, direction: @direction, l: l, thing: thing)
296
303
 
297
304
  add_lpos({x: x, y: y})
298
305
  end
@@ -5,6 +5,8 @@ require "jenncad/features/openscad_include"
5
5
  require "jenncad/features/climb"
6
6
  require "jenncad/features/stl_import"
7
7
  require "jenncad/features/path"
8
+ require "jenncad/features/multiples_of"
9
+
8
10
 
9
11
 
10
12
 
@@ -7,6 +7,9 @@ module JennCad::Primitives
7
7
  else
8
8
  @parts = parts
9
9
  end
10
+ if parts.first && parts.first.respond_to?(:debug?) && parts.first.debug?
11
+ $log.debug("Creating new #{self.class} for part #{parts}")
12
+ end
10
13
 
11
14
  @parent = @parts.first.parent
12
15
 
@@ -16,9 +19,11 @@ module JennCad::Primitives
16
19
  def add_or_new(part)
17
20
  case @transformations
18
21
  when nil, []
22
+ $log.debug("adding new part to existing boolean object") if part && part.debug?
19
23
  add(part)
20
24
  self
21
25
  else
26
+ $log.debug("add_or_new: creating new boolean object") if part.debug?
22
27
  self.class.new(self, part)
23
28
  end
24
29
  end
@@ -82,6 +82,13 @@ module JennCad::Primitives
82
82
  set_anchor :top_right, x: right, y: top
83
83
  set_anchor :bottom_left, x: left, y: bottom
84
84
  set_anchor :bottom_right, x: right, y: bottom
85
+ if @opts[:center_z]
86
+ set_anchor :bottom_face, z: -@z/2.0
87
+ set_anchor :top_face, z: @z/2.0
88
+ else
89
+ set_anchor :bottom_face, z: 0
90
+ set_anchor :top_face, z: @z
91
+ end
85
92
 
86
93
  # we need to re-do the inner ones, if they were defined
87
94
  if @inner_anchor_defs && @inner_anchor_defs.size > 0
@@ -1,6 +1,6 @@
1
1
  module JennCad::Primitives
2
2
  class Cylinder < Primitive
3
- attr_accessor :d, :d1, :d2, :r, :fn
3
+ attr_accessor :d, :d1, :d2, :r, :fn, :anchors
4
4
  def initialize(args)
5
5
  if args.kind_of?(Array) && args[0].kind_of?(Hash)
6
6
  args = args.first
@@ -24,6 +24,7 @@ module JennCad::Primitives
24
24
  r2: nil,
25
25
  z: nil,
26
26
  r: 0,
27
+ cz: false,
27
28
  margins: {
28
29
  r: 0,
29
30
  d: 0,
@@ -41,6 +42,35 @@ module JennCad::Primitives
41
42
  handle_radius_diameter
42
43
  handle_fn
43
44
  super(args)
45
+ set_anchors
46
+ end
47
+
48
+ def set_anchors
49
+ @anchors = {} # reset anchors
50
+ if @opts[:d]
51
+ rad = @opts[:d] / 2.0
52
+ else
53
+ rad = @opts[:r]
54
+ end
55
+
56
+ # Similar to cube
57
+ set_anchor :left, x: -rad
58
+ set_anchor :right, x: rad
59
+ set_anchor :top, y: rad
60
+ set_anchor :bottom, y: -rad
61
+
62
+ # TODO: figure out if we also want to have "corners"
63
+ # - possibly move it like a cube
64
+ # - points at 45 ° angles might not be that useful unless you can get the point on the circle at a given angle
65
+ # - inner/outer points could be useful for small $fn values
66
+
67
+ if @opts[:cz]
68
+ set_anchor :bottom_face, z: -@z/2.0
69
+ set_anchor :top_face, z: @z/2.0
70
+ else
71
+ set_anchor :bottom_face, z: 0
72
+ set_anchor :top_face, z: @z
73
+ end
44
74
  end
45
75
 
46
76
  def openscad_params
@@ -60,7 +90,9 @@ module JennCad::Primitives
60
90
  # Centers the cylinder around it's center point by height
61
91
  # This will transform the cylinder around the center point.
62
92
  def cz
93
+ @opts[:cz] = true
63
94
  @transformations << Move.new(z: -@z / 2.0)
95
+ set_anchors
64
96
  self
65
97
  end
66
98
 
@@ -93,8 +93,8 @@ module JennCad
93
93
  private
94
94
  def boolean_operation(part, klass)
95
95
  if part.respond_to? :transformations
96
- # Since ruby doesn't provide a way to make a deep clone, this seems to be the simplest solution that will effectively do that:
97
- part = Marshal.load(Marshal.dump(part))
96
+ # Clone the part in place
97
+ part = part.fix
98
98
  end
99
99
 
100
100
  case self
@@ -103,7 +103,12 @@ module JennCad
103
103
  when klass
104
104
  add_or_new(part)
105
105
  else
106
- klass.new(self,part)
106
+ own_part = if self.respond_to? :transformations
107
+ self.fix # clone self
108
+ else
109
+ self
110
+ end
111
+ klass.new(own_part,part)
107
112
  end
108
113
  end
109
114
  end
data/lib/jenncad/thing.rb CHANGED
@@ -33,6 +33,23 @@ module JennCad
33
33
  @opts[key] = val
34
34
  end
35
35
 
36
+ def set_flag(key)
37
+ set_option(key, true)
38
+ end
39
+
40
+ def unset_flag(key)
41
+ set_option(key, false)
42
+ end
43
+
44
+ def debug?
45
+ option(:debug) || false
46
+ end
47
+
48
+ def fixate
49
+ Marshal.load(Marshal.dump(self))
50
+ end
51
+ alias :fix :fixate
52
+
36
53
  def set_parent(parent)
37
54
  @parent = parent
38
55
  self
@@ -64,6 +81,22 @@ module JennCad
64
81
  end
65
82
  alias :sa :set_anchor
66
83
 
84
+ def set_anchor_from(name, new_name, args={})
85
+ a = anchor(name).dup
86
+ if !a
87
+ log.error "set_anchor_from couldn't find anchor #{name}"
88
+ return
89
+ end
90
+
91
+ [:x, :y, :z, :xy, :xz, :xyz, :yz].each do |key|
92
+ a[key] ||= 0.to_d
93
+ args[key] ||= 0.to_d
94
+ a[key] += args[key]
95
+ end
96
+ set_anchor new_name, a
97
+ end
98
+ alias :saf :set_anchor_from
99
+
67
100
  def auto_extrude
68
101
  ret = self.extrude
69
102
  ret.set_option(:auto_extrude, true)
@@ -206,10 +239,12 @@ module JennCad
206
239
  end
207
240
 
208
241
  if lt && lt.class == Move && chain == false
242
+ $log.debug "#{self} at move: Adding to previous move #{lt.inspect} , args: #{args}" if self.debug?
209
243
  lt.x += args[:x].to_d
210
244
  lt.y += args[:y].to_d
211
245
  lt.z += args[:z].to_d
212
246
  else
247
+ $log.debug "#{self} at move: Adding move of #{args} to transformations" if self.debug?
213
248
  @transformations << Move.new(args)
214
249
  end
215
250
  end
@@ -488,6 +523,8 @@ module JennCad
488
523
  return "##{args}"
489
524
  when String
490
525
  return args
526
+ when Symbol
527
+ return args.to_s
491
528
  end
492
529
  nil
493
530
  end
@@ -1,3 +1,3 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha14"
2
+ VERSION = "1.0.0-alpha15"
3
3
  end
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.alpha14
4
+ version: 1.0.0.pre.alpha15
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-02 00:00:00.000000000 Z
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d
@@ -122,6 +122,7 @@ files:
122
122
  - lib/jenncad/features/climb.rb
123
123
  - lib/jenncad/features/cuttable.rb
124
124
  - lib/jenncad/features/feature.rb
125
+ - lib/jenncad/features/multiples_of.rb
125
126
  - lib/jenncad/features/openscad_include.rb
126
127
  - lib/jenncad/features/path.rb
127
128
  - lib/jenncad/features/stl_import.rb