jenncad 1.0.0.pre.alpha16 → 1.0.0.pre.alpha17

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: ef20af7d3fc9a11140dacb23030a9ba671a80cbd39491caed609d6755f8bc85c
4
- data.tar.gz: 4e515e6fbedcfa16b315b8ea02cafe8a6d41207fbdd9aece996165edee7f9214
3
+ metadata.gz: be56296dfd0c04706441288172b3493d918f76a05ee92fa1004ce0c619e6d1c0
4
+ data.tar.gz: 7b1130259db67a2a0e75e8074265958fac8ada1dbd6a3ce34de2dc4050a1d7a9
5
5
  SHA512:
6
- metadata.gz: 17111c38b461ecdf683d2813284279b4bced3296d97dc9aebdf17797955affea2ad275bd21f5935680c09a8f08234ebac9c5bbb67ce197fdfe6c3e0a6489d0cf
7
- data.tar.gz: 9022e918187212aa81f4f02b28c9a9ac11d7b8d36c6afb36835346298309ec2204430478032c406177315ee9807d0513bb52f0d8581dfec9c3df13e91b42f5f8
6
+ metadata.gz: 76e84ad22e862bc9b961d4e96382d0c40ebdfe6ab2ff2ee709c5e90faf7eb01b5199612abb4c0950c193cef97c4a43a895b2e071c306a9036d018ac135416adc
7
+ data.tar.gz: df24c4d80c52738a6223dd0ac7d20a8448c06839c7c448e436afa0501d659276d7e28dc5c0a23cf2742babd13475e5afb1be8aa13bf69916fc8b4844306b006e
@@ -162,14 +162,16 @@ module JennCad::Exporters
162
162
  bool('intersection', part)
163
163
  when JennCad::HullObject
164
164
  bool('hull', part)
165
- when JennCad::Primitives::Circle
166
- prim('circle', part)
167
165
  when JennCad::Primitives::Cylinder
168
166
  prim('cylinder', part)
169
167
  when JennCad::Primitives::Sphere
170
168
  prim('sphere', part)
171
169
  when JennCad::Primitives::Cube
172
170
  prim('cube', part)
171
+ when JennCad::Primitives::Circle
172
+ prim('circle', part)
173
+ when JennCad::Primitives::Square
174
+ prim('square', part)
173
175
  when JennCad::Primitives::LinearExtrude
174
176
  new_obj(part, :linear_extrude, part.openscad_params, parse(part.parts))
175
177
  when JennCad::Primitives::RotateExtrude
@@ -2,10 +2,108 @@ module JennCad::Primitives
2
2
  class Circle < Primitive
3
3
  attr_accessor :d, :r, :fn
4
4
  def initialize(args)
5
- super
6
- @d = args[:d]
7
- @r = args[:r]
8
- @fn = args[:fn]
5
+ if args.kind_of?(Array) && args[0].kind_of?(Hash)
6
+ args = args.first
7
+ end
8
+ if args.kind_of? Array
9
+ m = {}
10
+ if args.last.kind_of? Hash
11
+ m = args.last
12
+ end
13
+ args = [:d, :z].zip(args.flatten).to_h
14
+ args.deep_merge!(m)
15
+ end
16
+
17
+
18
+ @opts = {
19
+ d: 0,
20
+ d1: nil,
21
+ d2: nil,
22
+ r1: nil,
23
+ r2: nil,
24
+ z: nil,
25
+ r: 0,
26
+ cz: false,
27
+ margins: {
28
+ r: 0,
29
+ d: 0,
30
+ z: 0,
31
+ },
32
+ fn: nil,
33
+ }.deep_merge!(args)
34
+ init(args)
35
+ @dimensions = [:x, :y]
36
+ handle_radius_diameter
37
+ handle_fn
38
+ set_anchors_2d
9
39
  end
