jenncad 1.0.0.pre.alpha2 → 1.0.0.pre.alpha3

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: ef018e45bc6303b2a45c2ad3340d714cb340288465936f23293961fbc2615cd4
4
- data.tar.gz: 1ee41eb205053ad3ea4e0d1b8c76b4fa13c98f212393e71008e96f1303b0f9c7
3
+ metadata.gz: b3b2667c6121606bece58cc0edbb2d7c0e0f2454dc175b62c3749209c1eef266
4
+ data.tar.gz: d8dbc84a707b0767374830df107ebcb098b89591664f0f7062468404b0c512e2
5
5
  SHA512:
6
- metadata.gz: b9541672a102b371b7a517be6d015ca1bc6e4f81fae97761399514733870bc1b0c67094b6a6e177c1c5af7d85416067e9b6dab024bff275b4537013f88072fc2
7
- data.tar.gz: 44d0ae2e9aefb56e1964cf2e0fdf0590be5fc600abea1d65f3edcf40fca03a57bf6e107020dd26ec2ffac6a3f4c9f6b6f3688cdbcb72489766984b3011c8abd3
6
+ metadata.gz: e512b91a4c6355cfd1b516bc52e434b1670e5aae02b39d75581e423a6242a90b11257a4c4902e30db74de0d4c1693aa7608829393df45806ecf56fc3e409bce9
7
+ data.tar.gz: 26fad5ebe17ad65610283315c2c33d9d7842717b78ad8560029038238b18c88aa351667a395f24ef134cf3f9fce298fcb1528ca459c7aeebfe618d71a5186233
data/lib/jenncad.rb CHANGED
@@ -20,10 +20,10 @@ require "jenncad/part"
20
20
  require "jenncad/project"
21
21
  require "jenncad/commands"
22
22
 
23
+ require "jenncad/features"
23
24
  require "jenncad/primitives"
24
25
 
25
26
 
26
-
27
27
  require "jenncad/transformation/transformation"
28
28
  require "jenncad/transformation/move"
29
29
  require "jenncad/transformation/rotate"
@@ -221,6 +221,8 @@ module JennCad::Exporters
221
221
  OpenScadObject.new(:translate, t.coordinates, transform(part, &block))
222
222
  when JennCad::Rotate, JennCad::Mirror
223
223
  OpenScadObject.new(demodulize(t.class).downcase, t.coordinates, transform(part, &block))
224
+ when JennCad::Scale
225
+ OpenScadObject.new(:scale, t.scale, transform(part, &block))
224
226
  when JennCad::Multmatrix
225
227
  OpenScadObject.new(:multmatrix, t.m, transform(part, &block))
226
228
  else
@@ -0,0 +1,9 @@
1
+ require "jenncad/features/feature"
2
+ require "jenncad/features/aggregation"
3
+ require "jenncad/features/cuttable"
4
+ require "jenncad/features/openscad_include"
5
+ require "jenncad/features/climb"
6
+
7
+ module JennCad
8
+ include Features
9
+ end
@@ -1,5 +1,5 @@
1
- module JennCad::Primitives
2
- class Aggregation < Primitive
1
+ module JennCad::Features
2
+ class Aggregation < Feature
3
3
  attr_accessor :part
4
4
 
5
5
  def initialize(name=nil, part=nil)
