File: bond_style3_quad4.c

package info (click to toggle)
garlic 1.5-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,324 kB
  • ctags: 1,378
  • sloc: ansic: 50,306; makefile: 1,088
file content (298 lines) | stat: -rw-r--r-- 8,129 bytes parent folder | download | duplicates (5)
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
/* Copyright (C) 2000-2002 Damir Zucic */

/*=============================================================================

				bond_style3_quad4.c

Purpose:
	Draw bond which fits into quadrant 4 using style 3. See the file
	file bonds_style3.c for description of quadrants.

Input:
	(1) Pointer to Aux1S structure, which contains required data.
	(2) Bond index.

Output:
	(1) A single bond drawn.
	(2) Return value.

Return value:
	(1) One if at least one pixel is drawn.
	(2) Zero otherwise.

=============================================================================*/

#include <stdio.h>

#include <math.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======draw bond in quadrant 4 using style 3:===============================*/

int BondStyle3Quadrant4_ (Aux1S *aux1SP, int bondI)
{
long			pixels_drawnN = 0;
double			recip_denom, y_to_x_scale, y_to_z_scale;
int                     screen_x, line_screen_x, screen_y, screen_y1, delta_y;
double			d, atomic_z;
int			lineI;
size_t			pixelI;
NearestAtomS		*curr_pixelSP;

/* Scale factor required to calculate screen_x from screen_y: */
if (aux1SP->screen_delta_y != 0)
	recip_denom = 1.0 / (double) aux1SP->screen_delta_y;
else recip_denom = 0.0;
y_to_x_scale = (double) aux1SP->screen_delta_x * recip_denom;

/* Scale factor required to calculate z (in atomic units) from screen_y: */
y_to_z_scale = aux1SP->atomic_delta_z * recip_denom;

/* Vertical scan (bottom to top): */
screen_y1 = (aux1SP->screen_y0 + aux1SP->screen_y1) / 2;
for (screen_y = aux1SP->screen_y0; screen_y >= screen_y1; screen_y--)
	{
	/* Check is this pixel inside the area reserved for the */
	/* current image (there are two images in stereo mode): */
	if (screen_y < aux1SP->configSP->image_screen_y0) continue;
	if (screen_y > aux1SP->configSP->image_screen_y1) continue;

	/* Relative position: */
	delta_y = screen_y - aux1SP->screen_y0;

	/* Find the corresponding screen_x: */
	d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y;
	screen_x = (int) (d + 0.5);

	/* z value (in atomic units): */
	atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y;

	/* Loop which draws five lines (horizontal scan): */
	for (lineI = 0; lineI <= 4; lineI++)
		{
		/* Pixel position: */
		line_screen_x = screen_x +lineI - 2;

		/* Check is this pixel inside the area reserved for the */
		/* current image (there are two images in stereo mode): */
		if (line_screen_x <
			aux1SP->configSP->image_screen_x0[aux1SP->imageI])
			{
			continue;
			}
		if (line_screen_x >
			aux1SP->configSP->image_screen_x1[aux1SP->imageI])
			{
			continue;
			}

		/* Current pixel index: */
		pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y +
			 line_screen_x;

		/* Check pixel index: */
		if (pixelI >= aux1SP->pixelsN) break;

		/* Pointer to  NearestAtomS struct. */
		/* assigned to current coordinates: */
		curr_pixelSP = aux1SP->nearest_atomSP + pixelI;

		/* Check was  this pixel used  already in */
		/* this drawing step;  if it was, compare */
		/* the z value of the current atom with z */
		/* value previously stored to this pixel: */
		if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
			{
			if (atomic_z >= curr_pixelSP->z) continue;
			}

		/* If this point is reached draw pixel: */
	        XDrawPoint (aux1SP->guiSP->displaySP,
			    aux1SP->guiSP->main_hidden_pixmapID,
			    aux1SP->guiSP->theGCA[lineI],
			    line_screen_x, screen_y);

		/* Refresh the content of NearestAtomS */
		/* array  associated  with this pixel: */
		curr_pixelSP->styleI = 3;
		curr_pixelSP->last_refreshI = aux1SP->refreshI;
		curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
		curr_pixelSP->atomI = aux1SP->atomI;
		curr_pixelSP->bondI = bondI;
		curr_pixelSP->z = atomic_z;
		curr_pixelSP->colorID = aux1SP->colorIDA[lineI];

		/* Update the number of pixels drawn: */
		pixels_drawnN++;
		}
	}

/* Rounding the bottom end: */
do
	{
	/* The y coordinate: */
	screen_y = aux1SP->screen_y0 + 1;

	/* Check: */
	if (screen_y < aux1SP->configSP->image_screen_y0) break;
	if (screen_y > aux1SP->configSP->image_screen_y1) break;

	/* z value (in atomic units): */
	atomic_z = aux1SP->atomic_z0;

	/* The x coordinate of central pixel: */
	screen_x = aux1SP->screen_x0;

	/* Scan three lines: */
	for (lineI = 0; lineI <= 2; lineI++)
		{
		/* Pixel position: */
		line_screen_x = screen_x +lineI - 1;

		/* Check: */
		if (line_screen_x <
			aux1SP->configSP->image_screen_x0[aux1SP->imageI])
			{
			continue;
			}
		if (line_screen_x >
			aux1SP->configSP->image_screen_x1[aux1SP->imageI])
			{
			continue;
			}

		/* Current pixel index: */
		pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y +
			 line_screen_x;

		/* Check pixel index: */
		if (pixelI >= aux1SP->pixelsN) break;

		/* Pointer to  NearestAtomS struct. */
		/* assigned to current coordinates: */
		curr_pixelSP = aux1SP->nearest_atomSP + pixelI;

		/* Check was this pixel used already in this drawing step : */
		if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
			{
			if (atomic_z >= curr_pixelSP->z) continue;
			}

		/* If this point is reached draw one pixel: */
		XDrawPoint (aux1SP->guiSP->displaySP,
			    aux1SP->guiSP->main_hidden_pixmapID,
			    aux1SP->guiSP->theGCA[lineI + 1],
			    line_screen_x, screen_y);

		/* Refresh the content of NearestAtomS */
		/* array  associated  with this pixel: */
		curr_pixelSP->styleI = 3;
		curr_pixelSP->last_refreshI = aux1SP->refreshI;
		curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
		curr_pixelSP->atomI = aux1SP->atomI;
		curr_pixelSP->bondI = bondI;
		curr_pixelSP->z = atomic_z;
		curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1];

		/* Update the number of pixels drawn: */
		pixels_drawnN++;
		}

	/* End of single pass loop: */
	} while (0);