40
+
41
+ def set_anchors_2d
42
+ @anchors = {} # reset anchors
43
+ if @opts[:d]
44
+ rad = @opts[:d] / 2.0
45
+ else
46
+ rad = @opts[:r]
47
+ end
48
+
49
+ # Similar to cube
50
+ set_anchor :left, x: -rad
51
+ set_anchor :right, x: rad
52
+ set_anchor :top, y: rad
53
+ set_anchor :bottom, y: -rad
54
+ end
55
+
56
+ def openscad_params
57
+ res = {}
58
+ [:d, :fn].each do |n|
59
+ res[n] = self.send n
60
+ end
61
+ res
62
+ end
63
+
64
+ def handle_fn
65
+ case @opts[:fn]
66
+ when nil, 0
67
+ $fn = auto_dn!
68
+ else
69
+ @fn = @opts[:fn]
70
+ end
71
+ end
72
+
73
+ def auto_dn!
74
+ case @d
75
+ when (16..)
76
+ @fn = (@d*4).ceil
77
+ else
78
+ @fn = 64
79
+ end
80
+ end
81
+
82
+ def handle_radius_diameter
83
+ case @opts[:d]
84
+ when 0, nil
85
+ @r = @opts[:r].to_d + @opts[:margins][:r].to_d
86
+ @d = @r * 2.0
87
+ else
88
+ @d = @opts[:d].to_d + @opts[:margins][:d].to_d
89
+ @r = @d / 2.0
90
+ end
91
+
92
+ case @opts[:d1]
93
+ when 0, nil
94
+ else
95
+ @d1 = @opts[:d1].to_d + @opts[:margins][:d].to_d
96
+ @d2 = @opts[:d2].to_d + @opts[:margins][:d].to_d
97
+ end
98
+
99
+ case @opts[:r1]
100
+ when 0, nil
101
+ else
102
+ @d1 = 2 * @opts[:r1].to_d + @opts[:margins][:d].to_d
103
+ @d2 = 2 * @opts[:r2].to_d + @opts[:margins][:d].to_d
104
+ end
105
+ end
106
+
107
+
10
108
  end
11
109
  end
@@ -1,24 +1,7 @@
1
1
  module JennCad::Primitives
2
- class Cube < Primitive
2
+ class Cube < Square
3
3
  extend JennCad::Features::Cuttable
4
4
 
5
- attr_accessor :corners, :sides
6
-
7
- def feed_opts(args)
8
- # FIXME: this doesn't seem to work
9
- if args.kind_of? Array
10
- m = {}
11
- if args.last.kind_of? Hash
12
- m = args.last
13
- end
14
- args = [:x, :y, :z].zip(args.flatten).to_h
15
- args.deep_merge!(m)
16
- @opts.deep_merge!(args)
17
- else
18
- @opts.deep_merge!(args)
19
- end
20
- end
21
-
22
5
  def initialize(args)
