-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentities.rb
145 lines (119 loc) · 2.44 KB
/
entities.rb
1
2
3
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
104
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
135
136
137
138
139
140
141
142
143
144
145
require 'fundamentals'
class GeometricEntity
def self.class_for_type(value)
case value
when :line
Line
when :arc
Arc
when :circle
Circle
when :text
Text
when :point
Point
end
end
end
class Point < GeometricEntity
def initialize(options)
@at = options[:at]
end
def from
@at
end
def to
@at
end
def center
@at
end
end
class Line < GeometricEntity
def initialize(options)
@from = Vector.new(*options[:from]) || Vector.new(0.0,0.0,0.0)
@to = Vector.new(*options[:to]) || Vector.new(0.0,0.0,0.0)
end
def from
@from
end
def to
@to
end
def inspect
"Line{:from => #{@from.inspect}, :to => #{@to.inspect}}"
end
end
class Arc < GeometricEntity
def initialize(options)
@center = Vector.new(*options[:center]) || Vector.new(0.0,0.0,0.0)
@radius = options[:radius] || 0.0
@from_radians = options[:from_radians]
@to_radians = options[:to_radians]
@from_radians ||= options[:from_degrees]/180.0*Math::PI
@to_radians ||= options[:to_degrees]/180.0*Math::PI
end
def center
@center
end
def radius
@radius
end
def from_radians
@from_radians
end
def to_radians
@to_radians
end
def from
Vector.new(Math::sin(@from_radians)*@[email protected],
Math::cos(@from_radians)*@[email protected],
@center.z)
end
def to
Vector.new(Math::sin(@to_radians)*@[email protected],
Math::cos(@to_radians)*@[email protected],
@center.z)
end
def inspect
"Arc{:center => #{@center.inspect}, :radius => #{@radius}, :from_radians => #{@from_radians}, :to_radians => #{@to_radians}}"
end
end
class Circle < GeometricEntity
def initialize(options)
@center = Vector.new(*options[:center]) || Vector.new(0.0,0.0,0.0)
@radius = options[:radius] || 0.0
end
def center
@center
end
def radius
@radius
end
def from
Vector.new(@center.x-@radius,
@center.y,
@center.z)
end
def to
Vector.new(@center.x-@radius,
@center.y,
@center.z)
end
def inspect
"Circle{:center => #{@center.inspect}, :radius => #{@radius}}"
end
end
class Text < GeometricEntity
def initialize(options)
@position = Vector.new(*options[:position]) || Vector.new(0.0,0.0,0.0)
@string = options[:string]
@linetype = options[:linetype]
end
def from
@position
end
def to
@position
end
end