-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCStack.rb
38 lines (31 loc) · 783 Bytes
/
CStack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require './MatrixUtils.rb'
require './Matrix.rb'
class CStack
# Wrapper class CStack makes it easy to work with co-ord systems in a stacky way
def initialize()
@data = []
@data.push(MatrixUtils.identity(4))
end
def pop()
@data.pop()
end
# Parser push, not stack push
# Places a copy of the current top on the top
def push()
@data.push(@data[-1].copy())
end
def peek()
@data[-1]
end
def modify_top(transformation)
@data.push(MatrixUtils.multiply(@data.pop(), transformation, modify_second: false))
end
def to_str to_s; end
def to_s
ret = "\nSTACK IS OF LENGTH #{@data.length}\nBOTTOM OF STACK\n"
for i in (0...@data.length)
ret+= "ELEMENT #{i}\n #{@data[i]}"
end
ret += "TOP OF STACK\n"
end
end