Class: AIXM::Component::Geometry

Inherits:
AIXM::Component show all
Includes:
AIXM::Concerns::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 Attribute Summary

Attributes inherited from AIXM::Component

#meta

Instance Method Summary collapse

Methods included from AIXM::Concerns::Association

included

Methods included from AIXM::Concerns::HashEquality

#eql?, #hash

Methods included from AIXM::Concerns::XMLBuilder

#build_fragment, #to_uid, #to_xml

Methods included from AIXM::Concerns::Memoize

included, method

Constructor Details

#initialize(*segments) ⇒ Geometry

See the cheat sheet for examples on how to create instances of this class.



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

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

Instance Method Details

#add_segment(segment) ⇒ self



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

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

#airspaceAIXM::Feature::Airspace

Returns airspace the geometry defines.

Returns:



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

belongs_to :airspace

#circle?Boolean

Whether a circle shaped geometry

Returns:

  • (Boolean)


81
82
83
84
# File 'lib/aixm/component/geometry.rb', line 81

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

#closed?Boolean

Whether the geometry is closed

Returns:

  • (Boolean)


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

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

#inspectString

Returns:

  • (String)


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

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

#point?Boolean

Whether a single point geometry

Returns:

  • (Boolean)


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

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

#polygon?Boolean

Whether a polygon shaped geometry

Returns:

  • (Boolean)


89
90
91
92
93
94
# File 'lib/aixm/component/geometry.rb', line 89

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.



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

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