Class: JennCad::RoundCorner

Inherits:
Object
  • Object
show all
Defined in:
lib/jenncad/features/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ RoundCorner

Returns a new instance of RoundCorner.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jenncad/features/path.rb', line 4

def initialize(args)
  @start_point = args[:start_point]
  @end_point = args[:end_point]
  @a = args[:a]
  @ccw = args[:ccw] || false
  @l = args[:l]
  @od = args[:od]
  @id = args[:id]
  @input_a = args[:input_a] || 0
  @output_a = args[:output_a] || 0
  thing = Marshal.load(args[:thing])

  @thing_dia = thing.d || thing.y
  unless @thing_dia
    $log.error "ERROR: cannot find diameter or y of thing #{thing.inspect}"
    return
  end
  @angle = args[:angle]
  @current_angle = args[:current_angle]
  @direction = args[:direction]
  @to = args[:to]
  @from = args[:from]

  if @a < 0
    @from = case @from
      when :left
        :right
      when :right
        :left
      when :top, :up
        :bottom
      when :down, :bottom
        :up
      else
        # // unimplemented
        @from
    end
  end

end

Instance Attribute Details

#aObject

Returns the value of attribute a.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def a
  @a
end

#angleObject

Returns the value of attribute angle.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def angle
  @angle
end

#ccwObject

Returns the value of attribute ccw.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def ccw
  @ccw
end

#current_angleObject

Returns the value of attribute current_angle.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def current_angle
  @current_angle
end

#directionObject

Returns the value of attribute direction.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def direction
  @direction
end

#end_pointObject

Returns the value of attribute end_point.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def end_point
  @end_point
end

#fromObject

Returns the value of attribute from.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def from
  @from
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def id
  @id
end

#input_aObject

Returns the value of attribute input_a.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def input_a
  @input_a
end

#lObject

Returns the value of attribute l.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def l
  @l
end

#odObject

Returns the value of attribute od.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def od
  @od
end

#output_aObject

Returns the value of attribute output_a.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def output_a
  @output_a
end

#start_pointObject

Returns the value of attribute start_point.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def start_point
  @start_point
end

#thingObject

Returns the value of attribute thing.



3
4
5
# File 'lib/jenncad/features/path.rb', line 3

def thing
  @thing
end

Instance Method Details

#marginObject



61
62
63
# File 'lib/jenncad/features/path.rb', line 61

def margin
  return @od
end

#normalize(angle) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/jenncad/features/path.rb', line 51

def normalize(angle)
  if angle < 0
    angle += 360
  end
  if angle >= 360
    angle -= 360
  end
  angle
end

#partObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/jenncad/features/path.rb', line 105

def part
  d = @thing_dia
  len = d * 2 + @id
  x = Math::sin((@a/180.0)*Math::PI)*len
  y = Math::cos((@a/180.0)*Math::PI)*len

  res  = circle(d: len)
  res -= circle(d: @id)
  points = [[0,0]]
  points << [0, len]
  points << [x, y]

  res *= polygon(points:points)

  r, ox, oy, x, y = positions
  res = res.rotate(z: r).move(x: ox, y: oy)
  res = res.auto_extrude#.color("red")

  #res += slot(d: 1.2, y: len/2.0, h: 10).rotate(z: r_midpoint).color("red")
  #res += cylinder(d: 1, h: 10).move(x: x+ox,y: y+oy)

  #res.moveh(x: thing.yield.d, y: -thing.yield.d)
  res.move(x: @start_point[:x], y: @start_point[:y])

  #res += cylinder(d: 1, h: 15).color("red").move(x: @start_point[:x], y: @start_point[:y]).move(z:-1)


  res

end

#positionsObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/jenncad/features/path.rb', line 65

def positions
  td = @thing_dia
  l = td + @id
  l2 = td / 2.0 + @id / 2.0
  r = 0
  ox = 0
  oy = 0
  cr = 180
  case @from
    when :left
      r = 0
      oy = -l
    when :top, :up
      r = -90
      ox = -l
      cr = 0
    when :right
      r = 180
      oy = l
    when :bottom, :down
      cr = 0
      r = 90
      ox = l
    # TODO: so this doesn't work yet,
    #       need to figure out the maths to translate this
    when 0..360
      r = 180-@from
      cr = @a
  end

  r2 = cr + r + @a   # 180+@a
  x = - l2 * Math::sin((r2/180.0)*Math::PI)
  y = - l2 * Math::cos((r2/180.0)*Math::PI)



  return r, ox/2.0, oy/2.0, x, y

end

#set_angles(cur, total, direction) ⇒ Object



45
46
47
48
49
# File 'lib/jenncad/features/path.rb', line 45

def set_angles(cur, total, direction)
  @current_angle = cur
  @angle = normalize(total)
  @direction = direction
end