jenncad 1.0.0.pre.alpha15 → 1.0.0.pre.alpha18
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 +4 -4
- data/lib/jenncad/commands.rb +6 -6
- data/lib/jenncad/exporters/openscad.rb +7 -3
- data/lib/jenncad/features/aggregation.rb +1 -0
- data/lib/jenncad/part.rb +46 -1
- data/lib/jenncad/primitives/circle.rb +102 -4
- data/lib/jenncad/primitives/cube.rb +4 -142
- data/lib/jenncad/primitives/cylinder.rb +11 -57
- data/lib/jenncad/primitives/linear_extrude.rb +1 -1
- data/lib/jenncad/primitives/polygon.rb +5 -2
- data/lib/jenncad/primitives/polyhedron.rb +35 -0
- data/lib/jenncad/primitives/primitive.rb +20 -1
- data/lib/jenncad/primitives/rounded_cube.rb +43 -14
- data/lib/jenncad/primitives/slot.rb +69 -6
- data/lib/jenncad/primitives/square.rb +181 -0
- data/lib/jenncad/primitives/subtract_object.rb +21 -9
- data/lib/jenncad/primitives.rb +2 -0
- data/lib/jenncad/shortcuts.rb +10 -0
- data/lib/jenncad/thing.rb +125 -9
- data/lib/jenncad/version.rb +1 -1
- data/lib/jenncad.rb +0 -1
- data/todo.txt +6 -10
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d05a39eda135dbbda74bcdc75c66a4c9d7620e426d5656e377442dcc17ef665
|
4
|
+
data.tar.gz: 1514fd3b8ecc502f95c0a9a7e93e13622e706d518abe31f7af4e60d56d85f357
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea62b48418d86b7daa3f2ddcb895d03494942dea723fd60de9f81cbd25aab1d6aefd801136258192ab18b0dc9803cfe368cfb3f5b8bb1a33288eade384b7b96
|
7
|
+
data.tar.gz: e25c9f138b698f5c041dc7d0455a06807fe26ba12663039a9c522f0433d7435f3ecebdb72031069e81dea24414a8b0cfec76809a20bdedc50ab76442e7380b65
|
data/lib/jenncad/commands.rb
CHANGED
@@ -118,15 +118,15 @@ module JennCad
|
|
118
118
|
File.open(filename, "w") do |f|
|
119
119
|
f.puts "class #{classname} < Part"
|
120
120
|
f.puts " def initialize(opts={})"
|
121
|
-
f.puts " @
|
122
|
-
f.puts "
|
123
|
-
f.puts "
|
124
|
-
f.puts " z: 5,"
|
125
|
-
f.puts " }.merge(opts)"
|
121
|
+
f.puts " @x = 10"
|
122
|
+
f.puts " @y = 10"
|
123
|
+
f.puts " @z = 5"
|
126
124
|
f.puts " end"
|
127
125
|
f.puts ""
|
128
126
|
f.puts " def part"
|
129
|
-
f.puts " cube(@
|
127
|
+
f.puts " base = cube(x: @x, y: @y, z: @z)"
|
128
|
+
f.puts " res = base.fix"
|
129
|
+
f.puts " res"
|
130
130
|
f.puts " end"
|
131
131
|
f.puts "end"
|
132
132
|
end
|
@@ -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
|
@@ -178,6 +180,8 @@ module JennCad::Exporters
|
|
178
180
|
new_obj(part, :projection, collect_params(part), parse(part.parts))
|
179
181
|
when JennCad::Primitives::Polygon
|
180
182
|
new_obj(part, :polygon, collect_params(part))
|
183
|
+
when JennCad::Primitives::Polyhedron
|
184
|
+
new_obj(part, :polyhedron, collect_params(part))
|
181
185
|
when JennCad::StlImport
|
182
186
|
new_obj(part, :import, collect_params(part))
|
183
187
|
when JennCad::Part
|
@@ -212,7 +216,7 @@ module JennCad::Exporters
|
|
212
216
|
return part.openscad_params
|
213
217
|
end
|
214
218
|
res = {}
|
215
|
-
[:d, :h, :d1, :d2, :size, :fn, :points, :file].each do |var|
|
219
|
+
[:d, :h, :d1, :d2, :size, :fn, :points, :paths, :faces, :convexity, :file].each do |var|
|
216
220
|
if part.respond_to? var
|
217
221
|
res[var] = part.send var
|
218
222
|
end
|
data/lib/jenncad/part.rb
CHANGED
@@ -1,9 +1,54 @@
|
|
1
|
+
module AutoName
|
2
|
+
def initialize(args={})
|
3
|
+
unless args.empty?
|
4
|
+
@auto_name = "#{self.class}_#{args.map{|key, val| "#{key}_#{val}"}.join('_')}"
|
5
|
+
end
|
6
|
+
super(args)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
1
10
|
module JennCad
|
2
11
|
# Part should be inherited from the user when making parts
|
3
12
|
class Part < Thing
|
13
|
+
def self.inherited(subclass)
|
14
|
+
subclass.prepend(AutoName) if subclass.superclass == Part
|
15
|
+
end
|
16
|
+
|
17
|
+
# this function both gets and defines hardware
|
18
|
+
def hardware(hw_type=nil, args={})
|
19
|
+
@_hw ||= {}
|
20
|
+
if hw_type == nil
|
21
|
+
return @_hw
|
22
|
+
end
|
23
|
+
|
24
|
+
anchors = args[:anchor] || args[:anchors]
|
25
|
+
unless anchors.kind_of? Array
|
26
|
+
anchors = [anchors]
|
27
|
+
end
|
28
|
+
|
29
|
+
anchors.each do |a|
|
30
|
+
@_hw[a] = {
|
31
|
+
hw_type: hw_type,
|
32
|
+
size: args[:size],
|
33
|
+
d: args[:d],
|
34
|
+
len: args[:len],
|
35
|
+
pos: anchor(a, args[:from]),
|
36
|
+
}
|
37
|
+
end
|
38
|
+
self
|
39
|
+
end
|
40
|
+
alias :hw :hardware
|
41
|
+
|
42
|
+
def fix_name_for_openscad(name)
|
43
|
+
[":", ",", ".", "[", "]","-", " "].each do |key|
|
44
|
+
name.gsub!(key, "_")
|
45
|
+
end
|
46
|
+
name
|
47
|
+
end
|
4
48
|
|
5
49
|
def to_openscad
|
6
|
-
|
50
|
+
name = @name || @auto_name || self.class.to_s
|
51
|
+
a = Aggregation.new(fix_name_for_openscad(name), self.get_contents)
|
7
52
|
a.transformations = @transformations
|
8
53
|
if self.has_explicit_color?
|
9
54
|
a.color(self.color)
|
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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 <
|
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
|
-
|
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,95 +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
|
-
@inner_anchor_defs ||= []
|
105
|
-
@inner_anchor_defs << { "dist": dist, "prefix": prefix } unless recreate
|
106
|
-
|
107
|
-
# $log.info "dist: #{dist}, prefix: #{prefix}"
|
108
|
-
sides = {
|
109
|
-
left: {x: dist, y: 0},
|
110
|
-
right: {x: -dist, y: 0},
|
111
|
-
top: {x: 0, y: -dist},
|
112
|
-
bottom: {x: 0, y: dist},
|
113
|
-
}
|
114
|
-
corners = {
|
115
|
-
top_left: {x: dist, y: -dist},
|
116
|
-
top_right: {x: -dist, y: -dist},
|
117
|
-
bottom_left: {x: dist, y: dist},
|
118
|
-
bottom_right: {x: -dist, y: dist},
|
119
|
-
}
|
120
|
-
new_sides = []
|
121
|
-
new_corners = []
|
122
|
-
|
123
|
-
sides.merge(corners).each do |key, vals|
|
124
|
-
new_dist = anchor(key).dup
|
125
|
-
new_dist[:x] += vals[:x]
|
126
|
-
new_dist[:y] += vals[:y]
|
127
|
-
name = [prefix, key].join.to_sym
|
128
|
-
# $log.info "Set anchor #{name} , new dist #{new_dist}"
|
129
|
-
set_anchor name, new_dist
|
130
|
-
if sides.include? key
|
131
|
-
new_sides << name
|
132
|
-
end
|
133
|
-
if corners.include? key
|
134
|
-
new_corners << name
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
sides_name = [prefix, "sides"].join
|
139
|
-
corners_name = [prefix, "corners"].join
|
140
|
-
all_name = [prefix, "all"].join
|
141
|
-
self.class.__send__(:attr_accessor, sides_name.to_sym)
|
142
|
-
self.class.__send__(:attr_accessor, corners_name.to_sym)
|
143
|
-
self.class.__send__(:attr_accessor, all_name.to_sym)
|
144
|
-
self.__send__("#{sides_name}=", new_sides)
|
145
|
-
self.__send__("#{corners_name}=", new_corners)
|
146
|
-
self.__send__("#{all_name}=", new_corners+new_sides)
|
147
|
-
|
148
|
-
|
149
|
-
self
|
150
|
-
end
|
151
|
-
|
152
|
-
|
153
52
|
# used for openscad export
|
154
53
|
def size
|
155
54
|
[@x, @y, z+z_margin]
|
156
55
|
end
|
157
56
|
|
158
|
-
def not_centered
|
159
|
-
@opts[:center] = false
|
160
|
-
set_anchors
|
161
|
-
self
|
162
|
-
end
|
163
|
-
alias :nc :not_centered
|
164
|
-
|
165
|
-
def cx
|
166
|
-
nc
|
167
|
-
@opts[:center_x] = true
|
168
|
-
set_anchors
|
169
|
-
self
|
170
|
-
end
|
171
|
-
alias :center_x :cx
|
172
|
-
|
173
|
-
def cy
|
174
|
-
nc
|
175
|
-
@opts[:center_y] = true
|
176
|
-
set_anchors
|
177
|
-
self
|
178
|
-
end
|
179
|
-
alias :center_y :cy
|
180
|
-
|
181
|
-
|
182
57
|
def cz
|
183
58
|
nc
|
184
59
|
@opts[:center_z] = true
|
@@ -187,18 +62,5 @@ module JennCad::Primitives
|
|
187
62
|
end
|
188
63
|
alias :center_z :cz
|
189
64
|
|
190
|
-
def centered_axis
|
191
|
-
return [:x, :y] if @opts[:center]
|
192
|
-
a = []
|
193
|
-
a << :x if @opts[:center_x]
|
194
|
-
a << :y if @opts[:center_y]
|
195
|
-
a << :z if @opts[:center_z]
|
196
|
-
a
|
197
|
-
end
|
198
|
-
|
199
|
-
def to_openscad
|
200
|
-
self.mh(centered_axis.to_h{|a| [a, -@opts[a]] }) # center cube
|
201
|
-
end
|
202
|
-
|
203
65
|
end
|
204
66
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module JennCad::Primitives
|
2
|
-
class Cylinder <
|
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
|
-
|
44
|
+
@dimensions = [:x, :y, :z]
|
45
45
|
set_anchors
|
46
46
|
end
|
47
47
|
|
48
48
|
def set_anchors
|
49
|
-
|
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,52 +79,18 @@ 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
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
88
|
+
def z=(val)
|
89
|
+
@z = val
|
90
|
+
@h = val
|
91
|
+
opts[:h] = val
|
92
|
+
opts[:z] = val
|
93
|
+
set_anchors
|
140
94
|
end
|
141
95
|
|
142
96
|
def h
|
@@ -1,9 +1,12 @@
|
|
1
1
|
module JennCad::Primitives
|
2
2
|
class Polygon < Primitive
|
3
|
-
attr_accessor :points
|
3
|
+
attr_accessor :points, :paths
|
4
4
|
def initialize(args)
|
5
|
-
super
|
6
5
|
@points = args[:points]
|
6
|
+
@paths = args[:paths]
|
7
|
+
@convexity = args[:convexity] || 10
|
8
|
+
@dimensions = [:x, :y]
|
9
|
+
super
|
7
10
|
end
|
8
11
|
end
|
9
12
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module JennCad::Primitives
|
2
|
+
class Polyhedron < Primitive
|
3
|
+
attr_accessor :points, :faces, :convexity
|
4
|
+
def initialize(args)
|
5
|
+
@opts = args
|
6
|
+
@points = args[:points]
|
7
|
+
@faces = args[:faces]
|
8
|
+
@convexity = args[:convexity] || 10
|
9
|
+
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def face(i)
|
14
|
+
unless @faces[i]
|
15
|
+
$log.error "polyhedron: Cannot find face #{i}"
|
16
|
+
return self
|
17
|
+
end
|
18
|
+
face = 0
|
19
|
+
poly_faces = []
|
20
|
+
poly_points = []
|
21
|
+
@faces[i].each do |f|
|
22
|
+
point = @points[f]
|
23
|
+
if point.nil?
|
24
|
+
$log.error "polyhedron: Cannot find point #{f} for face #{i}"
|
25
|
+
end
|
26
|
+
poly_points << point
|
27
|
+
poly_faces << face
|
28
|
+
face += 1
|
29
|
+
#poly_points << [point[0], point[1]]
|
30
|
+
end
|
31
|
+
#polygon(points: poly_points)
|
32
|
+
polyhedron(points: poly_points, faces: [poly_faces, poly_faces.reverse])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
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
|
-
|
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
|