23
6
  @opts = {
24
7
  x: 0,
@@ -41,47 +24,20 @@ module JennCad::Primitives
41
24
  else
42
25
  feed_opts(parse_xyz_shortcuts(args))
43
26
  end
27
+ init
44
28
 
45
29
 
46
30
  handle_margins
47
- super(z: @opts[:z])
48
31
  @h = @z.dup
49
32
  @calc_h = @z.dup
50
33
 
34
+ @dimensions = [:x, :y, :z]
51
35
 
52
36
  set_anchors
53
37
  end
54
38
 
55
39
  def set_anchors
56
- @anchors = {} # this resets anchors
57
-
58
- if @opts[:center] || @opts[:center_x]
59
- left = -@opts[:x] / 2.0
60
- right = @opts[:x] / 2.0
61
- mid_x = 0
62
- else
63
- left = 0
64
- right = @opts[:x]
65
- mid_x = @opts[:x] / 2.0
66
- end
67
- if @opts[:center] || @opts[:center_y]
68
- bottom = -@opts[:y] / 2.0
69
- top = @opts[:y] / 2.0
70
- mid_y = 0
71
- else
72
- bottom = 0
73
- top = @opts[:y]
74
- mid_y = @opts[:y] / 2.0
75
- end
76
-
77
- set_anchor :left, x: left, y: mid_y
78
- set_anchor :right, x: right, y: mid_y
79
- set_anchor :top, x: mid_x, y: top
80
- set_anchor :bottom, x: mid_x, y: bottom
81
- set_anchor :top_left, x: left, y: top
82
- set_anchor :top_right, x: right, y: top
83
- set_anchor :bottom_left, x: left, y: bottom
84
- set_anchor :bottom_right, x: right, y: bottom
40
+ set_anchors_2d
85
41
  if @opts[:center_z]
86
42
  set_anchor :bottom_face, z: -@z/2.0
87
43
  set_anchor :top_face, z: @z/2.0
@@ -90,100 +46,14 @@ module JennCad::Primitives
90
46
  set_anchor :top_face, z: @z
91
47
  end
92
48
 
93
- # we need to re-do the inner ones, if they were defined
94
- if @inner_anchor_defs && @inner_anchor_defs.size > 0
95
- @inner_anchor_defs.each do |anch|
96
- inner_anchors(anch[:dist], anch[:prefix], true)
97
- end
98
- end
99
49
 
100
- self
101
50
  end
102
51
 
103
- def inner_anchors(dist, prefix=:inner_, recreate=false)
104
- if dist.nil?
105
- $log.error "Distance of nil passed to inner anchors. Please check the variable name you passed along"
106
- return self
107
- end
108
-
109
- @inner_anchor_defs ||= []
110
- @inner_anchor_defs << { "dist": dist, "prefix": prefix } unless recreate
111
-
112
- # $log.info "dist: #{dist}, prefix: #{prefix}"
113
- sides = {
114
- left: {x: dist, y: 0},
115
- right: {x: -dist, y: 0},
116
- top: {x: 0, y: -dist},
117
- bottom: {x: 0, y: dist},
118
- }
119
- corners = {
120
- top_left: {x: dist, y: -dist},
121
- top_right: {x: -dist, y: -dist},
122
- bottom_left: {x: dist, y: dist},
123
- bottom_right: {x: -dist, y: dist},
124
- }
125
- new_sides = []
126
- new_corners = []
127
-
128
- sides.merge(corners).each do |key, vals|
129
- new_dist = anchor(key).dup
130
- new_dist[:x] += vals[:x]
131
- new_dist[:y] += vals[:y]
132
- name = [prefix, key].join.to_sym
133
- # $log.info "Set anchor #{name} , new dist #{new_dist}"
134
- set_anchor name, new_dist
135
- if sides.include? key
136
- new_sides << name
137
- end
138
- if corners.include? key
139
- new_corners << name
140
- end
141
- end
142
-
143
- sides_name = [prefix, "sides"].join
144
- corners_name = [prefix, "corners"].join
145
- all_name = [prefix, "all"].join
146
- self.class.__send__(:attr_accessor, sides_name.to_sym)
147
- self.class.__send__(:attr_accessor, corners_name.to_sym)
148
- self.class.__send__(:attr_accessor, all_name.to_sym)
149
- self.__send__("#{sides_name}=", new_sides)
150
- self.__send__("#{corners_name}=", new_corners)
151
- self.__send__("#{all_name}=", new_corners+new_sides)
152
-
153
-
154
- self
155
- end
156
-
157
-
158
52
  # used for openscad export
159
53
  def size
160
54
  [@x, @y, z+z_margin]
161
55
  end
162
56
 
163
- def not_centered
164
- @opts[:center] = false
165
- set_anchors
166
- self
167
- end
168
- alias :nc :not_centered
169
-
170
- def cx
171
- nc
172
- @opts[:center_x] = true
173
- set_anchors
174
- self
175
- end
176
- alias :center_x :cx
177
-
178
- def cy
179
- nc
180
- @opts[:center_y] = true
181
- set_anchors
182
- self
183
- end
184
- alias :center_y :cy
185
-
186
-
187
57
  def cz
188
58
  nc
189
59
  @opts[:center_z] = true
@@ -192,18 +62,5 @@ module JennCad::Primitives
192
62
  end
193
63
  alias :center_z :cz
194
64
 
195
- def centered_axis
196
- return [:x, :y] if @opts[:center]
197
- a = []
198
- a << :x if @opts[:center_x]
199
- a << :y if @opts[:center_y]
200
- a << :z if @opts[:center_z]
201
- a
202
- end
203
-
204
- def to_openscad
205
- self.mh(centered_axis.to_h{|a| [a, -@opts[a]] }) # center cube
206
- end
207
-
208
65
  end
209
66
  end
@@ -1,5 +1,5 @@
1
1
  module JennCad::Primitives
2
- class Cylinder < Primitive
2
+ class Cylinder < Circle
3
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)
@@ -32,7 +32,7 @@ module JennCad::Primitives
32
32
  },
33
33
  fn: nil,
34
34
  }.deep_merge!(args)
35
-
35
+ init(args)
36
36
  # FIXME:
37
37
  # - margins calculation needs to go to output
38
38
  # - assinging these variables has to stop
@@ -41,24 +41,12 @@ module JennCad::Primitives
41
41
  @z = args[:z] || args[:h]
