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,
lib/aixm/component/geometry/rhumb_line.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, RhumbLine

Instance Method Summary collapse

Methods included from Association

included

Constructor Details

#initialize(*segments) ⇒ Geometry

Returns a new instance of Geometry.


51
52
53
# File 'lib/aixm/component/geometry.rb', line 51

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

Instance Method Details

#add_segment(segment) ⇒ self


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

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

#airspaceAIXM::Feature::Airspace

Returns airspace the geometry defines.

Returns:


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

belongs_to :airspace

#circle?Boolean

Returns Circle shaped geometry?.

Returns:

  • (Boolean)

    Circle shaped geometry?


78
79
80
81
# File 'lib/aixm/component/geometry.rb', line 78

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


61
62
63
# File 'lib/aixm/component/geometry.rb', line 61

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

#inspectString

Returns:

  • (String)

56
57
58
# File 'lib/aixm/component/geometry.rb', line 56

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

#point?Boolean

Returns Single point geometry?.

Returns:

  • (Boolean)

    Single point geometry?


72
73
74
75
# File 'lib/aixm/component/geometry.rb', line 72

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?


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

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::RhumbLine AIXM::Component::Geometry::Arc, AIXM::Component::Geometry::Circle, AIXM::Component::Geometry::Border>

Returns points, rhumb lines, arcs, borders or circle.


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

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

#to_xmlString

Returns AIXM or OFMX markup.

Returns:

  • (String)

    AIXM or OFMX markup


66
67
68
69
# File 'lib/aixm/component/geometry.rb', line 66

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