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



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

def boundary
  factory.collection([])
end

#convex_hullObject



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

def convex_hull
  self
end

#coordinatesObject



88
89
90
91
92
93
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 88

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



38
39
40
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 38

def dimension
  0
end

#empty?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 46

def empty?
  false
end

#envelopeObject



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

def envelope
  self
end

#equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 66

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



42
43
44
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 42

def geometry_type
  Feature::Point
end

#hashObject



84
85
86
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 84

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

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

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
# 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
  raise ArgumentError, "Too many arguments for point initializer" unless extra.empty?
  init_geometry
end

#mObject



34
35
36
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 34

def m
  @m
end

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 80

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)


50
51
52
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 50

def simple?
  true
end

#xObject



22
23
24
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 22

def x
  @x
end

#yObject



26
27
28
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 26

def y
  @y
end

#zObject



30
31
32
# File 'lib/rgeo/impl_helper/basic_point_methods.rb', line 30

def z
  @z
end