1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Draw bond which fits into quadrant 3 using style 2. See the file
9
file bonds_style2.c for description of quadrants.
12
(1) Pointer to Aux1S structure, which contains required data.
15
(1) A single bond drawn.
19
(1) One if at least one pixel is drawn.
22
=============================================================================*/
28
#include <X11/Xutil.h>
30
#include <X11/Xatom.h>
35
/*======draw bond in quadrant 3 using style 2:===============================*/
37
int BondStyle2Quadrant3_ (Aux1S *aux1SP)
39
long pixels_drawnN = 0;
40
double recip_denom, x_to_y_scale, x_to_z_scale;
41
int screen_x, screen_x1, delta_x, screen_y, line_screen_y;
45
NearestAtomS *curr_pixelSP;
47
/* Scale factor required to calculate screen_y from screen_x: */
48
if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x;
49
else recip_denom = 0.0;
50
x_to_y_scale = aux1SP->screen_delta_y * recip_denom;
52
/* Scale factor required to calculate z (in atomic units) from screen_x: */
53
x_to_z_scale = aux1SP->atomic_delta_z * recip_denom;
55
/* Horizontal scan, from right to left: */
56
screen_x1 = aux1SP->screen_x0 + (aux1SP->screen_delta_x + 1) / 2;
57
for (screen_x = aux1SP->screen_x0; screen_x >= screen_x1; screen_x--)
59
/* Check is this pixel inside the area reserved for the */
60
/* current image (there are two images in stereo mode): */
61
if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
65
if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
70
/* Relative position: */
71
delta_x = screen_x - aux1SP->screen_x0;
73
/* Find the corresponding screen_y: */
74
d = aux1SP->screen_y0 + x_to_y_scale * delta_x;
75
screen_y = (int) (d + 0.5);
77
/* z value (in atomic units): */
78
atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
80
/* Loop which draws three lines (vertical scan): */
81
for (lineI = 0; lineI <= 2; lineI++)
84
line_screen_y = screen_y +lineI - 1;
86
/* Check is this pixel inside the area reserved for the */
87
/* current image (there are two images in stereo mode): */
88
if (line_screen_y < aux1SP->configSP->image_screen_y0)
92
if (line_screen_y > aux1SP->configSP->image_screen_y1)
97
/* Current pixel index: */
98
pixelI = aux1SP->guiSP->main_win_free_area_width *
99
line_screen_y + screen_x;
101
/* Check pixel index: */
102
if (pixelI >= aux1SP->pixelsN) break;
104
/* Pointer to NearestAtomS struct. */
105
/* assigned to current coordinates: */
106
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
108
/* Check was this pixel used already in */
109
/* this drawing step; if it was, compare */
110
/* the z value of the current atom with z */
111
/* value previously stored to this pixel: */
112
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
114
if (atomic_z >= curr_pixelSP->z) continue;
117
/* If this point is reached draw pixel: */
118
XDrawPoint (aux1SP->guiSP->displaySP,
119
aux1SP->guiSP->main_hidden_pixmapID,
120
aux1SP->guiSP->theGCA[lineI],
121
screen_x, line_screen_y);
123
/* Refresh the content of NearestAtomS */
124
/* array associated with this pixel: */
125
curr_pixelSP->styleI = 2;
126
curr_pixelSP->last_refreshI = aux1SP->refreshI;
127
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
128
curr_pixelSP->atomI = aux1SP->atomI;
129
curr_pixelSP->z = atomic_z;
130
curr_pixelSP->colorID = aux1SP->colorIDA[lineI];
132
/* Update the number of pixels drawn: */
137
/* Rounding the right end: */
140
/* Pixel position: */
141
screen_x = aux1SP->screen_x0 + 1;
142
screen_y = aux1SP->screen_y0;
144
/* Check is this pixel inside the area reserved for the */
145
/* current image (there are two images in stereo mode): */
146
if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
150
if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
154
if (screen_y < aux1SP->configSP->image_screen_y0) break;
155
if (screen_y > aux1SP->configSP->image_screen_y1) break;
157
/* Current pixel index: */
158
pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
160
/* Check pixel index: */
161
if (pixelI >= aux1SP->pixelsN) break;
163
/* Pointer to NearestAtomS struct. */
164
/* assigned to current coordinates: */
165
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
167
/* Relative position: */
168
delta_x = screen_x - aux1SP->screen_x0;
170
/* z value (in atomic units): */
171
atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
173
/* Check was this pixel used already in */
174
/* this drawing step; if it was, compare */
175
/* the z value of the current atom with z */
176
/* value previously stored to this pixel: */
177
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
179
if (atomic_z >= curr_pixelSP->z) continue;
182
/* If this point is reached draw one pixel: */
183
XDrawPoint (aux1SP->guiSP->displaySP,
184
aux1SP->guiSP->main_hidden_pixmapID,
185
aux1SP->guiSP->theGCA[1],
188
/* Refresh the content of NearestAtomS */
189
/* array associated with this pixel: */
190
curr_pixelSP->styleI = 2;
191
curr_pixelSP->last_refreshI = aux1SP->refreshI;
192
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
193
curr_pixelSP->atomI = aux1SP->atomI;
194
curr_pixelSP->z = atomic_z;
195
curr_pixelSP->colorID = aux1SP->colorIDA[1];
197
/* Update the number of pixels drawn: */
200
/* End of single pass loop: */
203
/* Rounding the left end: */
206
/* Pixel position: */
207
screen_x = screen_x1 - 1;
208
d = aux1SP->screen_y0 + x_to_y_scale * (screen_x1 - aux1SP->screen_x0);
209
screen_y = (int) (d + 0.5);
211
/* Check is this pixel inside the area reserved for the */
212
/* current image (there are two images in stereo mode): */
213
if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
217
if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
221
if (screen_y < aux1SP->configSP->image_screen_y0) break;
222
if (screen_y > aux1SP->configSP->image_screen_y1) break;
224
/* Current pixel index: */
225
pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
227
/* Check pixel index: */
228
if (pixelI >= aux1SP->pixelsN) break;
230
/* Pointer to NearestAtomS struct. */
231
/* assigned to current coordinates: */
232
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
234
/* Relative position: */
235
delta_x = screen_x - aux1SP->screen_x0;
237
/* z value (in atomic units): */
238
atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
240
/* Check was this pixel used already in */
241
/* this drawing step; if it was, compare */
242
/* the z value of the current atom with z */
243
/* value previously stored to this pixel: */
244
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
246
if (atomic_z >= curr_pixelSP->z) continue;
249
/* If this point is reached draw one pixel: */
250
XDrawPoint (aux1SP->guiSP->displaySP,
251
aux1SP->guiSP->main_hidden_pixmapID,
252
aux1SP->guiSP->theGCA[1],
255
/* Refresh the content of NearestAtomS */
256
/* array associated with this pixel: */
257
curr_pixelSP->styleI = 2;
258
curr_pixelSP->last_refreshI = aux1SP->refreshI;
259
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
260
curr_pixelSP->atomI = aux1SP->atomI;
261
curr_pixelSP->z = atomic_z;
262
curr_pixelSP->colorID = aux1SP->colorIDA[1];
264
/* Update the number of pixels drawn: */
267
/* End of single pass loop: */
270
/* Check is at least one pixel drawn: */
271
if (pixels_drawnN > 0) return 1;
273
/* If this point is reached, nothing is drawn: */
277
/*===========================================================================*/