1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Draw bond which fits into quadrant 3 using style 4. See the file
9
file bonds_style4.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 4:===============================*/
37
int BondStyle4Quadrant3_ (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
static int edge_maskAA[5][2] =
48
{{1, 0}, {1, 1}, {1, 1}, {1, 1}, {1, 0}};
50
/* Scale factor required to calculate screen_y from screen_x: */
51
if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x;
52
else recip_denom = 0.0;
53
x_to_y_scale = aux1SP->screen_delta_y * recip_denom;
55
/* Scale factor required to calculate z (in atomic units) from screen_x: */
56
x_to_z_scale = aux1SP->atomic_delta_z * recip_denom;
58
/* Horizontal scan, from right to left: */
59
screen_x1 = (aux1SP->screen_x0 + aux1SP->screen_x1) / 2;
60
for (screen_x = aux1SP->screen_x0; screen_x >= screen_x1; screen_x--)
62
/* Check is this pixel inside the area reserved for the */
63
/* current image (there are two images in stereo mode): */
64
if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
68
if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
73
/* Relative position: */
74
delta_x = screen_x - aux1SP->screen_x0;
76
/* Find the corresponding screen_y: */
77
d = aux1SP->screen_y0 + x_to_y_scale * delta_x;
78
screen_y = (int) (d + 0.5);
80
/* z value (in atomic units): */
81
atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
83
/* Loop which draws lines (vertical scan): */
84
for (lineI = 0; lineI <= 6; lineI++)
87
line_screen_y = screen_y +lineI - 3;
89
/* Check is this pixel inside the area reserved for the */
90
/* current image (there are two images in stereo mode): */
91
if (line_screen_y < aux1SP->configSP->image_screen_y0)
95
if (line_screen_y > aux1SP->configSP->image_screen_y1)
100
/* Current pixel index: */
101
pixelI = aux1SP->guiSP->main_win_free_area_width *
102
line_screen_y + screen_x;
104
/* Check pixel index: */
105
if (pixelI >= aux1SP->pixelsN) break;
107
/* Pointer to NearestAtomS struct. */
108
/* assigned to current coordinates: */
109
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
111
/* Check was this pixel used already in */
112
/* this drawing step; if it was, compare */
113
/* the z value of the current atom with z */
114
/* value previously stored to this pixel: */
115
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
117
if (atomic_z >= curr_pixelSP->z) continue;
120
/* If this point is reached draw pixel: */
121
XDrawPoint (aux1SP->guiSP->displaySP,
122
aux1SP->guiSP->main_hidden_pixmapID,
123
aux1SP->guiSP->theGCA[lineI],
124
screen_x, line_screen_y);
126
/* Refresh the content of NearestAtomS */
127
/* array associated with this pixel: */
128
curr_pixelSP->styleI = 4;
129
curr_pixelSP->last_refreshI = aux1SP->refreshI;
130
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
131
curr_pixelSP->atomI = aux1SP->atomI;
132
curr_pixelSP->z = atomic_z;
133
curr_pixelSP->colorID = aux1SP->colorIDA[lineI];
135
/* Update the number of pixels drawn: */
140
/* Rounding the right end: */
141
edge_y = aux1SP->screen_y0;
142
atomic_z = aux1SP->atomic_z0;
143
for (columnI = 0; columnI <= 1; columnI++)
145
/* Prepare and check screen_x: */
146
screen_x = aux1SP->screen_x0 + columnI + 1;
147
if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
149
if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
153
for (lineI = 0; lineI <= 4; lineI++)
155
/* Pixel y coordinate: */
156
line_screen_y = edge_y + lineI - 2;
158
/* Check line_screen_y: */
159
if (line_screen_y < aux1SP->configSP->image_screen_y0)
161
if (line_screen_y > aux1SP->configSP->image_screen_y1)
164
/* Check the mask: */
165
if (!edge_maskAA[lineI][columnI]) continue;
167
/* Current pixel index: */
168
pixelI = aux1SP->guiSP->main_win_free_area_width *
169
line_screen_y + screen_x;
171
/* Check pixel index: */
172
if (pixelI >= aux1SP->pixelsN) break;
174
/* Pointer to NearestAtomS struct. */
175
/* assigned to current coordinates: */
176
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
178
/* Check was this pixel used already in this drawing step : */
179
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
181
if (atomic_z >= curr_pixelSP->z) continue;
184
/* If this point is reached draw one pixel: */
185
XDrawPoint (aux1SP->guiSP->displaySP,
186
aux1SP->guiSP->main_hidden_pixmapID,
187
aux1SP->guiSP->theGCA[lineI + 1],
188
screen_x, line_screen_y);
190
/* Refresh the content of NearestAtomS */
191
/* array associated with this pixel: */
192
curr_pixelSP->styleI = 4;
193
curr_pixelSP->last_refreshI = aux1SP->refreshI;
194
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
195
curr_pixelSP->atomI = aux1SP->atomI;
196
curr_pixelSP->z = atomic_z;
197
curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1];
199
/* Update the number of pixels drawn: */
204
/* Rounding the right end: */
205
delta_x = screen_x1 - aux1SP->screen_x0;
206
d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x;
207
edge_y = (int) (d + 0.5);
208
atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x;
209
for (columnI = 0; columnI <= 1; columnI++)
211
/* Prepare and check screen_x: */
212
screen_x = screen_x1 - columnI - 1;
213
if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
215
if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
219
for (lineI = 0; lineI <= 4; lineI++)
221
/* Pixel y coordinate: */
222
line_screen_y = edge_y + lineI - 2;
224
/* Check line_screen_y: */
225
if (line_screen_y < aux1SP->configSP->image_screen_y0)
227
if (line_screen_y > aux1SP->configSP->image_screen_y1)
230
/* Check the mask: */
231
if (!edge_maskAA[lineI][columnI]) continue;
233
/* Current pixel index: */
234
pixelI = aux1SP->guiSP->main_win_free_area_width *
235
line_screen_y + screen_x;
237
/* Check pixel index: */
238
if (pixelI >= aux1SP->pixelsN) break;
240
/* Pointer to NearestAtomS struct. */
241
/* assigned to current coordinates: */
242
curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
244
/* Check was this pixel used already in this drawing step : */
245
if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
247
if (atomic_z >= curr_pixelSP->z) continue;
250
/* If this point is reached draw one pixel: */
251
XDrawPoint (aux1SP->guiSP->displaySP,
252
aux1SP->guiSP->main_hidden_pixmapID,
253
aux1SP->guiSP->theGCA[lineI + 1],
254
screen_x, line_screen_y);
256
/* Refresh the content of NearestAtomS */
257
/* array associated with this pixel: */
258
curr_pixelSP->styleI = 4;
259
curr_pixelSP->last_refreshI = aux1SP->refreshI;
260
curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
261
curr_pixelSP->atomI = aux1SP->atomI;
262
curr_pixelSP->z = atomic_z;
263
curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1];
265
/* Update the number of pixels drawn: */
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
/*===========================================================================*/