Class: EagleCAD::Geometry::Polygon

Inherits:
Geometry::Polygon
  • Object
show all
Defined in:
lib/eaglecad/geometry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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)
		options, args = args.partition {|a| a.is_a? Hash}
		options = options.reduce({}, :merge)

		@line_width = options.delete(:line_width)

		super *args
end

Instance Attribute Details

#line_widthObject

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

Parameters:

  • element (Element)

    The REXML::Element to parse



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_xmlREXML::Element

Returns:

  • (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