~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to bond_style2_quad4.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                bond_style2_quad4.c
 
6
 
 
7
Purpose:
 
8
        Draw bond which fits into quadrant 4 using style 2. See the file
 
9
        file bonds_style2.c for description of quadrants.
 
10
 
 
11
Input:
 
12
        (1) Pointer to Aux1S structure, which contains required data.
 
13
 
 
14
Output:
 
15
        (1) A single bond drawn.
 
16
        (2) Return value.
 
17
 
 
18
Return value:
 
19
        (1) One if at least one pixel is drawn.
 
20
        (2) Zero otherwise.
 
21
 
 
22
=============================================================================*/
 
23
 
 
24
#include <stdio.h>
 
25
#include <math.h>
 
26
 
 
27
#include <X11/Xlib.h>
 
28
#include <X11/Xutil.h>
 
29
#include <X11/Xos.h>
 
30
#include <X11/Xatom.h>
 
31
 
 
32
#include "defines.h"
 
33
#include "typedefs.h"
 
34
 
 
35
/*======draw bond in quadrant 4 using style 2:===============================*/
 
36
 
 
37
int BondStyle2Quadrant4_ (Aux1S *aux1SP)
 
38
{
 
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;
 
42
double                  d, atomic_z;
 
43
int                     lineI;
 
44
size_t                  pixelI;
 
45
NearestAtomS            *curr_pixelSP;
 
46
 
 
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;
 
51
 
 
52
/* Scale factor required to calculate z (in atomic units) from screen_y: */
 
53
y_to_z_scale = aux1SP->atomic_delta_z * recip_denom;
 
54
 
 
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--)
 
58
        {
 
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;
 
63
 
 
64
        /* Relative position: */
 
65
        delta_y = screen_y - aux1SP->screen_y0;
 
66
 
 
67
        /* Find the corresponding screen_x: */
 
68
        d = aux1SP->screen_x0 + y_to_x_scale * delta_y;
 
69
        screen_x = (int) (d + 0.5);
 
70
 
 
71
        /* z value (in atomic units): */
 
72
        atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y;
 
73
 
 
74
        /* Loop which draws three lines (horizontal scan): */
 
75
        for (lineI = 0; lineI <= 2; lineI++)
 
76
                {
 
77
                /* Pixel position: */
 
78
                line_screen_x = screen_x +lineI - 1;
 
79
 
 
80
                /* Check is this pixel inside the area reserved for the */
 
81
                /* current image (there are two images in stereo mode): */
 
82
                if (line_screen_x <
 
83
                        aux1SP->configSP->image_screen_x0[aux1SP->imageI])
 
84
                        {
 
85
                        continue;
 
86
                        }
 
87
                if (line_screen_x >
 
88
                        aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
89
                        {
 
90
                        continue;
 
91
                        }
 
92
 
 
93
                /* Current pixel index: */
 
94
                pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y +
 
95
                         line_screen_x;
 
96
 
 
97
                /* Check pixel index: */
 
98
                if (pixelI >= aux1SP->pixelsN) break;
 
99
 
 
100
                /* Pointer to  NearestAtomS struct. */
 
101
                /* assigned to current coordinates: */
 
102
                curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
103
 
 
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)
 
109
                        {
 
110
                        if (atomic_z >= curr_pixelSP->z) continue;
 
111
                        }
 
112
 
 
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);
 
118
 
 
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];
 
127
 
 
128
                /* Update the number of pixels drawn: */
 
129
                pixels_drawnN++;
 
130
                }
 
131
        }
 
132
 
 
133
/* Rounding the bottom end: */
 
134
do
 
135
        {
 
136
        /* Pixel position: */
 
137
        screen_x = aux1SP->screen_x0;
 
138
        screen_y = aux1SP->screen_y0 + 1;
 
139
 
 
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])
 
143
                {
 
144
                break;
 
145
                }
 
146
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
147
                {
 
148
                break;
 
149
                }
 
150
        if (screen_y < aux1SP->configSP->image_screen_y0) break;
 
151
        if (screen_y > aux1SP->configSP->image_screen_y1) break;
 
152
 
 
153
        /* Current pixel index: */
 
154
        pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
 
155
 
 
156
        /* Check pixel index: */
 
157
        if (pixelI >= aux1SP->pixelsN) break;
 
158
 
 
159
        /* Pointer to  NearestAtomS struct. */
 
160
        /* assigned to current coordinates: */
 
161
        curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
162
 
 
163
        /* Relative position: */
 
164
        delta_y = screen_y - aux1SP->screen_y0;
 
165
 
 
166
        /* z value (in atomic units): */
 
167
        atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y;
 
168
 
 
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)
 
174
                {
 
175
                if (atomic_z >= curr_pixelSP->z) continue;
 
176
                }
 
177
 
 
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],
 
182
                    screen_x, screen_y);
 
183
 
 
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];
 
192
 
 
193
        /* Update the number of pixels drawn: */
 
194
        pixels_drawnN++;
 
195
 
 
196
        /* End of single pass loop: */
 
197
        } while (0);
 
198
 
 
199
/* Rounding the top end: */
 
200
do
 
201
        {
 
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);
 
207
 
 
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])
 
211
                {
 
212
                break;
 
213
                }
 
214
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
215
                {
 
216
                break;
 
217
                }
 
218
        if (screen_y < aux1SP->configSP->image_screen_y0) break;
 
219
        if (screen_y > aux1SP->configSP->image_screen_y1) break;
 
220
 
 
221
        /* Current pixel index: */
 
222
        pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
 
223
 
 
224
        /* Check pixel index: */
 
225
        if (pixelI >= aux1SP->pixelsN) break;
 
226
 
 
227
        /* Pointer to  NearestAtomS struct. */
 
228
        /* assigned to current coordinates: */
 
229
        curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
230
 
 
231
        /* Relative position: */
 
232
        delta_y = screen_y - aux1SP->screen_y0;
 
233
 
 
234
        /* z value (in atomic units): */
 
235
        atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y;
 
236
 
 
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)
 
242
                {
 
243
                if (atomic_z >= curr_pixelSP->z) continue;
 
244
                }
 
245
 
 
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],
 
250
                    screen_x, screen_y);
 
251
 
 
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];
 
260
 
 
261
        /* Update the number of pixels drawn: */
 
262
        pixels_drawnN++;
 
263
 
 
264
        /* End of single pass loop: */
 
265
        } while (0);
 
266
 
 
267
/* Check is at least one pixel drawn: */
 
268
if (pixels_drawnN > 0) return 1;
 
269
 
 
270
/* If this point is reached, nothing is drawn: */
 
271
return 0;
 
272
}
 
273
 
 
274
/*===========================================================================*/
 
275
 
 
276