class EagleCAD::Geometry::Polygon

Attributes

line_width[RW]

Public Class Methods

from_xml(element) click to toggle source

Create a {Polygon} from an {REXML::Element} @param [Element] element The {REXML::Element} to parse

# 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
new(*args) click to toggle source
Calls superclass method
# 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

Public Instance Methods

to_xml() click to toggle source

@return [REXML::Element]

# 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