aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/gtedit/gtdelete.x
blob: c09f6a96918ecd5746d77ae83322be5e2108c918 (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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
include <mach.h>
include	<gset.h>
include	<gio.h>

define	MSIZE 2.0

# GT_DELPT -- Mark a point as deleted

procedure gt_delpt (gd, wx, wy, x, y, npix, deleted, undelete)

pointer	gd				# Graphics descriptor
real	wx				# Cursor position
real	wy				#   ""
real	x[ARB]				# Plotted data
real	y[ARB]				# Plotted data
int	npix				# # of pixels
int	deleted[ARB]			# Array of delete indicators
int	undelete			# Undelete flag

int	row, i
real	r2min, r2, x0, y0

begin
	# Search for the nearest point which has not been deleted

	row = 0
	r2min = MAX_REAL

	# Transform  world cursor coordintes to NDC
	call gctran (gd, wx, wy, wx, wy, 1, 0)
	do i = 1 , npix {
	    if ((deleted[i] == YES && undelete == NO) ||
		(deleted[i] == NO && undelete == YES))
		next
	    
	    call gctran (gd, x[i], y[i], x0, y0, 1, 0)
	    if (x[i] < INDEFR && y[i] < INDEFR)
	        r2 = (wx - x0) ** 2 + (wy - y0) ** 2
	    else
		r2 = MAX_REAL

	    if (r2 < r2min) {
		r2min = r2
		row = i
	    }
	}

	if (row != 0) {
	    # Mark row as being deleted
	    if (undelete == NO) {
	        # Plot X over point
	        call gscur (gd, x[row], y[row])
		call gseti (gd, G_PMLTYPE, GL_SOLID)
	        call gmark (gd, x[row], y[row], GM_CROSS, MSIZE, MSIZE)
	        deleted[row] = YES
	    } else {
		deleted[row] = NO
	        call gscur (gd, x[row], y[row])
		call gseti (gd, G_PMLTYPE, GL_CLEAR)
	        call gmark (gd, x[row], y[row], GM_CROSS, MSIZE, MSIZE)
	    }

	}

end

# GT_DYGT -- Delete all point > input Y

procedure gt_dygt (gd, wy, x, y, npix, deleted, undelete)

pointer	gd				# Graphics descriptor
real	wy				# Cursor position
real	x[ARB]				# Plotted data
real	y[ARB]				# Plotted data
int	npix				# # of pixels
int	deleted[ARB]			# Array of delete indicators
int	undelete

int	i

begin
	# Search for points with Y values > than the critical value

	do i = 1 , npix {
	    if ((deleted[i] == YES && undelete == NO) ||
		(deleted[i] == NO && undelete == YES))
		next
	    
	    if (y[i] > wy) {
		if (undelete == NO) {
	            # Plot X over point
		    call gseti (gd, G_PMLTYPE, GL_SOLID)
	            call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		    deleted[i] = YES
		} else {
		    deleted[i] = NO
		    call gseti (gd, G_PMLTYPE, GL_CLEAR)
	            call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		}
	    }
	}
end

# GT_DYLT -- Delete all point < input Y

procedure gt_dylt (gd, wy, x, y, npix, deleted, undelete)

pointer	gd				# Graphics descriptor
real	wy				# Cursor position
real	x[ARB]				# Plotted data
real	y[ARB]				# Plotted data
int	npix				# # of pixels
int	deleted[ARB]			# Array of delete indicators
int	undelete

int	i

begin
	# Search for points with Y values > than the critical value

	do i = 1 , npix {
	    if ((deleted[i] == YES && undelete == NO) ||
		(deleted[i] == NO && undelete == YES))
		next
	    
	    if (y[i] < wy) {
		if (undelete == NO) {
		    deleted[i] = YES
	            # Plot X over point
		    call gseti (gd, G_PMLTYPE, GL_SOLID)
	            call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		} else {
		    deleted[i] = NO
		    call gseti (gd, G_PMLTYPE, GL_CLEAR)
	            call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		}
	    }
	}
end

# GT_DXGT -- Delete all point > input X

procedure gt_dxgt (gd, wx, x, y, npix, deleted, undelete)

pointer	gd				# Graphics descriptor
real	wx				# Cursor position
real	x[ARB]				# Plotted data
real	y[ARB]				# Plotted data
int	npix				# # of pixels
int	deleted[ARB]			# Array of delete indicators
int	undelete

int	i

begin
	# Search for points with X values > than the critical value

	do i = 1 , npix {
	    if ((deleted[i] == YES && undelete == NO) ||
		(deleted[i] == NO && undelete == YES))
		next
	    
	    if (x[i] > wx) {
		if (undelete == NO) {
		    deleted[i] = YES
	            # Plot X over point
		    call gseti (gd, G_PMLTYPE, GL_SOLID)
	            call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		} else {
		    deleted[i] = NO
		    call gseti (gd, G_PMLTYPE, GL_CLEAR)
	            call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		}
	    }
	}
end

# GT_DXLT -- Delete all point > input Y

procedure gt_dxlt (gd, wx, x, y, npix, deleted, undelete)

pointer	gd				# Graphics descriptor
real	wx				# Cursor position
real	x[ARB]				# Plotted data
real	y[ARB]				# Plotted data
int	npix				# # of pixels
int	deleted[ARB]			# Array of delete indicators
int	undelete

int	i

begin
    # Search for points with X values < than the critical value

	do i = 1 , npix {
	    if ((deleted[i] == YES && undelete == NO) ||
		(deleted[i] == NO && undelete == YES))
		next
	    
	    if (x[i] < wx) {
		if (undelete == NO) {
		    deleted[i] = YES
	            # Plot X over point
		    call gseti (gd, G_PMLTYPE, GL_SOLID)
	            call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		} else {
		    deleted[i] = NO
		    call gseti (gd, G_PMLTYPE, GL_CLEAR)
	            call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		}
	    }
	}
end

# GT_DBOX -- Delete all point in a box

procedure gt_dbox (gd, npix, deleted, undelete, x, y, x1, y1, x2, y2)

pointer	gd				# Graphics descriptor
int	npix				# # of pixels
int	deleted[ARB]			# Array of delete indicators
int	undelete
real	x[ARB]				# Plotted data
real	y[ARB]				# Plotted data
real	x1, y1, x2, y2			# Corners of the box

int	i
real	temp

begin
        # Make sure the points are in  the correct order
        if (y2 < y1) {
	    temp = y1
	    y1 = y2
	    y2 = temp
	}
        if (x2 < x1) {
	    temp = x1
	    x1 = x2
	    x2 = temp
	}
        # Search for points within the box
	do i = 1 , npix {
	    if ((deleted[i] == YES && undelete == NO) ||
		(deleted[i] == NO && undelete == YES))
		next
	    
	    if (x[i] <= x2 && x[i] >= x1) {
		if (y[i] <= y2 && y[i] >= y1) {
		    if (undelete == NO) {
		        deleted[i] = YES
	                # Plot X over point
			call gseti (gd, G_PMLTYPE, GL_SOLID)
	                call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		    } else {
			deleted[i] = NO
		        call gseti (gd, G_PMLTYPE, GL_CLEAR)
	                call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		    }
		}
	    }
	}
end

# GT_DSEG -- Delete all point on one side of a line segment

procedure gt_dseg (gd, npix, deleted, undelete, x, y, x1, y1, x2, y2, x0, y0)

pointer	gd				# Graphics descriptor
int	npix				# # of pixels
int	deleted[ARB]			# Array of delete indicators
int	undelete
real	x[ARB]				# Plotted data
real	y[ARB]				# Plotted data
real	x1, y1, x2, y2			# Corners of the box
real	x0, y0, slope, inter, temp

int	i, lessthan

begin
        # Make sure the points are in  the correct order
        if (y2 < y1) {
	    temp = y1
	    y1 = y2
	    y2 = temp
	}
        if (x2 < x1) {
	    temp = x1
	    x1 = x2
	    x2 = temp
	}

	# Calculate slope and intercept
	slope = (y2 - y1) / (x2 - x1)
	inter = (x2 * y1 - x1 * y2) / (x2 - x1)

	# Which side should we delete the lines from?
	temp = x0 * slope + inter
	if (temp <= y0)
	    lessthan = NO
	else
	    lessthan = YES

        # Search for points with X values between x1 and x2
	do i = 1 , npix {
	    if ((deleted[i] == YES && undelete == NO) ||
		(deleted[i] == NO && undelete == YES))
		next
	    
	    if (x[i] <= x2 && x[i] >= x1) {
		# Now which side of the line does this point fall on
		temp = x[i] * slope + inter
		if (y[i] < temp && lessthan == YES) {
		    if (undelete == NO) {
		        deleted[i] = YES
	                # Plot X over point
			call gseti (gd, G_PMLTYPE, GL_SOLID)
	                call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		    } else {
			deleted[i] = NO
		        call gseti (gd, G_PMLTYPE, GL_CLEAR)
	                call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		    }
		} else if (y[i] > temp && lessthan == NO) {
		    if (undelete == NO) {
		        deleted[i] = YES
	                # Plot X over point
			call gseti (gd, G_PMLTYPE, GL_SOLID)
	                call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		    } else {
			deleted[i] = NO
		        call gseti (gd, G_PMLTYPE, GL_CLEAR)
	                call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
		    }
		}
	    }
	}
end

# GT_PDEL -- Overplot crosses on those points which have been marked for zap.

procedure gt_pdel (gd, x, y, deleted, npix)

pointer	gd
real	x[ARB]
real	y[ARB]
int	deleted[ARB]
int	npix

int 	i

begin
	do i = 1, npix {
	    if (deleted[i] == YES) {
	        # Plot X over point
		call gseti (gd, G_PMLTYPE, GL_SOLID)
	        call gmark (gd, x[i], y[i], GM_CROSS, MSIZE, MSIZE)
	    }
	}
end