1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Draw bond which fits into quadrant 4 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 4 using style 2:===============================*/
37
int BondStyle2Quadrant4_ (Aux1S *aux1SP)
39
long pixels_drawnN = 0;
40
double recip_denom, y_to_x_scale, y_to_z_scale;
41
int screen_x, line_screen_x, screen_y, screen_y1, delta_y;
45
NearestAtomS *curr_pixelSP;
47
/* Scale factor required to calculate screen_x from screen_y: */
48
if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y;
49
else recip_denom = 0.0;
50
y_to_x_scale = aux1SP->screen_delta_x * recip_denom;
52
/* Scale factor required to calculate z (in atomic units) from screen_y: */
53
y_to_z_scale = aux1SP->atomic_delta_z * recip_denom;
55
/* Vertical scan (bottom to top): */
56
screen_y1 = aux1SP->screen_y0 + (aux1SP->screen_delta_y + 1) / 2;
57
for (screen_y = aux1SP->screen_y0; screen_y >= screen_y1; screen_y--)
59
/* Check is this pixel inside the area reserved for the */
60
/* current image (there are two images in stereo mode): */
61
if (screen_y < aux1SP->configSP->image_screen_y0) continue;
62
if (screen_y > aux1SP->configSP->image_screen_y1) continue;
64
/* Relative position: */
65
delta_y = screen_y - aux1SP->screen_y0;
67
/* Find the corresponding screen_x: */
68
d = aux1SP->screen_x0 + y_to_x_scale * delta_y;
69
screen_x = (int) (d + 0.5);
71
/* z value (in atomic units): */
72
atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y;
74
/* Loop which draws three lines (horizontal scan): */
75
for (lineI = 0; lineI <= 2; lineI++)
78
line_screen_x = screen_x +lineI - 1;
80
/* Check is this pixel inside the area reserved for the */
81
/* current image (there are two images in stereo mode): */
83
aux1SP->configSP->image_screen_x0[aux1SP->imageI])
88
aux1SP->configSP->image_screen_x1[aux1SP->imageI])
93
/* Current pixel index: */
94
pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y +
97
/* Check pixel index: */
98
if (pixelI >= aux1SP->pixelsN) break;
100
/* Pointer to NearestAtomS struct. */
101
/* assigned to current coordinates: */
102
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
104
/* Check was this pixel used already in */
105
/* this drawing step; if it was, compare */
106
/* the z value of the current atom with z */
107
/* value previously stored to this pixel: */
108
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
110
if (atomic_z >= curr_pixelSP->z) continue;
113
/* If this point is reached draw pixel: */
114
XDrawPoint (aux1SP->guiSP->displaySP,
115
aux1SP->guiSP->main_hidden_pixmapID,
116
aux1SP->guiSP->theGCA[lineI],
117
line_screen_x, screen_y);
119
/* Refresh the content of NearestAtomS */
120
/* array associated with this pixel: */
121
curr_pixelSP->styleI = 2;
122
curr_pixelSP->last_refreshI = aux1SP->refreshI;
123
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
124
curr_pixelSP->atomI = aux1SP->atomI;
125
curr_pixelSP->z = atomic_z;
126
curr_pixelSP->colorID = aux1SP->colorIDA[lineI];
128
/* Update the number of pixels drawn: */
133
/* Rounding the bottom end: */
136
/* Pixel position: */
137
screen_x = aux1SP->screen_x0;
138
screen_y = aux1SP->screen_y0 + 1;
140
/* Check is this pixel inside the area reserved for the */
141
/* current image (there are two images in stereo mode): */
142
if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
146
if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
150
if (screen_y < aux1SP->configSP->image_screen_y0) break;
151
if (screen_y > aux1SP->configSP->image_screen_y1) break;
153
/* Current pixel index: */
154
pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
156
/* Check pixel index: */
157
if (pixelI >= aux1SP->pixelsN) break;
159
/* Pointer to NearestAtomS struct. */
160
/* assigned to current coordinates: */
161
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
163
/* Relative position: */
164
delta_y = screen_y - aux1SP->screen_y0;
166
/* z value (in atomic units): */
167
atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y;
169
/* Check was this pixel used already in */
170
/* this drawing step; if it was, compare */
171
/* the z value of the current atom with z */
172
/* value previously stored to this pixel: */
173
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
175
if (atomic_z >= curr_pixelSP->z) continue;
178
/* If this point is reached draw one pixel: */
179
XDrawPoint (aux1SP->guiSP->displaySP,
180
aux1SP->guiSP->main_hidden_pixmapID,
181
aux1SP->guiSP->theGCA[1],
184
/* Refresh the content of NearestAtomS */
185
/* array associated with this pixel: */
186
curr_pixelSP->styleI = 2;
187
curr_pixelSP->last_refreshI = aux1SP->refreshI;
188
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
189
curr_pixelSP->atomI = aux1SP->atomI;
190
curr_pixelSP->z = atomic_z;
191
curr_pixelSP->colorID = aux1SP->colorIDA[1];
193
/* Update the number of pixels drawn: */
196
/* End of single pass loop: */
199
/* Rounding the top end: */
202
/* Pixel position: */
203
screen_y = screen_y1 - 1;
204
delta_y = screen_y1 - aux1SP->screen_y0;
205
d = aux1SP->screen_x0 + y_to_x_scale * (screen_y1 - aux1SP->screen_y0);
206
screen_x = (int) (d + 0.5);
208
/* Check is this pixel inside the area reserved for the */
209
/* current image (there are two images in stereo mode): */
210
if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
214
if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
218
if (screen_y < aux1SP->configSP->image_screen_y0) break;
219
if (screen_y > aux1SP->configSP->image_screen_y1) break;
221
/* Current pixel index: */
222
pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
224
/* Check pixel index: */
225
if (pixelI >= aux1SP->pixelsN) break;
227
/* Pointer to NearestAtomS struct. */
228
/* assigned to current coordinates: */
229
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
231
/* Relative position: */
232
delta_y = screen_y - aux1SP->screen_y0;
234
/* z value (in atomic units): */
235
atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y;
237
/* Check was this pixel used already in */
238
/* this drawing step; if it was, compare */
239
/* the z value of the current atom with z */
240
/* value previously stored to this pixel: */
241
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
243
if (atomic_z >= curr_pixelSP->z) continue;
246
/* If this point is reached draw one pixel: */
247
XDrawPoint (aux1SP->guiSP->displaySP,
248
aux1SP->guiSP->main_hidden_pixmapID,
249
aux1SP->guiSP->theGCA[1],
252
/* Refresh the content of NearestAtomS */
253
/* array associated with this pixel: */
254
curr_pixelSP->styleI = 2;
255
curr_pixelSP->last_refreshI = aux1SP->refreshI;
256
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
257
curr_pixelSP->atomI = aux1SP->atomI;
258
curr_pixelSP->z = atomic_z;
259
curr_pixelSP->colorID = aux1SP->colorIDA[1];
261
/* Update the number of pixels drawn: */
264
/* End of single pass loop: */
267
/* Check is at least one pixel drawn: */
268
if (pixels_drawnN > 0) return 1;
270
/* If this point is reached, nothing is drawn: */
274
/*===========================================================================*/