aboutsummaryrefslogtreecommitdiff
path: root/pkg/images/tv/tvmark/mkfind.x
blob: 5824422a38903fa73f624a4ae61b7ba4af6d7491 (plain) (blame)
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
include <mach.h>

# MK_FIND -- Procedure to detect the object in a file closest to the
# input cursor position.

int procedure mk_find (cl, xcur, ycur, xlist, ylist, label, id, ltid, tol)

int	cl		# coordinates file descriptor
real	xcur, ycur	# x and y cursor position
real	xlist, ylist	# x and y  list position
char	label[ARB]	# label string
int	id		# sequence number of detected object in list
int	ltid		# current sequence number in the list
real	tol		# tolerance for detection

real	x, y, dist2, ldist2, tol2
int	fscan(), nscan()

begin
	if (cl == NULL)
	    return (0)
	call seek (cl, BOF)
	ltid = 0

	# Initialize
	id = 0
	dist2 = MAX_REAL
	tol2 = tol ** 2

	# Fetch the coordinates.
	while (fscan (cl) != EOF) {
	    call gargr (x)
	    call gargr (y)
	    call gargwrd (label, SZ_LINE)
	    if (nscan () < 2)
		next
	    if (nscan () < 3)
		label[1] = EOS
	    ltid = ltid + 1
	    ldist2 = (x - xcur) ** 2 + (y - ycur) ** 2
	    if (ldist2 > tol2)
		next
	    if (ldist2 > dist2)
		next
	    xlist = x
	    ylist = y
	    dist2 = ldist2
	    id = ltid
	}

	return (id)
end