aboutsummaryrefslogtreecommitdiff
path: root/sys/qpoe/qpexsub.gx
blob: 1fc51821bf925d050f7f1b82bc4eaabba10f6d04 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<mach.h>
include	"../qpex.h"

# QPEX_SUBLIST -- Extract a sublist spanning the indicated range from a
# larger range list.  The number of ranges extracted is returned as the
# function value.

int procedure qpex_sublist$t (x1, x2, xs,xe,nranges,ip, o_xs,o_xe)

PIXEL	x1, x2				#I range to be extracted
PIXEL	xs[nranges],xe[nranges]		#I input range list
int	nranges				#I nranges in input list
int	ip				#U start position in input list
PIXEL	o_xs[ARB],o_xe[ARB]		#O output sublist

PIXEL	tol
int	op, i

begin
	$if (datatype == i)
	    tol = 0
	$else
	    tol = (EPSILON$T * 10$f)
	$endif

	# Determine the range containing or immediately following the
	# start point of the range of interest.

	while (x1 < xs[ip] && ip > 1)
	    ip = ip - 1
	while (x1 >= xs[ip])
	    if (x1 <= xe[ip] || ip >= nranges)
		break
	    else
		ip = ip + 1

	# Check for an empty output range list.
	if (xs[ip] > x2)
	    return (0)

	# At least one input range contributes something to the output region.
	# Copy a portion of the input range list to the ouput range list.

	op = 1
	do i = ip, nranges {
	    if (xs[i] <= x1)
		o_xs[op] = LEFT$T - tol
	    else
		o_xs[op] = xs[i]

	    if ((xe[i] - x2) >= tol) {
		o_xe[op] = RIGHT$T + tol
		op = op + 1
		break
	    } else
		o_xe[op] = xe[i]

	    op = op + 1
	    if (xs[i+1] > x2)
		break
	}

	ip = i
	return (op - 1)
end