Class: Vedeu::Area

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/geometry/area.rb

Overview

Define an area from dimensions or points.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y:, yn:, x:, xn:) ⇒ Vedeu::Area

Returns a new instance of Vedeu::Area.

Parameters:

  • y (Fixnum)
  • yn (Fixnum)
  • x (Fixnum)
  • xn (Fixnum)


53
54
55
56
57
58
# File 'lib/vedeu/geometry/area.rb', line 53

def initialize(y:, yn:, x:, xn:)
  @y  = y
  @yn = yn
  @x  = x
  @xn = xn
end

Instance Attribute Details

#xFixnum (readonly) Also known as: left

Returns the left coordinate of the interface.

Returns:

  • (Fixnum)

    Returns the left coordinate of the interface.



18
19
20
# File 'lib/vedeu/geometry/area.rb', line 18

def x
  @x
end

#xnFixnum (readonly) Also known as: right

Returns the right coordinate of the interface.

Returns:

  • (Fixnum)

    Returns the right coordinate of the interface.



23
24
25
# File 'lib/vedeu/geometry/area.rb', line 23

def xn
  @xn
end

#yFixnum (readonly) Also known as: top

Returns the top coordinate of the interface.

Returns:

  • (Fixnum)

    Returns the top coordinate of the interface.



8
9
10
# File 'lib/vedeu/geometry/area.rb', line 8

def y
  @y
end

#ynFixnum (readonly) Also known as: bottom

Returns the bottom coordinate of the interface.

Returns:

  • (Fixnum)

    Returns the bottom coordinate of the interface.



13
14
15
# File 'lib/vedeu/geometry/area.rb', line 13

def yn
  @yn
end

Class Method Details

.from_dimensions(y_yn:, x_xn:) ⇒ Vedeu::Area

Parameters:

  • y_yn (Array<Fixnum>)
  • x_xn (Array<Fixnum>)

Returns:



29
30
31
# File 'lib/vedeu/geometry/area.rb', line 29

def self.from_dimensions(y_yn:, x_xn:)
  new(y: y_yn.first, yn: y_yn.last, x: x_xn.first, xn: x_xn.last)
end

.from_height_and_width(height:, width:) ⇒ Vedeu::Area

Parameters:

  • height (Fixnum)
  • width (Fixnum)

Returns:



36
37
38
# File 'lib/vedeu/geometry/area.rb', line 36

def self.from_height_and_width(height:, width:)
  new(y: 1, yn: height, x: 1, xn: width)
end

.from_points(y:, yn:, x:, xn:) ⇒ Vedeu::Area

Parameters:

  • y (Fixnum)
  • yn (Fixnum)
  • x (Fixnum)
  • xn (Fixnum)

Returns:



42
43
44
# File 'lib/vedeu/geometry/area.rb', line 42

def self.from_points(y:, yn:, x:, xn:)
  new(y: y, yn: yn, x: x, xn: xn)
end

Instance Method Details

#centreArray<Fixnum>

Returns:

  • (Array<Fixnum>)


71
72
73
# File 'lib/vedeu/geometry/area.rb', line 71

def centre
  [centre_y, centre_x]
end

#centre_xFixnum

Returns:

  • (Fixnum)


81
82
83
# File 'lib/vedeu/geometry/area.rb', line 81

def centre_x
  (width / 2) + x
end

#centre_yFixnum

Returns:

  • (Fixnum)


76
77
78
# File 'lib/vedeu/geometry/area.rb', line 76

def centre_y
  (height / 2) + y
end

#east(offset = 1) ⇒ Fixnum

Returns the column after right by default.

Examples:

`right` / `xn` is 19.

east     # => 20
east(2)  # => 21 (positive goes east)
east(-4) # => 15 (negative goes west)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


121
122
123
# File 'lib/vedeu/geometry/area.rb', line 121

def east(offset = 1)
  xn + offset
end

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

An object is equal when its values are the same.

Parameters:

Returns:

  • (Boolean)


64
65
66
67
# File 'lib/vedeu/geometry/area.rb', line 64

def eql?(other)
  self.class == other.class && y == other.y && yn == other.yn &&
    x == other.x && xn == other.xn
end

#heightFixnum

Returns:

  • (Fixnum)


86
87
88
# File 'lib/vedeu/geometry/area.rb', line 86

def height
  (y..yn).size
end

#north(offset = 1) ⇒ Fixnum

Returns the row above the top by default.

Examples:

`top` / `y` is 4.

north     # => 3
north(2)  # => 2 (positive goes north)
north(-4) # => 8 (negative goes south)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


106
107
108
# File 'lib/vedeu/geometry/area.rb', line 106

def north(offset = 1)
  y - offset
end

#south(offset = 1) ⇒ Fixnum

Returns the row below the bottom by default.

Examples:

`bottom` / `yn` is 12.

south     # => 13
south(2)  # => 14 (positive goes south)
south(-4) # => 8  (negative goes north)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


136
137
138
# File 'lib/vedeu/geometry/area.rb', line 136

def south(offset = 1)
  yn + offset
end

#west(offset = 1) ⇒ Fixnum

Returns the column before left by default.

Examples:

`left` / `x` is 8.

west      # => 7
west(2)   # => 6  (positive goes west)
west(-4)  # => 12 (negative goes east)

Parameters:

  • offset (Fixnum) (defaults to: 1)

Returns:

  • (Fixnum)


151
152
153
# File 'lib/vedeu/geometry/area.rb', line 151

def west(offset = 1)
  x - offset
end

#widthFixnum

Returns:

  • (Fixnum)


91
92
93
# File 'lib/vedeu/geometry/area.rb', line 91

def width
  (x..xn).size
end