Class: DxfIO::Entity::Other
- Inherits:
-
Object
- Object
- DxfIO::Entity::Other
show all
- Defined in:
- lib/dxf_io/entity/other.rb
Direct Known Subclasses
Arc, Circle, Dimension, Ellipse, Hatch, Leader, Line, Mline, Mtext, Polyline, Spline, Text
Constant Summary
collapse
- START_POINT_GROUP_NUMS =
start point:
x coordinate - 10
y coordinate - 20
end point:
x coordinate - 11
y coordinate - 21
DxfIO::Constants::START_POINT_GROUP_NUMS
- END_POINT_GROUP_NUMS =
DxfIO::Constants::END_POINT_GROUP_NUMS
- X_COORDINATE_GROUP_NUMS =
[10, 11].freeze
- Y_COORDINATE_GROUP_NUMS =
[20, 21].freeze
- Z_COORDINATE_GROUP_NUMS =
[30, 31].freeze
- TYPE_NAME_VALUE_MAPPING =
DxfIO::Constants::ENTITIES_TYPE_NAME_VALUE_MAPPING
- GROUP_CODES =
{type: 0}.freeze
Instance Method Summary
collapse
Constructor Details
#initialize(groups) ⇒ Other
Returns a new instance of Other.
21
22
23
24
25
26
27
|
# File 'lib/dxf_io/entity/other.rb', line 21
def initialize(groups)
if groups.is_a? Array
@groups = groups
else
raise ArgumentError, 'groups must be an Array'
end
end
|
Instance Method Details
#-(point) ⇒ Object
166
167
168
169
170
171
172
|
# File 'lib/dxf_io/entity/other.rb', line 166
def -(point)
if point.is_a? DxfIO::Entity::Support::Point
self + (-point)
else
raise ArgumentError, 'argument must be a DxfIO::Entity::Support::Point'
end
end
|
#bordering_points ⇒ Object
88
89
90
|
# File 'lib/dxf_io/entity/other.rb', line 88
def bordering_points
points
end
|
#bordering_xs ⇒ Object
114
115
116
|
# File 'lib/dxf_io/entity/other.rb', line 114
def bordering_xs
bordering_points.collect(&:x)
end
|
#bordering_ys ⇒ Object
118
119
120
|
# File 'lib/dxf_io/entity/other.rb', line 118
def bordering_ys
bordering_points.collect(&:y)
end
|
#frame? ⇒ Boolean
is entity a rectangle figure without rotation
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/dxf_io/entity/other.rb', line 125
def frame?
if points.count < 4
false
else
((points[0].x == points[3].x) && (points[1].x == points[2].x) &&
(points[0].y == points[1].y) && (points[2].y == points[3].y)) ||
((points[0].y == points[3].y) && (points[1].y == points[2].y) &&
(points[0].x == points[1].x) && (points[2].x == points[3].x))
end
end
|
#height ⇒ Object
96
97
98
|
# File 'lib/dxf_io/entity/other.rb', line 96
def height
(bordering_ys.max - bordering_ys.min).abs
end
|
#left_down_point ⇒ Object
92
93
94
|
# File 'lib/dxf_io/entity/other.rb', line 92
def left_down_point
DxfIO::Entity::Support::Point.new(bordering_xs.min, bordering_ys.min)
end
|
#move_to!(point) ⇒ Object
Also known as:
+
clear alternative for “+” method move all points of Entity on specified vector
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/dxf_io/entity/other.rb', line 145
def move_to!(point)
if point.is_a? DxfIO::Entity::Support::Point
@groups.each do |group|
if x_coordinate?(group)
group[group.keys.first] = group.values.first + point.x
elsif y_coordinate?(group)
group[group.keys.first] = group.values.first + point.y
end
end
else
raise ArgumentError, 'argument must be a DxfIO::Entity::Support::Point'
end
end
|
#points ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/dxf_io/entity/other.rb', line 71
def points
groups = validate_point_groups(point_groups)
groups[1..-1].each.with_index.inject([]) do |result, (group, index)|
if (index % 2) == 0
type = start_point?(group) ? :start : :end
result << DxfIO::Entity::Support::Point.new(groups[index].values.first,
group.values.first,
type: type)
else
result
end
end
end
|
#to_a ⇒ Object
47
48
49
|
# File 'lib/dxf_io/entity/other.rb', line 47
def to_a
@groups
end
|
#to_h ⇒ Object
Also known as:
to_hash
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/dxf_io/entity/other.rb', line 29
def to_h
@representation_hash ||=
@groups.inject({}) do |h, group|
group_value = group.values.first
group_values = h[group.keys.first]
if group_values.nil?
h[group.keys.first] = group_value
elsif group_values.is_a? Array
h[group.keys.first] << group_value
else
h[group.keys.first] = [group_values, group_value]
end
h
end
end
|
#width ⇒ Object
100
101
102
|
# File 'lib/dxf_io/entity/other.rb', line 100
def width
(bordering_xs.max - bordering_xs.min).abs
end
|
#xs ⇒ Object
106
107
108
|
# File 'lib/dxf_io/entity/other.rb', line 106
def xs
points.collect(&:x)
end
|
#ys ⇒ Object
110
111
112
|
# File 'lib/dxf_io/entity/other.rb', line 110
def ys
points.collect(&:y)
end
|