Module: RGeo::ImplHelper::BasicPointMethods

Included in:
Cartesian::PointImpl, Geographic::ProjectedPointImpl, Geographic::SphericalPointImpl
Defined in:
lib/rgeo/impl_helper/basic_point_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#boundaryObject


70
71
72
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 70

def boundary
  factory.collection([])
end

#convex_hullObject


74
75
76
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 74

def convex_hull
  self
end

#coordinatesObject


100
101
102
103
104
105
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 100

def coordinates
  [x, y].tap do |coords|
    coords << z if factory.property(:has_z_coordinate)
    coords << m if factory.property(:has_m_coordinate)
  end
end

#dimensionObject


40
41
42
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 40

def dimension
  0
end

#empty?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 48

def empty?
  false
end

#envelopeObject


66
67
68
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 66

def envelope
  self
end

#equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 78

def equals?(rhs)
  return false unless rhs.is_a?(self.class) && rhs.factory == factory
  case rhs
  when Feature::Point
    rhs.x == @x && rhs.y == @y
  when Feature::LineString
    rhs.num_points > 0 && rhs.points.all? { |elem| equals?(elem) }
  when Feature::GeometryCollection
    rhs.num_geometries > 0 && rhs.all? { |elem| equals?(elem) }
  else
    false
  end
end

#geometry_typeObject


44
45
46
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 44

def geometry_type
  Feature::Point
end

#hashObject


96
97
98
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 96

def hash
  @hash ||= [factory, geometry_type, @x, @y, @z, @m].hash
end

#initialize(factory, x, y, *extra) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 12

def initialize(factory, x, y, *extra)
  self.factory = factory
  @x = x.to_f
  @y = y.to_f
  @z = factory.property(:has_z_coordinate) ? extra.shift.to_f : nil
  @m = factory.property(:has_m_coordinate) ? extra.shift.to_f : nil
  if extra.size > 0
    raise ArgumentError, "Too many arguments for point initializer"
  end
  validate_geometry
end

#is_empty?Boolean

Returns:

  • (Boolean)

52
53
54
55
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 52

def is_empty?
  warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  empty?
end

#is_simple?Boolean

Returns:

  • (Boolean)

61
62
63
64
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 61

def is_simple?
  warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  simple?
end

#mObject


36
37
38
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 36

def m
  @m
end

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

92
93
94
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 92

def rep_equals?(rhs)
  rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @x == rhs.x && @y == rhs.y && @z == rhs.z && @m == rhs.m
end

#simple?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 57

def simple?
  true
end

#xObject


24
25
26
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 24

def x
  @x
end

#yObject


28
29
30
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 28

def y
  @y
end

#zObject


32
33
34
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 32

def z
  @z
end