Class: CrystalScad::Pipe

Inherits:
Assembly show all
Defined in:
lib/crystalscad/Pipe.rb

Instance Attribute Summary collapse

Attributes inherited from Assembly

#color, #hardware, #skip, #transformations, #z

Attributes inherited from Primitive

#children

Attributes inherited from CrystalScadObject

#args, #transformations

Instance Method Summary collapse

Methods inherited from Assembly

#*, #+, #-, #add_to_bom, #colorize, #description, get_skip, get_views, #method_missing, #output, #part, #scad_output, #show, #show_hardware, skip, #threads, #transform, view, #walk_tree

Methods inherited from Primitive

#mirror, #rotate, #rotate_around, #scale, #transform, #translate, #union

Methods inherited from CrystalScadObject

#method_missing, #save, #to_rubyscad, #walk_tree, #walk_tree_classes

Constructor Details

#initialize(args = {}) ⇒ Pipe

Returns a new instance of Pipe.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/crystalscad/Pipe.rb', line 32

def initialize(args={})
	# parameters
	@diameter = args[:diameter] || 1
	@fn = args[:fn] || 64
	@bent_segments = args[:bent_segments] || 128
	@line_rotation = args[:line_rotation] || 0 # z rotation in case needed with fn values

	# variable initialization
	@pipe = nil	
	@sum_x = 0
	@sum_y = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CrystalScad::Assembly

Instance Attribute Details

#bent_segmentsObject

Returns the value of attribute bent_segments.



20
21
22
# File 'lib/crystalscad/Pipe.rb', line 20

def bent_segments
  @bent_segments
end

#pipeObject

Returns the value of attribute pipe.



20
21
22
# File 'lib/crystalscad/Pipe.rb', line 20

def pipe
  @pipe
end

#sum_xObject

Returns the value of attribute sum_x.



20
21
22
# File 'lib/crystalscad/Pipe.rb', line 20

def sum_x
  @sum_x
end

#sum_yObject

Returns the value of attribute sum_y.



20
21
22
# File 'lib/crystalscad/Pipe.rb', line 20

def sum_y
  @sum_y
end

#xObject

Returns the value of attribute x.



20
21
22
# File 'lib/crystalscad/Pipe.rb', line 20

def x
  @x
end

#yObject

Returns the value of attribute y.



20
21
22
# File 'lib/crystalscad/Pipe.rb', line 20

def y
  @y
end

Instance Method Details

#apply_rotation(obj) ⇒ Object

This will be called on bent, so this library can work with rectangle pipes, if you overwrite this and let it rotate z by 90



54
55
56
# File 'lib/crystalscad/Pipe.rb', line 54

def apply_rotation(obj)
	return obj		
end

#ccw(radius, angle, color = nil) ⇒ Object

go counter clockwise



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/crystalscad/Pipe.rb', line 80

def ccw(radius,angle,color=nil)
	if angle > 360
		return false		
	end		
	# since bent can only do up to 90°, splitting it up in chunks in order to grow it 
	if angle > 90
		return ccw(radius,90,color) + ccw(radius,angle-90,color)	
	end

	if @pipe == nil
		@pipe = bent_ccw(radius,angle)	
		@pipe = @pipe.color(color) unless color == nil
	else
		rotated_pipe = @pipe.rotate(z:angle)	
		pipe_piece = bent_ccw(radius,angle)
		pipe_piece = pipe_piece.color(color) unless color == nil
		@pipe = pipe_piece + rotated_pipe.translate(x:x,y:y+radius)
	end	
	
end

#cw(radius, angle, color = nil) ⇒ Object

go clockwise



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/crystalscad/Pipe.rb', line 59

def cw(radius,angle,color=nil)
	if angle > 360
		return false		
	end		
	# since bent can only do up to 90°, splitting it up in chunks in order to grow it 
	if angle > 90
		return cw(radius,90,color) + cw(radius,angle-90,color)	
	end

	if @pipe == nil
		@pipe = bent_cw(radius,angle)	
		@pipe = @pipe.color(color) unless color == nil
	else
		rotated_pipe = @pipe.rotate(z:-angle)	
		pipe_piece = bent_cw(radius,angle)
		pipe_piece = pipe_piece.color(color) unless color == nil
		@pipe = pipe_piece + rotated_pipe.translate(x:x,y:y-radius)
	end	
end

#inner_shapeObject



49
50
51
# File 'lib/crystalscad/Pipe.rb', line 49

def inner_shape
	nil
end

#line(length, color = nil) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/crystalscad/Pipe.rb', line 101

def line(length,color=nil)
	if @pipe == nil
		@pipe = create_line(length,color) 
	else
		@pipe = @pipe.translate(x:length) + create_line(length,color)				
	end
	@sum_x += length
end

#radians(a) ⇒ Object

Warning: sum_x and sum_y are both a quick hack at the moment They will ONLY work on bends if you do same thing in the other direction for example pipe.cw(20,30) pipe.ccw(20,30) This might be fixed in the future.



28
29
30
# File 'lib/crystalscad/Pipe.rb', line 28

def radians(a)
  a/180.0 * Math::PI
end

#shapeObject



45
46
47
# File 'lib/crystalscad/Pipe.rb', line 45

def shape
	res = circle(d:@diameter,fn:@fn)
end