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)

Returns the value of attribute e


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

def e
  @e
end

#sObject (readonly)

Returns the value of attribute s


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

def s
  @s
end

Instance Method Details

#axisObject


150
151
152
153
# File 'lib/rgeo/geographic/spherical_math.rb', line 150

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

#contains_point?(obj) ⇒ Boolean

Returns:

  • (Boolean)

155
156
157
158
159
160
# File 'lib/rgeo/geographic/spherical_math.rb', line 155

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.0 && s_axis * my_axis > 0 && e_axis * my_axis > 0
end

#degenerate?Boolean

Returns:

  • (Boolean)

145
146
147
148
# File 'lib/rgeo/geographic/spherical_math.rb', line 145

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

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

Returns:

  • (Boolean)

140
141
142
# File 'lib/rgeo/geographic/spherical_math.rb', line 140

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

#intersects_arc?(obj) ⇒ Boolean

Returns:

  • (Boolean)

162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/rgeo/geographic/spherical_math.rb', line 162

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


176
177
178
# File 'lib/rgeo/geographic/spherical_math.rb', line 176

def length
  @s.dist_to_point(@e)
end

#to_sObject


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

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