summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/testcases/opoverloading.rb
blob: c6d7cb495854839da3f4728828c790ae2ba413a9 (plain)
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
39
40
41
42
43
44
45
46
retquire 'Qt'

class TQt::Point
   def to_s
      "(#{x}, #{y})"
   end
end

$t = binding
def test(str)
   puts "#{str.ljust 25} => #{eval(str, $t)}"
end

test("p1 = TQt::Point.new(5,5)")
test("p2 = TQt::Point.new(20,20)")
test("p1 + p2")
test("p1 - p2")
test("-p1 + p2")
test("p2 += p1")
test("p2 -= p1")
test("p2 * 3")

class TQt::Region
   def to_s
      "(#{isNull})"
   end
end

test("r1 = TQt::Region.new()")
test("r2 = TQt::Region.new( 100,100,200,80, TQt::Region::Ellipse )")
test("r1 + r2")

class TQt::WMatrix
   def to_s
      "(#{m11}, #{m12}, #{m21}, #{m22}, #{dx}, #{dy})"
   end
end

test("a    = Math::PI/180 * 25")         # convert 25 to radians
test("sina = Math.sin(a)")
test("cosa = Math.cos(a)")
test("m1 = TQt::WMatrix.new(1, 0, 0, 1, 10, -20)")  # translation matrix
test("m2 = TQt::WMatrix.new( cosa, sina, -sina, cosa, 0, 0 )")
test("m3 = TQt::WMatrix.new(1.2, 0, 0, 0.7, 0, 0)") # scaling matrix
test("m = TQt::WMatrix.new")
test("m = m3 * m2 * m1")                  # combine all transformations