42
42
  handle_radius_diameter
43
43
  handle_fn
44
- super(args)
44
+ @dimensions = [:x, :y, :z]
45
45
  set_anchors
46
46
  end
47
47
 
48
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
-
49
+ set_anchors_2d
62
50
  # TODO: figure out if we also want to have "corners"
63
51
  # - possibly move it like a cube
64
52
  # - points at 45 ° angles might not be that useful unless you can get the point on the circle at a given angle
@@ -91,54 +79,12 @@ module JennCad::Primitives
91
79
  # This will transform the cylinder around the center point.
92
80
  def cz
93
81
  @opts[:cz] = true
82
+ @transformations ||= []
94
83
  @transformations << Move.new(z: -@z / 2.0)
95
84
  set_anchors
96
85
  self
97
86
  end
98
87
 
99
- def handle_fn
100
- case @opts[:fn]
101
- when nil, 0
102
- $fn = auto_dn!
103
- else
104
- @fn = @opts[:fn]
105
- end
106
- end
107
-
108
- def auto_dn!
109
- case @d
110
- when (16..)
111
- @fn = (@d*4).ceil
112
- else
113
- @fn = 64
114
- end
115
- end
116
-
117
- def handle_radius_diameter
118
- case @opts[:d]
119
- when 0, nil
120
- @r = @opts[:r].to_d + @opts[:margins][:r].to_d
121
- @d = @r * 2.0
122
- else
123
- @d = @opts[:d].to_d + @opts[:margins][:d].to_d
124
- @r = @d / 2.0
125
- end
126
-
127
- case @opts[:d1]
128
- when 0, nil
129
- else
130
- @d1 = @opts[:d1].to_d + @opts[:margins][:d].to_d
131
- @d2 = @opts[:d2].to_d + @opts[:margins][:d].to_d
132
- end
133
-
134
- case @opts[:r1]
135
- when 0, nil
136
- else
137
- @d1 = 2 * @opts[:r1].to_d + @opts[:margins][:d].to_d
138
- @d2 = 2 * @opts[:r2].to_d + @opts[:margins][:d].to_d
139
- end
140
- end
141
-
142
88
  def z=(val)
143
89
  @z = val
144
90
  @h = val
@@ -5,6 +5,7 @@ module JennCad::Primitives
5
5
  @points = args[:points]
6
6
  @paths = args[:paths]
7
7
  @convexity = args[:convexity] || 10
8
+ @dimensions = [:x, :y]
8
9
  super
9
10
  end
10
11
  end
@@ -1,5 +1,7 @@
1
1
  module JennCad::Primitives
2
2
  class Primitive < JennCad::Thing
3
+ attr_accessor :dimensions
4
+
3
5
  def initialize(*args)
4
6
  super(*args)
5
7
  end
@@ -7,7 +9,9 @@ module JennCad::Primitives
7
9
  def handle_margins
8
10
  @x = @opts[:x].to_d + @opts[:margins][:x].to_d
9
11
  @y = @opts[:y].to_d + @opts[:margins][:y].to_d
10
- @z = @opts[:z].to_d + @opts[:margins][:z].to_d
12
+ if @opts[:z]
13
+ @z = @opts[:z].to_d + @opts[:margins][:z].to_d
14
+ end
11
15
  end
12
16
 
13
17
  def handle_diameter
@@ -20,5 +24,20 @@ module JennCad::Primitives
20
24
  end
21
25
  end
22
26
 
27
+ def feed_opts(args)
28
+ if args.kind_of? Array
29
+ m = {}
30
+ if args.last.kind_of? Hash
31
+ m = args.last
32
+ end
33
+ args = [:x, :y, :z].zip(args.flatten).to_h
34
+ args.deep_merge!(m)
35
+ @opts.deep_merge!(args)
36
+ else
37
+ @opts.deep_merge!(args)
38
+ end
39
+ end
40
+
41
+
23
42
  end
24
43
  end
@@ -4,6 +4,7 @@ module JennCad::Primitives
4
4
  include JennCad::Features::Cuttable
5
5
 
6
6
  def initialize(args)
7
+
7
8
  if args.kind_of?(Array) && args[0].kind_of?(Hash)
8
9
  args = args.first
9
10
  end
@@ -35,20 +36,43 @@ module JennCad::Primitives
35
36
  z: 0,
