Class: GeoHex::Polygon

Inherits:
Struct
  • Object
show all
Defined in:
lib/geo_hex/polygon.rb

Constant Summary collapse

H_K =
Math.tan(Math::PI / 180.0 * 60)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eastingObject

Returns the value of attribute easting

Returns:

  • (Object)

    the current value of easting



3
4
5
# File 'lib/geo_hex/polygon.rb', line 3

def easting
  @easting
end

#northingObject

Returns the value of attribute northing

Returns:

  • (Object)

    the current value of northing



3
4
5
# File 'lib/geo_hex/polygon.rb', line 3

def northing
  @northing
end

#sizeObject

Returns the value of attribute size

Returns:

  • (Object)

    the current value of size



3
4
5
# File 'lib/geo_hex/polygon.rb', line 3

def size
  @size
end

Instance Method Details

#centroidGeoHex::PP Also known as: c

Returns The Centroid of the Polygon.

Returns:



7
8
9
# File 'lib/geo_hex/polygon.rb', line 7

def centroid
  @centroid ||= PP.new(easting, northing)
end

#eastGeoHex::PP Also known as: e

Returns The East point of the Polygon.

Returns:



19
20
21
# File 'lib/geo_hex/polygon.rb', line 19

def east
  @east ||= PP.new(easting + 2 * size, northing)
end

#northGeoHex::PP Also known as: n

Returns Point in the middle of the northern polygon boundary.

Returns:

  • (GeoHex::PP)

    Point in the middle of the northern polygon boundary



49
50
51
# File 'lib/geo_hex/polygon.rb', line 49

def north
  @north ||= PP.new(easting, north_bound)
end

#north_eastGeoHex::PP Also known as: ne

Returns The Northeast point of the Polygon.

Returns:

  • (GeoHex::PP)

    The Northeast point of the Polygon



13
14
15
# File 'lib/geo_hex/polygon.rb', line 13

def north_east
  @north_east ||= PP.new(east_bound, north_bound)
end

#north_westGeoHex::PP Also known as: nw

Returns The Northwest point of the Polygon.

Returns:

  • (GeoHex::PP)

    The Northwest point of the Polygon



43
44
45
# File 'lib/geo_hex/polygon.rb', line 43

def north_west
  @north_west ||= PP.new(west_bound, north_bound)
end

#pointsArray<GeoHex::PP> Also known as: to_a

Returns All the points of the Polygon, ordered from Northeast round to Northwest.

Returns:

  • (Array<GeoHex::PP>)

    All the points of the Polygon, ordered from Northeast round to Northwest



61
62
63
# File 'lib/geo_hex/polygon.rb', line 61

def points
  @points ||= [ne, e, se, sw, w, nw]
end

#southGeoHex::PP Also known as: s

Returns Point in the middle of the southern polygon boundary.

Returns:

  • (GeoHex::PP)

    Point in the middle of the southern polygon boundary



55
56
57
# File 'lib/geo_hex/polygon.rb', line 55

def south
  @south ||= PP.new(easting, south_bound)
end

#south_eastGeoHex::PP Also known as: se

Returns The Southeast point of the Polygon.

Returns:

  • (GeoHex::PP)

    The Southeast point of the Polygon



25
26
27
# File 'lib/geo_hex/polygon.rb', line 25

def south_east
  @south_east ||= PP.new(east_bound, south_bound)
end

#south_westGeoHex::PP Also known as: sw

Returns The Southwest point of the Polygon.

Returns:

  • (GeoHex::PP)

    The Southwest point of the Polygon



31
32
33
# File 'lib/geo_hex/polygon.rb', line 31

def south_west
  @south_west ||= PP.new(west_bound, south_bound)
end

#westGeoHex::PP Also known as: w

Returns The West point of the Polygon.

Returns:



37
38
39
# File 'lib/geo_hex/polygon.rb', line 37

def west
  @west ||= PP.new(easting - 2 * size, northing)
end