Class: EagleCAD::Geometry::Polygon
- Inherits:
-
Geometry::Polygon
- Object
- Geometry::Polygon
- EagleCAD::Geometry::Polygon
- Defined in:
- lib/eaglecad/geometry.rb
Instance Attribute Summary collapse
-
#line_width ⇒ Object
Returns the value of attribute line_width.
Class Method Summary collapse
-
.from_xml(element) ⇒ Object
Create a Polygon from an REXML::Element.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Polygon
constructor
A new instance of Polygon.
- #to_xml ⇒ REXML::Element
Constructor Details
#initialize(*args) ⇒ Polygon
Returns a new instance of Polygon.
114 115 116 117 118 119 120 121 |
# File 'lib/eaglecad/geometry.rb', line 114 def initialize(*args) , args = args.partition {|a| a.is_a? Hash} = .reduce({}, :merge) @line_width = .delete(:line_width) super *args end |
Instance Attribute Details
#line_width ⇒ Object
Returns the value of attribute line_width.
104 105 106 |
# File 'lib/eaglecad/geometry.rb', line 104 def line_width @line_width end |
Class Method Details
.from_xml(element) ⇒ Object
Create a EagleCAD::Geometry::Polygon from an REXML::Element
108 109 110 111 112 |
# File 'lib/eaglecad/geometry.rb', line 108 def self.from_xml(element) width = element.attributes['width'] vertices = element.elements.map {|vertex| Geometry::point_from(vertex, 'x', 'y') } self.new(*vertices, line_width:width) end |
Instance Method Details
#to_xml ⇒ REXML::Element
124 125 126 127 128 129 |
# File 'lib/eaglecad/geometry.rb', line 124 def to_xml REXML::Element.new('polygon').tap do |element| element.add_attribute 'width', line_width vertices.each {|vertex| element.add_element('vertex', {'x' => Geometry.format(vertex.x), 'y' => Geometry.format(vertex.y)}) } end end |