Module: Position
- Defined in:
- tomes/spells/geometry/position.rb
Overview
A module for calculating the position of one object in relation to another.
Class Method Summary collapse
-
.above(object, spacing: 1) ⇒ Object
Calculates a point above the object (along the Y-axis only), including an optional spacing parameter.
-
.add_coordinates(first_coordinates, second_coordinates) ⇒ Array<Integer, Integer>
Adds one set of coordinates to the other.
-
.below(object, spacing: 1) ⇒ Object
Calculates a point below the object (along the Y-axis only), including an optional spacing parameter.
-
.left_of(object, spacing: 1) ⇒ Object
Calculates a point left of the object (along the X-axis only), including an optional spacing parameter.
-
.right_of(object, spacing: 1) ⇒ Object
Calculates a point right of the object (along the X-axis only), including an optional spacing parameter.
-
.subtract_coordinates(first_coordinates, second_coordinates) ⇒ Array<Integer, Integer>
Subtracts one set of coordinates from the other.
-
.these_collide?(primary_object, secondary_object) ⇒ Boolean
(also: collide?)
Checks if two objects collide.
Class Method Details
.above(object, spacing: 1) ⇒ Object
Calculates a point above the object (along the Y-axis only), including an optional spacing parameter. (This method does not assume the object includes the Apex module.)
59 60 61 |
# File 'tomes/spells/geometry/position.rb', line 59 def above(object, spacing: 1) object.y + object.height + spacing end |
.add_coordinates(first_coordinates, second_coordinates) ⇒ Array<Integer, Integer>
Adds one set of coordinates to the other.
32 33 34 |
# File 'tomes/spells/geometry/position.rb', line 32 def add_coordinates(first_coordinates, second_coordinates) [first_coordinates[0] + second_coordinates[0], first_coordinates[1] + second_coordinates[1]] end |
.below(object, spacing: 1) ⇒ Object
Calculates a point below the object (along the Y-axis only), including an optional spacing parameter. (This method does not assume the object includes the Apex module.)
68 69 70 |
# File 'tomes/spells/geometry/position.rb', line 68 def below(object, spacing: 1) object.y - spacing end |
.left_of(object, spacing: 1) ⇒ Object
Calculates a point left of the object (along the X-axis only), including an optional spacing parameter. (This method does not assume the object includes the Apex module.)
41 42 43 |
# File 'tomes/spells/geometry/position.rb', line 41 def left_of(object, spacing: 1) object.x - spacing end |
.right_of(object, spacing: 1) ⇒ Object
Calculates a point right of the object (along the X-axis only), including an optional spacing parameter. (This method does not assume the object includes the Apex module.)
50 51 52 |
# File 'tomes/spells/geometry/position.rb', line 50 def right_of(object, spacing: 1) object.x + object.width + spacing end |
.subtract_coordinates(first_coordinates, second_coordinates) ⇒ Array<Integer, Integer>
Subtracts one set of coordinates from the other.
24 25 26 |
# File 'tomes/spells/geometry/position.rb', line 24 def subtract_coordinates(first_coordinates, second_coordinates) [first_coordinates[0] - second_coordinates[0], first_coordinates[1] - second_coordinates[1]] end |
.these_collide?(primary_object, secondary_object) ⇒ Boolean Also known as: collide?
Checks if two objects collide.
12 13 14 15 16 17 |
# File 'tomes/spells/geometry/position.rb', line 12 def these_collide?(primary_object, secondary_object) primary_object.top > secondary_object.bottom and primary_object.left < secondary_object.right and primary_object.bottom < secondary_object.top and primary_object.right > secondary_object.left end |