/* Rounding the top end: */
do
	{
	/* The y coordinate: */
	screen_y = screen_y1 - 1;

	/* Check: */
	if (screen_y < aux1SP->configSP->image_screen_y0) break;
	if (screen_y > aux1SP->configSP->image_screen_y1) break;

	/* Relative position: */
	delta_y = screen_y1 - aux1SP->screen_y0;

	/* z value (in atomic units): */
	atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y;

	/* The x coordinate of central pixel: */
	d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y;
	screen_x = (int) (d + 0.5);

	/* Scan three lines: */
	for (lineI = 0; lineI <= 2; lineI++)
		{
		/* Pixel position: */
		line_screen_x = screen_x +lineI - 1;

		/* Check: */
		if (line_screen_x <
			aux1SP->configSP->image_screen_x0[aux1SP->imageI])
			{
			continue;
			}
		if (line_screen_x >
			aux1SP->configSP->image_screen_x1[aux1SP->imageI])
			{
			continue;
			}

		/* Current pixel index: */
		pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y +
			 line_screen_x;

		/* Check pixel index: */
		if (pixelI >= aux1SP->pixelsN) break;

		/* Pointer to  NearestAtomS struct. */
		/* assigned to current coordinates: */
		curr_pixelSP = aux1SP->nearest_atomSP + pixelI;

		/* Check was this pixel used already in this drawing step : */
		if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
			{
			if (atomic_z >= curr_pixelSP->z) continue;
			}

		/* If this point is reached draw one pixel: */
		XDrawPoint (aux1SP->guiSP->displaySP,
			    aux1SP->guiSP->main_hidden_pixmapID,
			    aux1SP->guiSP->theGCA[lineI + 1],
			    line_screen_x, screen_y);

		/* Refresh the content of NearestAtomS */
		/* array  associated  with this pixel: */
		curr_pixelSP->styleI = 3;
		curr_pixelSP->last_refreshI = aux1SP->refreshI;
		curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
		curr_pixelSP->atomI = aux1SP->atomI;
		curr_pixelSP->bondI = bondI;
		curr_pixelSP->z = atomic_z;
		curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1];

		/* Update the number of pixels drawn: */
		pixels_drawnN++;
		}

	/* End of single pass loop: */
	} while (0);

/* Check is at least one pixel drawn: */
if (pixels_drawnN > 0) return 1;

/* If this point is reached, nothing is drawn: */
return 0;
}

/*===========================================================================*/