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
|
class REFERENCE_POINTS
insert PLATFORM
create {CALIBRATION}
make
feature {}
make is
do
create x_device_points.with_capacity(10)
create y_device_points.with_capacity(10)
create x_display_points.with_capacity(10)
create y_display_points.with_capacity(10)
end
feature {ANY}
add_point(x_device, y_device, x_display, y_display: INTEGER) is
do
x_device_points.add_last(x_device)
y_device_points.add_last(y_device)
x_display_points.add_last(x_display)
y_display_points.add_last(y_display)
ensure
count = old count + 1
end
count: INTEGER is
do
Result := x_device_points.count
end
find_best_pair_for(x, y: INTEGER) is
-- Find the two nearest points for (x, y) in device
-- coordinates, trying as much as possible to get one point
-- on each side.
--
-- Note: The result can be the same point twice
local
d1, d2, d_min, tmp: INTEGER_64
p1, p2: INTEGER
i1, i2: INTEGER
x1, y1, x2, y2: INTEGER
do
from
i1 := x_device_points.upper
d_min := Maximum_integer_64
until
i1 < x_device_points.lower
loop
x1 := x_device_points.item(i1)
d1 := x1 - x
d1 := d1 * d1
y1 := y_device_points.item(i1)
tmp := y1 - y
d1 := d1 + tmp * tmp
if d1 < d_min then
from
i2 := i1 - 1
until
i2 < x_device_points.lower
loop
x2 := x_device_points.item(i2)
y2 := y_device_points.item(i2)
if ((x1 < x) xor (x2 < x)) and then
((y1 < y) xor (y2 < y)) then
d2 := x2 - x
tmp := y2 - y
d2 := d2 * d2 + tmp * tmp + d1
if d2 < d_min then
d_min := d2
p1 := i1
p2 := i2
end
end
i2 := i2 - 1
end
end
i1 := i1 - 1
end
-- *** le cas où on ne peut pas trouver un point de chaque
-- coté n'est pas géré
-- *** a la fin, il faudrait renseigner last_*
end
last_point1_x, last_point1_y: INTEGER
-- Answer point for `find_best_pair_for'
last_point2_x, last_point2_y: INTEGER
-- Answer point for `find_best_pair_for'
feature {}
x_device_points, y_device_points: FAST_ARRAY[INTEGER]
x_display_points, y_display_points: FAST_ARRAY[INTEGER]
invariant
x_display_points.count = count
y_display_points.count = count
x_device_points.count = count
y_device_points.count = count
end
|