Class: VORuby::STC::V1_10::STC::SphereType

Inherits:
SpatialIntervalType show all
Defined in:
lib/voruby/stc/1.10/stc.rb

Overview

Defines a sphere

Direct Known Subclasses

Sphere, VelocitySphereType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(options = {}) ⇒ SphereType

Returns a new instance of SphereType.



2039
2040
2041
2042
2043
2044
# File 'lib/voruby/stc/1.10/stc.rb', line 2039

def initialize(options={})
  raise_argument_required_error('radius') if !options.has_key?(:radius)
  raise_argument_required_error('center') if !options.has_key?(:center)
  raise_argument_required_error('unit') if !options.has_key?(:unit)
  super(options)
end

Instance Attribute Details

#centerObject

Returns the value of attribute center.



2037
2038
2039
# File 'lib/voruby/stc/1.10/stc.rb', line 2037

def center
  @center
end

#radiusObject

Returns the value of attribute radius.



2037
2038
2039
# File 'lib/voruby/stc/1.10/stc.rb', line 2037

def radius
  @radius
end

#unitObject

Returns the value of attribute unit.



2037
2038
2039
# File 'lib/voruby/stc/1.10/stc.rb', line 2037

def unit
  @unit
end

Class Method Details

.from_xml(xml) ⇒ Object



2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
# File 'lib/voruby/stc/1.10/stc.rb', line 2112

def self.from_xml(xml)
  root = element_from(xml)
  
  options = {
    :radius => Float(REXML::XPath.first(root, 'x:Radius', {'x' => obj_ns.uri}).text),
    :center => Double3.from_xml(REXML::XPath.first(root, 'x:Center', {'x' => obj_ns.uri})),
    :unit => PosUnit.new(root.attributes.get_attribute_ns(obj_ns.uri, 'unit').value)
  }
  
  radius_unit = root.attributes.get_attribute_ns(obj_ns.uri, 'radius_unit')
  options[:radius_unit] = PosUnit.new(radius_unit.value) if radius_unit
  
  fill_factor = root.attributes.get_attribute_ns(obj_ns.uri, 'fill_factor')
  options[:fill_factor] = Float(fill_factor.value) if fill_factor
  
  self.new(options)
end

Instance Method Details

#==(s) ⇒ Object



2085
2086
2087
2088
2089
2090
2091
# File 'lib/voruby/stc/1.10/stc.rb', line 2085

def ==(s)
  self.radius == s.radius and
  self.center == s.center and
  self.unit == s.unit and
  self.radius_unit == s.radius_unit and
  self.fill_factor == s.fill_factor
end

#fill_factorObject



2081
2082
2083
# File 'lib/voruby/stc/1.10/stc.rb', line 2081

def fill_factor
  @fill_factor || 1.0
end

#fill_factor=(f) ⇒ Object



2076
2077
2078
2079
# File 'lib/voruby/stc/1.10/stc.rb', line 2076

def fill_factor=(f)
  f = Float(f) if !f.is_a?(Float)
  @fill_factor = f
end

#radius_unitObject



2072
2073
2074
# File 'lib/voruby/stc/1.10/stc.rb', line 2072

def radius_unit
  @radius_unit || PosUnit.new('deg')
end

#radius_unit=(u) ⇒ Object



2066
2067
2068
2069
2070
# File 'lib/voruby/stc/1.10/stc.rb', line 2066

def radius_unit=(u)
  u = PosUnit.new(u.to_s) if u and !u.is_a?(PosUnit)
  raise_type_mismatch_error(u, PosUnit) if u
  @radius_unit = u
end

#to_xml(name = nil) ⇒ Object



2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
# File 'lib/voruby/stc/1.10/stc.rb', line 2093

def to_xml(name=nil)
  el = element(name)
  
  el.attributes["#{obj_ns.prefix}:unit"] = self.unit.to_s
  el.attributes["#{obj_ns.prefix}:radius_unit"] = self.radius_unit.to_s if self.radius_unit
  el.attributes["#{obj_ns.prefix}:fill_factor"] = self.fill_factor.to_s if self.fill_factor
  
  radius = REXML::Element.new("#{obj_ns.prefix}:Radius")
  radius.text = self.radius.to_s
  el.add_element(radius)
  
  center = REXML::Element.new("#{obj_ns.prefix}:Center")
  center.text = self.center.to_s
  el.add_element(center)
  
  collapse_namespaces(el)
  el
end