Class: RGeo::Geographic::SphericalMath::ArcXYZ

Inherits:
Object
  • Object
show all
Defined in:
lib/rgeo/geographic/spherical_math.rb

Overview

Represents a finite arc on the sphere.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start, stop) ⇒ ArcXYZ

Returns a new instance of ArcXYZ.


127
128
129
130
131
# File 'lib/rgeo/geographic/spherical_math.rb', line 127

def initialize(start, stop)
  @s = start
  @e = stop
  @axis = false
end

Instance Attribute Details

#eObject (readonly)

:nodoc:


125
126
127
# File 'lib/rgeo/geographic/spherical_math.rb', line 125

def e
  @e
end

#sObject (readonly)

:nodoc:


125
126
127
# File 'lib/rgeo/geographic/spherical_math.rb', line 125

def s
  @s
end

Instance Method Details

#axisObject


147
148
149
150
# File 'lib/rgeo/geographic/spherical_math.rb', line 147

def axis
  @axis = @s % @e if @axis == false
  @axis
end

#contains_point?(obj) ⇒ Boolean

Returns:

  • (Boolean)

152
153
154
155
156
157
# File 'lib/rgeo/geographic/spherical_math.rb', line 152

def contains_point?(obj)
  my_axis = axis
  s_axis = ArcXYZ.new(@s, obj).axis
  e_axis = ArcXYZ.new(obj, @e).axis
  !s_axis || !e_axis || obj * my_axis == 0 && s_axis * my_axis > 0 && e_axis * my_axis > 0
end

#degenerate?Boolean

Returns:

  • (Boolean)

142
143
144
145
# File 'lib/rgeo/geographic/spherical_math.rb', line 142

def degenerate?
  my_axis = axis
  my_axis.x == 0 && my_axis.y == 0 && my_axis.z == 0
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

137
138
139
# File 'lib/rgeo/geographic/spherical_math.rb', line 137

def eql?(other)
  other.is_a?(ArcXYZ) && @s == other.s && @e == other.e
end

#intersects_arc?(obj) ⇒ Boolean

Returns:

  • (Boolean)

159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/rgeo/geographic/spherical_math.rb', line 159

def intersects_arc?(obj)
  my_axis = axis
  dot1 = my_axis * obj.s
  dot2 = my_axis * obj.e
  if dot1 >= 0.0 && dot2 <= 0.0 || dot1 <= 0.0 && dot2 >= 0.0
    ob_axis = obj.axis
    dot1 = ob_axis * @s
    dot2 = ob_axis * @e
    dot1 >= 0.0 && dot2 <= 0.0 || dot1 <= 0.0 && dot2 >= 0.0
  else
    false
  end
end

#lengthObject


173
174
175
# File 'lib/rgeo/geographic/spherical_math.rb', line 173

def length
  @s.dist_to_point(@e)
end

#to_sObject


133
134
135
# File 'lib/rgeo/geographic/spherical_math.rb', line 133

def to_s
  "#{@s} - #{@e}"
end