summaryrefslogtreecommitdiff
path: root/reference_points.e
blob: ff5237f089e81a9ac50a5a68dbb87c5f76b652e4 (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
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
class REFERENCE_POINTS

insert PLATFORM
	
create {CALIBRATION}
	make

feature {}
	default_capacity: INTEGER is 10
	
	make(nb_parameters_: INTEGER) is
		local
			i: INTEGER
			tmp: FAST_ARRAY[INTEGER]
		do
			create x_target_points.with_capacity(default_capacity)
			create y_target_points.with_capacity(default_capacity)
			create x_measure_points.with_capacity(default_capacity)
			create y_measure_points.with_capacity(default_capacity)
			from
				nb_parameters := nb_parameters_
				create parameters.with_capacity(nb_parameters)
				i := 0
			until
				i >= nb_parameters
			loop
				create tmp.with_capacity(default_capacity)
				parameters.add_last(tmp)
				i := i + 1
			end
		ensure
			nb_parameters = nb_parameters_
		end

feature {ANY}
	add_point(a_x_target, a_y_target: INTEGER; a_x_measure, a_y_measure: INTEGER; parameters_values: FAST_ARRAY[INTEGER]) is
		require
			parameters_values.count = nb_parameters
		local
			i: INTEGER
		do
			x_target_points.add_last(a_x_target)
			y_target_points.add_last(a_y_target)
			x_measure_points.add_last(a_x_measure)
			y_measure_points.add_last(a_y_measure)
			from
				i := parameters.lower
			until
				i > parameters.upper
			loop
				parameters.item(i).add_last(parameters_values.item(i))
				i := i + 1
			end
		ensure
			count = old count + 1
		end

	count: INTEGER is
		do
			Result := x_target_points.count
		end

	x_target(point: INTEGER): INTEGER is
		require
			point.in_range(0, count - 1)
		do
			Result := x_target_points.item(point)
		end

	y_target(point: INTEGER): INTEGER is
		require
			point.in_range(0, count - 1)
		do
			Result := y_target_points.item(point)
		end

	x_measure(point: INTEGER): INTEGER is
		require
			point.in_range(0, count - 1)
		do
			Result := x_measure_points.item(point)
		end

	y_measure(point: INTEGER): INTEGER is
		require
			point.in_range(0, count - 1)
		do
			Result := y_measure_points.item(point)
		end

	parameter_value(point, param: INTEGER): INTEGER is
		require
			point.in_range(0, count - 1)
			param.in_range(0, nb_parameters - 1)
		do
			Result := parameters.item(param).item(point)
		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 {}
	nb_parameters: INTEGER
	
	x_target_points, y_target_points: FAST_ARRAY[INTEGER]
			-- in device coordinates

	x_measure_points, y_measure_points: FAST_ARRAY[INTEGER]

	parameters: FAST_ARRAY[FAST_ARRAY[INTEGER]]
	
invariant
	x_target_points.count = count
	y_target_points.count = count
	x_measure_points.count = count
	y_measure_points.count = count

	parameters.count = nb_parameters
	
end