crystalscad 0.5.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -455,7 +455,10 @@ module CrystalScad
455
455
  @attributes = attributes
456
456
  end
457
457
 
458
- def to_rubyscad
458
+ def to_rubyscad
459
+ # Apparently this doesn't work for CSGModifiers, like it does for other things in RubyScad?
460
+ # also this is a dirty, dirty hack.
461
+ @attributes = @attributes.gsub("fn","$fn").gsub("$$","$")
459
462
  ret = "#{@operation}(#{@attributes}){"
460
463
  @children ||= []
461
464
  @children.each do |child|
@@ -521,12 +524,12 @@ module CrystalScad
521
524
  return LinearExtrude.new(self,args)
522
525
  end
523
526
 
524
- def rotate_extrude(args)
527
+ def rotate_extrude(args={})
525
528
  if args[:h] # rename to height
526
529
  args[:height] = args[:h]
527
530
  args.delete(:h)
528
531
  end
529
- args = args.collect { |k, v| "#{k} = #{v}" }.join(', ')
532
+ args = args.collect { |k, v| "#{k} = #{v}" }.join(', ')
530
533
  return RotateExtrude.new(self,args)
531
534
  end
532
535
 
@@ -17,19 +17,33 @@
17
17
 
18
18
  module CrystalScad
19
19
  class Pipe
20
- attr_accessor :x,:y, :pipe
20
+ attr_accessor :x,:y, :sum_x, :sum_y, :pipe, :bent_segments
21
+ # Warning: sum_x and sum_y are both a quick hack at the moment
22
+ # They will ONLY work on bends if you do same thing in the other direction
23
+ # for example
24
+ # pipe.cw(20,30)
25
+ # pipe.ccw(20,30)
26
+ # This might be fixed in the future.
27
+
21
28
  def radians(a)
22
29
  a/180.0 * Math::PI
23
30
  end
24
31
 
25
32
  def initialize(args={})
26
- @diameter = args[:diameter]
33
+ # parameters
34
+ @diameter = args[:diameter] || 1
35
+ @fn = args[:fn] || 64
36
+ @bent_segments = args[:bent_segments] || 128
37
+ @line_rotation = args[:line_rotation] || 0 # z rotation in case needed with fn values
38
+
39
+ # variable initialization
27
40
  @pipe = nil
28
- @line_rotation = 0 # z rotation in case needed with fn values
41
+ @sum_x = 0
42
+ @sum_y = 0
29
43
  end
30
44
 
31
45
  def shape
32
- res = circle(d:@diameter)
46
+ res = circle(d:@diameter,fn:@fn)
33
47
  end
34
48
 
35
49
  def inner_shape
@@ -85,7 +99,7 @@ module CrystalScad
85
99
  else
86
100
  @pipe = @pipe.translate(x:length) + create_line(length,color)
87
101
  end
88
-
102
+ @sum_x += length
89
103
  end
90
104
 
91
105
  private
@@ -101,8 +115,8 @@ module CrystalScad
101
115
  end
102
116
 
103
117
  def bent_cw(radius,angle)
104
- res = shape.translate(x:radius).rotate_extrude(convexity:10)
105
- res -= inner_shape.translate(x:radius).rotate_extrude(convexity:10) unless inner_shape == nil
118
+ res = shape.translate(x:radius).rotate_extrude(fn:@bent_segments)
119
+ res -= inner_shape.translate(x:radius).rotate_extrude(fn:@bent_segments) unless inner_shape == nil
106
120
 
107
121
  len = radius+@diameter/2.0
108
122
  @x = Math::sin(radians(angle))*len
@@ -114,6 +128,8 @@ module CrystalScad
114
128
  @x = Math::sin(radians(angle))*len
115
129
  @y = Math::cos(radians(angle))*len
116
130
 
131
+ @sum_x += @x
132
+ @sum_y += @y
117
133
 
118
134
  res *= cut.linear_extrude(h:100).translate(z:-50)
119
135
 
@@ -123,8 +139,8 @@ module CrystalScad
123
139
  end
124
140
 
125
141
  def bent_ccw(radius,angle)
126
- res = shape.translate(x:radius).rotate_extrude(convexity:10)
127
- res -= inner_shape.translate(x:radius).rotate_extrude(convexity:10) unless inner_shape == nil
142
+ res = shape.translate(x:radius).rotate_extrude(fn:@bent_segments)
143
+ res -= inner_shape.translate(x:radius).rotate_extrude(fn:@bent_segments) unless inner_shape == nil
128
144
 
129
145
  len = radius+@diameter/2.0
130
146
  @x = Math::sin(radians(angle))*len
@@ -136,6 +152,8 @@ module CrystalScad
136
152
  @x = Math::sin(radians(angle))*len
137
153
  @y = -1*Math::cos(radians(angle))*len
138
154
 
155
+ @sum_x += @x
156
+ @sum_y += @y
139
157
 
140
158
  res *= cut.linear_extrude(h:100).translate(z:-50)
141
159
  res = res.mirror(y:1)
@@ -1,4 +1,4 @@
1
1
  module CrystalScad
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.3"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crystalscad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
9
+ - 3
10
+ version: 0.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joachim Glauche
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2015-04-09 00:00:00 Z
18
+ date: 2015-04-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rubyscad