summaryrefslogtreecommitdiff
path: root/reference_points.e
diff options
context:
space:
mode:
authorguez2008-04-08 13:43:01 +0000
committerguez2008-04-08 13:43:01 +0000
commit8f1e0435cca1d97caba2da1e306432ace45d0bbd (patch)
tree55a65c1ccd8c1f8401f6bb204b656f451fcf97e8 /reference_points.e
downloadxinput-ivy-8f1e0435cca1d97caba2da1e306432ace45d0bbd.zip
xinput-ivy-8f1e0435cca1d97caba2da1e306432ace45d0bbd.tar.gz
xinput-ivy-8f1e0435cca1d97caba2da1e306432ace45d0bbd.tar.bz2
xinput-ivy-8f1e0435cca1d97caba2da1e306432ace45d0bbd.tar.xz
Version 1.1 de xinput-ivy, auteur Philippe Ribet
Diffstat (limited to 'reference_points.e')
-rw-r--r--reference_points.e103
1 files changed, 103 insertions, 0 deletions
diff --git a/reference_points.e b/reference_points.e
new file mode 100644
index 0000000..8059108
--- /dev/null
+++ b/reference_points.e
@@ -0,0 +1,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