Class: Location

Inherits:
Object
  • Object
show all
Defined in:
lib/locationclass.rb

Overview

Represents a 2D location in space. Note that there is an attr_accessor for @x and @y.

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Location

Sets the x and y to the given values.



7
8
9
10
# File 'lib/locationclass.rb', line 7

def initialize(x, y)
	@x = x
	@y = y
end

Instance Method Details

#[](k) ⇒ Object



45
46
47
48
49
# File 'lib/locationclass.rb', line 45

def [](k)
	return nil unless (k == 0 or k == 1)
	return self.x() if (k == 0)
	return self.y()
end

#[]=(k, v) ⇒ Object



50
51
52
53
54
# File 'lib/locationclass.rb', line 50

def []=(k, v)
	return nil unless (k == 0 or k == 1)
	self.x = v if (k == 0)
	self.y = v
end

#highest_value_x?Boolean

Returns true if @x > @y.

Returns:

  • (Boolean)


29
30
31
# File 'lib/locationclass.rb', line 29

def highest_value_x?()
	return @x > @y
end

#highest_value_y?Boolean

Returns true if @y > @x.

Returns:

  • (Boolean)


33
34
35
# File 'lib/locationclass.rb', line 33

def highest_value_y?()
	return @y > @x
end

#lowest_value_x?Boolean

Returns true unless @x > @y.

Returns:

  • (Boolean)


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

def lowest_value_x?()
	return !highest_value_x?()
end

#lowest_value_y?Boolean

Returns true unless @y > @x.

Returns:

  • (Boolean)


41
42
43
# File 'lib/locationclass.rb', line 41

def lowest_value_y?()
	return !highest_value_y?()
end

#move(x, y) ⇒ Object

Increases the x and y by the given amounts.



13
14
15
16
# File 'lib/locationclass.rb', line 13

def move(x, y)
	@x += x
	@y += y
end

#moveNeg(x, y) ⇒ Object

Decreases the x and y by the given amounts.



18
19
20
21
# File 'lib/locationclass.rb', line 18

def moveNeg(x, y)
	@x -= x
	@y -= y
end

#moveTo(x, y) ⇒ Object

Moves the location to the specified values.



23
24
25
26
# File 'lib/locationclass.rb', line 23

def moveTo(x, y)
	@x = x
	@y = y
end