File: dbPointTest.rb

package info (click to toggle)
klayout 0.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 292,204 kB
  • sloc: cpp: 2,068,428; ruby: 47,823; xml: 26,924; python: 14,404; sh: 1,812; tcl: 212; perl: 170; makefile: 112; ansic: 42
file content (190 lines) | stat: -rw-r--r-- 5,157 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# encoding: UTF-8

# KLayout Layout Viewer
# Copyright (C) 2006-2025 Matthias Koefferlein
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

if !$:.member?(File::dirname($0))
  $:.push(File::dirname($0))
end

load("test_prologue.rb")

class DBPoint_TestClass < TestBase

  # DPoint basics
  def test_1_DPoint

    a = RBA::DPoint::new( 1, -17 )
    b = RBA::DPoint::new
    c = RBA::DPoint::new( RBA::Point::new( 5, 11 ) )

    assert_equal( a.to_s, "1,-17" )
    assert_equal( RBA::DPoint::from_s(a.to_s).to_s, a.to_s )
    assert_equal( (-a).to_s, "-1,17" )
    assert_equal( b.to_s, "0,0" )
    assert_equal( c.to_s, "5,11" )

    assert_equal( (a + c).to_s, "6,-6" )
    assert_equal( (a * 0.5).to_s, "0.5,-8.5" )
    assert_equal( (a - c).to_s, "-4,-28" )
    assert_equal( a == c, false )
    assert_equal( a == a, true )
    assert_equal( a != c, true )
    assert_equal( a != a, false )

    assert_equal( a.x.to_s, "1.0" )
    assert_equal( a.y.to_s, "-17.0" )

    assert_equal( (a.distance(c) - Math::sqrt(800.0)).abs < 1e-12, true )
    assert_equal( ((a-c).length - Math::sqrt(800.0)).abs < 1e-12, true )

    assert_equal( a.sq_distance(c).to_s, "800.0" )
    assert_equal( (a-c).sq_length.to_s, "800.0" )

    b.x = a.x
    b.y = a.y
    assert_equal( a, b )

  end

  # Transforming DPoint
  def test_2_DPoint

    a = RBA::DPoint::new( 1, -17 )
    b = RBA::DPoint::new

    t = RBA::DTrans::new( RBA::DTrans::R90, RBA::DPoint::new( 5, -2 )) 
    assert_equal( t.trans(a).to_s, "22,-1" )

    m = RBA::DCplxTrans::new( RBA::DTrans::new( RBA::DTrans::R90, RBA::DPoint::new( 5, -2 )), 0.5 ) 
    assert_equal( m.trans(a).to_s, "13.5,-1.5" )

  end

  # Point basics
  def test_1_Point

    a = RBA::Point::new( 1, -17 )
    b = RBA::Point::new
    c = RBA::Point::new( RBA::DPoint::new( 5, 11 ) )

    assert_equal( a.to_s, "1,-17" )
    assert_equal( RBA::Point::from_s(a.to_s).to_s, a.to_s )
    assert_equal( (-a).to_s, "-1,17" )
    assert_equal( b.to_s, "0,0" )
    assert_equal( c.to_s, "5,11" )

    assert_equal( (a + c).to_s, "6,-6" )
    assert_equal( (a * 0.5).to_s, "1,-9" )
    assert_equal( (a - c).to_s, "-4,-28" )
    assert_equal( a == c, false )
    assert_equal( a == a, true )
    assert_equal( a != c, true )
    assert_equal( a != a, false )

    assert_equal( a.x.to_s, "1" )
    assert_equal( a.y.to_s, "-17" )

    assert_equal( (a.distance(c) - Math::sqrt(800.0)).abs < 1e-12, true )

    assert_equal( a.sq_distance(c).to_s, "800.0" )

    b.x = a.x
    b.y = a.y
    assert_equal( a, b )

  end

  # Transforming Point
  def test_2_Point

    a = RBA::Point::new( 1, -17 )
    b = RBA::Point::new

    t = RBA::Trans::new( RBA::Trans::R90, RBA::Point::new( 5, -2 )) 
    assert_equal( t.trans(a).to_s, "22,-1" )

    m = RBA::CplxTrans::new( RBA::Trans::new( RBA::Trans::R90, RBA::Point::new( 5, -2 )), 0.5 ) 
    assert_equal( m.trans(a).to_s, "13.5,-1.5" )

  end

  # Fuzzy compare
  def test_3_Point

    p1 = RBA::DPoint::new(1, 2)
    p2 = RBA::DPoint::new(1 + 1e-7, 2)
    p3 = RBA::DPoint::new(1 + 1e-4, 2)
    assert_equal(p1.to_s, "1,2")
    assert_equal(p2.to_s, "1.0000001,2")
    assert_equal(p3.to_s, "1.0001,2")

    assert_equal(p1 == p2, true)
    assert_equal(p1.eql?(p2), true)
    assert_equal(p1 != p2, false)
    assert_equal(p1 < p2, false)
    assert_equal(p2 < p1, false)
    assert_equal(p1 == p3, false)
    assert_equal(p1.eql?(p3), false)
    assert_equal(p1 != p3, true)
    assert_equal(p1 < p3, true)
    assert_equal(p3 < p1, false)

  end

  # Hash values 
  def test_4_Point

    p1 = RBA::DPoint::new(1, 2)
    p2 = RBA::DPoint::new(1 + 1e-7, 2)
    p3 = RBA::DPoint::new(1 + 1e-4, 2)

    assert_equal(p1.hash == p2.hash, true)
    assert_equal(p1.hash == p3.hash, false)

    h = { p1 => "a", p3 => "b" }
    assert_equal(h[p1], "a")
    assert_equal(h[p2], "a")
    assert_equal(h[p3], "b")

  end

  # move/moved
  def test_5_Point

    p1 = RBA::DPoint::new(1, 2)
    assert_equal(p1.moved(2, 3).to_s, "3,5")
    assert_equal(p1.to_s, "1,2")
    assert_equal(p1.move(2, 3).to_s, "3,5")
    assert_equal(p1.to_s, "3,5")

    p1 = RBA::DPoint::new(1, 2)
    assert_equal(p1.moved(RBA::DVector::new(2, 3)).to_s, "3,5")
    assert_equal(p1.to_s, "1,2")
    assert_equal(p1.move(RBA::DVector::new(2, 3)).to_s, "3,5")
    assert_equal(p1.to_s, "3,5")

    p1 = RBA::DPoint::new(1, 2)
    assert_equal(p1.moved(:dx => 1).to_s, "2,2")
    p1.move(:dy => 3)
    assert_equal(p1.to_s, "1,5")

  end

end

load("test_epilogue.rb")