@@ -0,0 +1,95 @@
1
+ module JennCad::Features
2
+ class Climb < Feature
3
+ def initialize(opts, block)
4
+ @opts = {
5
+ offset: :auto,
6
+ step: nil,
7
+ steps: nil,
8
+ bottom: nil,
9
+ top: nil,
10
+ z: nil,
11
+ }.deep_merge!(opts)
12
+ if @opts[:step].nil? && @opts[:steps].nil?
13
+ raise "please define at least one of :step or :steps for climb"
14
+ end
15
+ super(@opts)
16
+ @block = block
17
+ end
18
+
19
+ def z_or_referenced
20
+ case z = @opts[:z]
21
+ when nil
22
+ referenced_z.z
23
+ else
24
+ z
25
+ end
26
+ end
27
+
28
+ def get_step(z)
29
+ case step = @opts[:step]
30
+ when nil, :auto, 0, 0.0
31
+ steps = @opts[:steps]
32
+ (z / steps).floor
33
+ else
34
+ step.to_f
35
+ end
36
+ end
37
+
38
+ def get_offset(z)
39
+ case offset = @opts[:offset]
40
+ when :auto
41
+ step = get_step(z)
42
+ ((z % step) + step) / 2.0
43
+ when nil, 0, 0.0
44
+ 0.0
45
+ else
46
+ offset
47
+ end
48
+ end
49
+
50
+ def climb_from_bottom(offset, step, n)
51
+ n.times.map{ |i| @block.yield.mz(offset+step*i) }.union
52
+ end
53
+
54
+ def climb_from_top(z, offset, step, n)
55
+ n.times.map{ |i| @block.yield.mz(z-offset-step*i) }.union
56
+ end
57
+
58
+ def to_openscad
59
+ ref_z = z_or_referenced
60
+ step = get_step(ref_z)
61
+ steps, top, bottom = @opts.values_at(:steps, :top, :bottom)
62
+
63
+ offset = get_offset(ref_z)
64
+
65
+ lo = (ref_z-offset*2).to_f % step.to_f
66
+ unless lo.to_f == 0.0
67
+ puts "[Warning]: climb has leftover offset #{lo}"
68
+ end
69
+
70
+ if steps
71
+ top = steps
72
+ bottom = steps
73
+ end
74
+
75
+ unless top or bottom
76
+ climb_from_bottom(offset, step, ((ref_z-offset*2) / step).floor + 1 )
77
+ else
78
+ res = nil
79
+ if top
80
+ res += climb_from_top(ref_z, offset, step, top)
81
+ end
82
+ if bottom
83
+ res += climb_from_bottom(offset, step, bottom)
84
+ end
85
+ res
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ def climb(args, &block)
92
+ Climb.new(args, block)
93
+ end
94
+
95
+ end
@@ -0,0 +1,35 @@
1
+ module JennCad::Features
2
+ module Cuttable
3
+ def cut(args, &block)
4
+ if args[:x]
5
+ l = args[:x].min * @opts[:y] / 2.0
6
+ r = args[:x].max * @opts[:y] / 2.0
7
+ prepare_cut(l, r, &block).flip_x
8
+ elsif args[:y]
9
+ l = args[:y].min * @opts[:y] / 2.0
10
+ r = args[:y].max * @opts[:y] / 2.0
11
+ prepare_cut(l, r, &block).flip_y
12
+ elsif args[:z]
13
+ raise "cut for Z is not implemented yet"
14
+ end
15
+ end
16
+
17
+ def prepare_cut(l, r, &block)
18
+ part = block.call
19
+ if part.z.to_f > 0.0
20
+ part.opts[:margins][:z] = 0.2
21
+ if l == 0.0
22
+ part.mz(r+0.1)
23
+ else
24
+ part.mz(l+part.z.to_f-0.2)
25
+ end
26
+ else
27
+ part.opts[:margins][:z] = 0.2
28
+ part.z = l.abs + r.abs + 0.2
29
+ part.mz(-0.1)
30
+ end
31
+ end
32
+
33
+
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module JennCad::Features
2
+ class Feature < JennCad::Thing
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module JennCad::Primitives
1
+ module JennCad::Features
2
2
  class OpenScadImport < Aggregation
3
3
  attr_accessor :import, :args
4
4
 
@@ -12,8 +12,7 @@ class Array
12
12
  else
13
13
  res = part
14
14
  end
15
- # FIXME: I added 0.01 to all for now to fix z-fighting issues; this should not be hardcoded like this
16
- res, z = res.move(z:z), z + res.z.to_f + 0.01 unless skip_z
15
+ res, z = res.mz(z), z + res.z.to_f unless skip_z
17
16
  res
18
17
  end
19
18
  .union
@@ -1,6 +1,4 @@
1
1
  require "jenncad/primitives/primitive"
2
- require "jenncad/primitives/aggregation"
3
- require "jenncad/primitives/openscad_include"
4
2
  require "jenncad/primitives/circle"
5
3
  require "jenncad/primitives/cylinder"
6
4
  require "jenncad/primitives/sphere"
@@ -1,5 +1,6 @@
1
1
  module JennCad::Primitives
2
2
  class Cube < Primitive
3
+ extend JennCad::Features::Cuttable
3
4
 
4
5
  def initialize(args)
5
6
  if args.kind_of?(Array) && args[0].kind_of?(Hash)
@@ -1,6 +1,7 @@
1
1
  module JennCad::Primitives
