Class: AIXM::Component::Geometry

Inherits:
Object
  • Object
show all
Includes:
Association
Defined in:
lib/aixm/component/geometry.rb,
lib/aixm/component/geometry/arc.rb,
lib/aixm/component/geometry/point.rb,
lib/aixm/component/geometry/border.rb,
lib/aixm/component/geometry/circle.rb

Overview

Geometries define a 3D airspace horizontally.

For a geometry to be valid, it must be comprised of either:

  • exactly one point

  • exactly one circle

  • at least three points, arcs or borders (the last of which a point with identical coordinates as the first)

Cheat Sheet in Pseudo Code:

geometry = AIXM.geometry
geometry.add_segment(AIXM.point or AIXM.arc or AIXM.border or AIXM.circle)

Examples:

Built by passing elements to the initializer

geometry = AIXM.geometry(
  AIXM.point(...),
  AIXM.point(...)
)

Built by adding segments

geometry = AIXM.geometry
geometry.add_segment(AIXM.point(...))

See Also:

Defined Under Namespace

Classes: Arc, Border, Circle, Point

Instance Method Summary collapse

Methods included from Association

included

Constructor Details

#initialize(*segments) ⇒ Geometry

Returns a new instance of Geometry.


49
50
51
# File 'lib/aixm/component/geometry.rb', line 49

def initialize(*segments)
  segments.each { add_segment(_1) }
end

Instance Method Details

#add_segment(segment) ⇒ self


43
# File 'lib/aixm/component/geometry.rb', line 43

has_many :segments, accept: %i(point arc border circle)

#airspaceAIXM::Feature::Airspace

Returns airspace the geometry defines.

Returns:


47
# File 'lib/aixm/component/geometry.rb', line 47

belongs_to :airspace

#circle?Boolean

Returns Circle shaped geometry?.

Returns:

  • (Boolean)

    Circle shaped geometry?


76
77
78
79
# File 'lib/aixm/component/geometry.rb', line 76

def circle?
  segments.size == 1 &&
    segments.first.is_a?(AIXM::Component::Geometry::Circle)
end

#closed?Boolean

Returns whether the geometry is closed.

Returns:

  • (Boolean)

    whether the geometry is closed


59
60
61
# File 'lib/aixm/component/geometry.rb', line 59

def closed?
  point? || circle? || polygon?
end

#inspectString

Returns:

  • (String)

54
55
56
# File 'lib/aixm/component/geometry.rb', line 54

def inspect
  %Q(#<#{self.class} segments=#{segments.count.inspect}>)
end

#point?Boolean

Returns Single point geometry?.

Returns:

  • (Boolean)

    Single point geometry?


70
71
72
73
# File 'lib/aixm/component/geometry.rb', line 70

def point?
  segments.size == 1 &&
    segments.first.is_a?(AIXM::Component::Geometry::Point)
end

#polygon?Boolean

Returns Polygon shaped geometry?.

Returns:

  • (Boolean)

    Polygon shaped geometry?


82
83
84
85
86
87
# File 'lib/aixm/component/geometry.rb', line 82

def polygon?
  segments.size >= 3 &&
    !segments.any? { _1.is_a?(AIXM::Component::Geometry::Circle) } &&
    segments.last.is_a?(AIXM::Component::Geometry::Point) &&
    segments.first.xy == segments.last.xy
end

#segmentsArray<AIXM::Component::Geometry::Point, AIXM::Component::Geometry::Arc, AIXM::Component::Geometry::Border, AIXM::Component::Geometry::Circle>

Returns points, arcs, borders or circle.


43
# File 'lib/aixm/component/geometry.rb', line 43

has_many :segments, accept: %i(point arc border circle)

#to_xmlString

Returns AIXM or OFMX markup.

Returns:

  • (String)

    AIXM or OFMX markup


64
65
66
67
# File 'lib/aixm/component/geometry.rb', line 64

def to_xml
  fail(GeometryError.new("geometry is not closed", self)) unless closed?
  segments.map { _1.to_xml }.join
end