36
37
  },
37
38
  }.deep_merge!(args)
39
+ if args.kind_of? Array
40
+ args.each do |a|
41
+ feed_opts(parse_xyz_shortcuts(a))
42
+ end
43
+ else
44
+ feed_opts(parse_xyz_shortcuts(args))
45
+ end
46
+ init(args)
47
+
48
+
38
49
  handle_margins
39
50
  handle_diameter
40
- super(opts)
51
+ if @opts[:z] && opts[:z].to_d > 0
52
+ @dimensions = [:x, :y, :z]
53
+ else
54
+ @dimensions = [:x, :y]
55
+ end
56
+
41
57
  end
42
58
 
43
59
  def to_openscad
44
- return cube(@opts) if @d == 0
60
+ # FIXME: this check needs to be done on object creation
61
+ # otherwise it fails to position it
62
+ if @d == 0
63
+ if @z.to_d > 0
64
+ return cube(@opts)
65
+ else
66
+ return square(@opts)
67
+ end
68
+ end
45
69
  # make diameter not bigger than any side
46
70
  d = [@d, @x, @y].min
47
71
  res = HullObject.new(
48
- cylinder(d: d, h:z+z_margin),
49
- cylinder(d: d).move(x: @x - d, y: 0),
50
- cylinder(d: d).move(x: 0, y: @y - d),
51
- cylinder(d: d).move(x: @x - d, y: @y - d),
72
+ circle(d: d),
73
+ circle(d: d).move(x: @x - d, y: 0),
74
+ circle(d: d).move(x: 0, y: @y - d),
75
+ circle(d: d).move(x: @x - d, y: @y - d),
52
76
  )
53
77
  res = res.move(xy: d/2.0)
54
78
 
@@ -56,6 +80,10 @@ module JennCad::Primitives
56
80
  res += apply_flat_edge(edge)
57
81
  end
58
82
 
83
+ if @z.to_d > 0
84
+ res = res.extrude(z: @z + z_margin)
85
+ end
86
+
59
87
  res = union(res) # put everything we have in a parent union that we can apply the transformations of this object of
60
88
  res.transformations = @transformations
61
89
 
@@ -76,13 +104,13 @@ module JennCad::Primitives
76
104
  def apply_flat_edge(edge)
77
105
  case edge
78
106
  when :up, :top
79
- cube(x: @x, y: @y/2.0, z: @z).nc.moveh(y:@y)
107
+ square(x: @x, y: @y/2.0).nc.moveh(y:@y)
80
108
  when :down, :bottom
81
- cube(x: @x, y: @y/2.0, z: @z).nc
109
+ square(x: @x, y: @y/2.0).nc
82
110
  when :right
83
- cube(x: @x/2.0, y: @y, z: @z).nc.moveh(x:@x)
111
+ square(x: @x/2.0, y: @y).nc.moveh(x:@x)
84
112
  when :left
85
- cube(x: @x/2.0, y: @y, z: @z).nc
113
+ square(x: @x/2.0, y: @y).nc
86
114
  else
87
115
  nil
88
116
  end