2
2
  class RoundedCube < Primitive
3
3
  attr_accessor :d, :r
4
+ include JennCad::Features::Cuttable
4
5
 
5
6
  def initialize(args)
6
7
  if args.kind_of?(Array) && args[0].kind_of?(Hash)
@@ -40,7 +41,7 @@ module JennCad::Primitives
40
41
  # make diameter not bigger than any side
41
42
  @d = [@d, @x, @y].min
42
43
  res = HullObject.new(
43
- cylinder(d:@d, h:@z+z_margin).moveh(x: -@x + @d, y: @y - @d),
44
+ cylinder(d:@d, h:z+z_margin).moveh(x: -@x + @d, y: @y - @d),
44
45
  cylinder(d:@d).moveh(x: @x - @d, y: @y - @d),
45
46
  cylinder(d:@d).moveh(x: -@x + @d, y: -@y + @d),
46
47
  cylinder(d:@d).moveh(x: @x - @d, y: -@y + @d),
data/lib/jenncad/thing.rb CHANGED
@@ -6,7 +6,7 @@ module JennCad
6
6
  attr_accessor :x, :y, :diameter
7
7
  attr_accessor :calc_x, :calc_y, :calc_z, :calc_h
8
8
  attr_accessor :shape
9
- attr_accessor :angle, :cut, :fn
9
+ attr_accessor :angle, :fn
10
10
 
11
11
  def initialize(args={})
12
12
  @transformations = []
@@ -49,17 +49,22 @@ module JennCad
49
49
 
50
50
  def flip(direction)
51
51
  case self
52
+ when UnionObject
53
+ ref = self.parts.first
54
+ rz = self.z.to_f + self.calc_h.to_f
52
55
  when BooleanObject
53
56
  ref = self.parts.first
57
+ rz = ref.calc_z + ref.calc_h
54
58
  else
55
59
  ref = self
60
+ rz = self.z + self.calc_h
56
61
  end
57
62
 
58
63
  case direction
59
64
  when :x
60
- self.ry(90).mh(x: -ref.z, z: ref.x)
65
+ self.ry(90).mh(x: -rz, z: ref.x)
61
66
  when :y
62
- self.rx(90).mh(y: ref.z, z: ref.y)
67
+ self.rx(90).mh(y: rz, z: ref.y)
63
68
  end
64
69
  end
65
70
 
@@ -1,7 +1,9 @@
1
1
  module JennCad
2
+ attr_accessor :scale
2
3
  class Scale < Transformation
3
4
  def initialize(args)
4
5
  super(args)
6
+ @scale = args
5
7
  end
6
8
  end
7
9
  end
@@ -1,4 +1,4 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha2"
2
+ VERSION = "1.0.0-alpha3"
3
3
  end
4
4
 
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.alpha2
4
+ version: 1.0.0.pre.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jennifer Glauche
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-28 00:00:00.000000000 Z
11
+ date: 2019-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d
@@ -108,10 +108,15 @@ files:
108
108
  - lib/jenncad/extras/din934.rb
109
109
  - lib/jenncad/extras/hardware.rb
110
110
  - lib/jenncad/extras/iso7380.rb
111
+ - lib/jenncad/features.rb
112
+ - lib/jenncad/features/aggregation.rb
113
+ - lib/jenncad/features/climb.rb
114
+ - lib/jenncad/features/cuttable.rb
115
+ - lib/jenncad/features/feature.rb
116
+ - lib/jenncad/features/openscad_include.rb
111
117
  - lib/jenncad/part.rb
112
118
  - lib/jenncad/patches/array.rb
113
119
  - lib/jenncad/primitives.rb
114
- - lib/jenncad/primitives/aggregation.rb
115
120
  - lib/jenncad/primitives/boolean_object.rb
116
121
  - lib/jenncad/primitives/circle.rb
117
122
  - lib/jenncad/primitives/cube.rb
@@ -119,7 +124,6 @@ files:
119
124
  - lib/jenncad/primitives/hull_object.rb
120
125
  - lib/jenncad/primitives/intersection_object.rb
121
126
  - lib/jenncad/primitives/linear_extrude.rb
122
- - lib/jenncad/primitives/openscad_include.rb
123
127
  - lib/jenncad/primitives/polygon.rb
124
128
  - lib/jenncad/primitives/primitive.rb
125
129
  - lib/jenncad/primitives/projection.rb