@@ -0,0 +1,181 @@
1
+ module JennCad::Primitives
2
+ class Square < Primitive
3
+ attr_accessor :corners, :sides
4
+
5
+ def initialize(args)
6
+ @opts = {
7
+ x: 0,
8
+ y: 0,
9
+ margins: {
10
+ x: 0,
11
+ y: 0,
12
+ },
13
+ center: true,
14
+ center_y: false,
15
+ center_x: false,
16
+ }
17
+ if args.kind_of? Array
18
+ args.each do |a|
19
+ feed_opts(parse_xyz_shortcuts(a))
20
+ end
21
+ else
22
+ feed_opts(parse_xyz_shortcuts(args))
23
+ end
24
+ init(args)
25
+
26
+ handle_margins
27
+ set_anchors
28
+ @x = args[:x]
29
+ @y = args[:y]
30
+ @dimensions = [:x, :y]
31
+ end
32
+
33
+
34
+ # used for openscad export
35
+ def size
36
+ [@x, @y]
37
+ end
38
+
39
+ def set_anchors
40
+ set_anchors_2d
41
+ end
42
+
43
+ def set_anchors_2d
44
+ @anchors = {} # this resets anchors
45
+
46
+ if @opts[:center] || @opts[:center_x]
47
+ left = -@opts[:x] / 2.0
48
+ right = @opts[:x] / 2.0
49
+ mid_x = 0
50
+ else
51
+ left = 0
52
+ right = @opts[:x]
53
+ mid_x = @opts[:x] / 2.0
54
+ end
55
+ if @opts[:center] || @opts[:center_y]
56
+ bottom = -@opts[:y] / 2.0
57
+ top = @opts[:y] / 2.0
58
+ mid_y = 0
59
+ else
60
+ bottom = 0
61
+ top = @opts[:y]
62
+ mid_y = @opts[:y] / 2.0
63
+ end
64
+
65
+ set_anchor :left, x: left, y: mid_y
66
+ set_anchor :right, x: right, y: mid_y
67
+ set_anchor :top, x: mid_x, y: top
68
+ set_anchor :bottom, x: mid_x, y: bottom
69
+ set_anchor :top_left, x: left, y: top
70
+ set_anchor :top_right, x: right, y: top
71
+ set_anchor :bottom_left, x: left, y: bottom
72
+ set_anchor :bottom_right, x: right, y: bottom
73
+
74
+ # we need to re-do the inner ones, if they were defined
75
+ if @inner_anchor_defs && @inner_anchor_defs.size > 0
76
+ @inner_anchor_defs.each do |anch|
77
+ inner_anchors(anch[:dist], anch[:prefix], true)
78
+ end
79
+ end
80
+
81
+ self
82
+ end
83
+
84
+ def inner_anchors(dist, prefix=:inner_, recreate=false)
85
+ if dist.nil?
86
+ $log.error "Distance of nil passed to inner anchors. Please check the variable name you passed along"
87
+ return self
88
+ end
89
+
90
+ @inner_anchor_defs ||= []
91
+ @inner_anchor_defs << { "dist": dist, "prefix": prefix } unless recreate
92
+
93
+ # $log.info "dist: #{dist}, prefix: #{prefix}"
94
+ sides = {
95
+ left: {x: dist, y: 0},
96
+ right: {x: -dist, y: 0},
97
+ top: {x: 0, y: -dist},
98
+ bottom: {x: 0, y: dist},
99
+ }
100
+ corners = {
101
+ top_left: {x: dist, y: -dist},
102
+ top_right: {x: -dist, y: -dist},
103
+ bottom_left: {x: dist, y: dist},
104
+ bottom_right: {x: -dist, y: dist},
105
+ }
106
+ new_sides = []
107
+ new_corners = []
108
+
109
+ sides.merge(corners).each do |key, vals|
110
+ new_dist = anchor(key).dup
111
+ new_dist[:x] += vals[:x]
112
+ new_dist[:y] += vals[:y]
113
+ name = [prefix, key].join.to_sym
114
+ # $log.info "Set anchor #{name} , new dist #{new_dist}"
115
+ set_anchor name, new_dist
116
+ if sides.include? key
117
+ new_sides << name
118
+ end
119
+ if corners.include? key
120
+ new_corners << name
121
+ end
122
+ end
123
+
124
+ sides_name = [prefix, "sides"].join
125
+ corners_name = [prefix, "corners"].join
126
+ all_name = [prefix, "all"].join
127
+ self.class.__send__(:attr_accessor, sides_name.to_sym)
128
+ self.class.__send__(:attr_accessor, corners_name.to_sym)
129
+ self.class.__send__(:attr_accessor, all_name.to_sym)
130
+ self.__send__("#{sides_name}=", new_sides)
131
+ self.__send__("#{corners_name}=", new_corners)
132
+ self.__send__("#{all_name}=", new_corners+new_sides)
133
+
134
+
135
+ self
136
+ end
137
+
138
+
139
+
140
+ def not_centered
141
+ @opts[:center] = false
142
+ set_anchors
143
+ self
144
+ end
145
+ alias :nc :not_centered
146
+
147
+ def cx
148
+ nc
149
+ @opts[:center_x] = true
150
+ set_anchors
151
+ self
152
+ end
153
+ alias :center_x :cx
154
+
155
+ def cy
156
+ nc
157
+ @opts[:center_y] = true
158
+ set_anchors
159
+ self
160
+ end
161
+ alias :center_y :cy
162
+
163
+
164
+
165
+ def centered_axis
166
+ return [:x, :y] if @opts[:center]
167
+ a = []
168
+ a << :x if @opts[:center_x]
169
+ a << :y if @opts[:center_y]
170
+ a << :z if @opts[:center_z]
171
+ a
172
+ end
173
+
174
+ def to_openscad
175
+ self.mh(centered_axis.to_h{|a| [a, -@opts[a]] }) # center cube
176
+ end
177
+
178
+
179
+
180
+ end
181
+ end
@@ -60,9 +60,8 @@ module JennCad::Primitives
60
60
  add_z = nil
61
61
  if part.respond_to? :z
62
62
  part.opts[:margins] ||= {}
63
- if part.referenced_z && part.z != 0.0
63
+ if part.referenced_z && part.z != 0.0 && part.is_3d?
64
64
  case part
65
- when JennCad::Circle
66
65
  when JennCad::BooleanObject
67
66
  else
68
67
  # $log.debug part if part.opts[:debug]
@@ -89,7 +88,7 @@ module JennCad::Primitives
89
88
  move_z = 0.002
90
89
  end
91
90
 
92
- if add_z
91
+ if add_z && part.is_3d?
93
92
  if part.kind_of? Part
94
93
  part.modify_values(part, {z: add_z}, {mode: :add})
95
94
  end
@@ -1,5 +1,6 @@
1
1
  require "jenncad/primitives/primitive"
2
2
  require "jenncad/primitives/circle"
3
+ require "jenncad/primitives/square"
3
4
  require "jenncad/primitives/cylinder"
4
5
  require "jenncad/primitives/sphere"
5
6
  require "jenncad/primitives/cube"
@@ -3,6 +3,11 @@ module JennCad
3
3
  Circle.new(args).set_parent(self)
4
4
  end
5
5
 
6
+ def square(args)
7
+ Square.new(args).set_parent(self)
8
+ end
9
+ alias :sq :square
10
+
6
11
  def cylinder(*args)
7
12
  Cylinder.new(args).set_parent(self)
8
13
  end
@@ -36,6 +41,7 @@ module JennCad
36
41
  end
37
42
  alias :rcube :rounded_cube
38
43
  alias :rc :rounded_cube
44
+ alias :rsq :rounded_cube
39
45
 
40
46
  # import/use OpenScad library
41
47
  def import(import,name,args)
data/lib/jenncad/thing.rb CHANGED
@@ -11,6 +11,10 @@ module JennCad
11
11
  attr_accessor :parent
12
12
 
13
13
  def initialize(args={})
14
+ init(args)
15
+ end
16
+
17
+ def init(args={})
14
18
  @transformations = []
15
19
  # calculated origin; only works for move atm
16
20
  @calc_x = 0
@@ -18,7 +22,7 @@ module JennCad
18
22
  @calc_z = 0
19
23
  @calc_h = args[:z] || 0
20
24
  @anchors = {}
21
- @parent = args[:parent]
25
+ @parent = args[:parent] || nil
22
26
  @opts ||= args
23
27
  @cache = nil
24
28
  end
@@ -753,12 +757,25 @@ module JennCad
753
757
  end
754
758
  end
755
759
 
756
-
757
760
  def to_mod(name)
758
761
  a = Aggregation.new(name, self)
759
762
  a.transformations = @transformations
760
763
  a
761
764
  end
762
765
 
766
+ def is_2d?
767
+ !is_3d?
768
+ end
769
+
770
+ def is_3d?
771
+ if self.respond_to?(:dimensions) && self.dimensions
772
+ return true if self.dimensions && self.dimensions.include?(:z)
773
+ else
774
+ # assume true if not set
775
+ return true
776
+ end
777
+ false
778
+ end
779
+
763
780
  end
764
781
  end
@@ -1,3 +1,3 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha16"
2
+ VERSION = "1.0.0-alpha17"
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.alpha16
4
+ version: 1.0.0.pre.alpha17
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-14 00:00:00.000000000 Z
11
+ date: 2022-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d
@@ -144,6 +144,7 @@ files:
144
144
  - lib/jenncad/primitives/rounded_cube.rb
145
145
  - lib/jenncad/primitives/slot.rb
146
146
  - lib/jenncad/primitives/sphere.rb
147
+ - lib/jenncad/primitives/square.rb
147
148
  - lib/jenncad/primitives/subtract_object.rb
148
149
  - lib/jenncad/primitives/union_object.rb
149
150
  - lib/jenncad/profile_loader.rb