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

« back to all changes in this revision

Viewing changes to bond_style2_quad3.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_quad3.c
 
6
 
 
7
Purpose:
 
8
        Draw bond which fits into quadrant 3 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 3 using style 2:===============================*/
 
36
 
 
37
int BondStyle2Quadrant3_ (Aux1S *aux1SP)
 
38
{
 
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;
 
42
double                  d, atomic_z;
 
43
int                     lineI;
 
44
size_t                  pixelI;
 
45
NearestAtomS            *curr_pixelSP;
 
46
 
 
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;
 
51
 
 
52
/* Scale factor required to calculate z (in atomic units) from screen_x: */
 
53
x_to_z_scale = aux1SP->atomic_delta_z * recip_denom;
 
54
 
 
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--)
 
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_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
 
62
                {
 
63
                continue;
 
64
                }
 
65
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
66
                {
 
67
                continue;
 
68
                }
 
69
 
 
70
        /* Relative position: */
 
71
        delta_x = screen_x - aux1SP->screen_x0;
 
72
 
 
73
        /* Find the corresponding screen_y: */
 
74
        d = aux1SP->screen_y0 + x_to_y_scale * delta_x;
 
75
        screen_y = (int) (d + 0.5);
 
76
 
 
77
        /* z value (in atomic units): */
 
78
        atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
 
79
        
 
80
        /* Loop which draws three lines (vertical scan): */
 
81
        for (lineI = 0; lineI <= 2; lineI++)
 
82
                {
 
83
                /* Pixel position: */
 
84
                line_screen_y = screen_y +lineI - 1;
 
85
 
 
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)
 
89
                        {
 
90
                        continue;
 
91
                        }
 
92
                if (line_screen_y > aux1SP->configSP->image_screen_y1)
 
93
                        {
 
94
                        continue;
 
95
                        }
 
96
 
 
97
                /* Current pixel index: */
 
98
                pixelI = aux1SP->guiSP->main_win_free_area_width *
 
99
                         line_screen_y + screen_x;
 
100
 
 
101
                /* Check pixel index: */
 
102
                if (pixelI >= aux1SP->pixelsN) break;
 
103
 
 
104
                /* Pointer to  NearestAtomS struct. */
 
105
                /* assigned to current coordinates: */
 
106
                curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
107
 
 
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)
 
113
                        {
 
114
                        if (atomic_z >= curr_pixelSP->z) continue;
 
115
                        }
 
116
 
 
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);
 
122
 
 
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];
 
131
 
 
132
                /* Update the number of pixels drawn: */
 
133
                pixels_drawnN++;
 
134
                }
 
135
        }
 
136
 
 
137
/* Rounding the right end: */
 
138
do
 
139
        {
 
140
        /* Pixel position: */
 
141
        screen_x = aux1SP->screen_x0 + 1;
 
142
        screen_y = aux1SP->screen_y0;
 
143
 
 
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])
 
147
                {
 
148
                break;
 
149
                }
 
150
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
151
                {
 
152
                break;
 
153
                }
 
154
        if (screen_y < aux1SP->configSP->image_screen_y0) break;
 
155
        if (screen_y > aux1SP->configSP->image_screen_y1) break;
 
156
 
 
157
        /* Current pixel index: */
 
158
        pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
 
159
 
 
160
        /* Check pixel index: */
 
161
        if (pixelI >= aux1SP->pixelsN) break;
 
162
 
 
163
        /* Pointer to  NearestAtomS struct. */
 
164
        /* assigned to current coordinates: */
 
165
        curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
166
 
 
167
        /* Relative position: */
 
168
        delta_x = screen_x - aux1SP->screen_x0;
 
169
 
 
170
        /* z value (in atomic units): */
 
171
        atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
 
172
 
 
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)
 
178
                {
 
179
                if (atomic_z >= curr_pixelSP->z) continue;
 
180
                }
 
181
 
 
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],
 
186
                    screen_x, screen_y);
 
187
 
 
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];
 
196
 
 
197
        /* Update the number of pixels drawn: */
 
198
        pixels_drawnN++;
 
199
 
 
200
        /* End of single pass loop: */
 
201
        } while (0);
 
202
 
 
203
/* Rounding the left end: */
 
204
do
 
205
        {
 
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);
 
210
 
 
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])
 
214
                {
 
215
                break;
 
216
                }
 
217
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
218
                {
 
219
                break;
 
220
                }
 
221
        if (screen_y < aux1SP->configSP->image_screen_y0) break;
 
222
        if (screen_y > aux1SP->configSP->image_screen_y1) break;
 
223
 
 
224
        /* Current pixel index: */
 
225
        pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
 
226
 
 
227
        /* Check pixel index: */
 
228
        if (pixelI >= aux1SP->pixelsN) break;
 
229
 
 
230
        /* Pointer to  NearestAtomS struct. */
 
231
        /* assigned to current coordinates: */
 
232
        curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
233
 
 
234
        /* Relative position: */
 
235
        delta_x = screen_x - aux1SP->screen_x0;
 
236
 
 
237
        /* z value (in atomic units): */
 
238
        atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
 
239
 
 
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)
 
245
                {
 
246
                if (atomic_z >= curr_pixelSP->z) continue;
 
247
                }
 
248
 
 
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],
 
253
                    screen_x, screen_y);
 
254
 
 
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];
 
263
 
 
264
        /* Update the number of pixels drawn: */
 
265
        pixels_drawnN++;
 
266
 
 
267
        /* End of single pass loop: */
 
268
        } while (0);
 
269
 
 
270
/* Check is at least one pixel drawn: */
 
271
if (pixels_drawnN > 0) return 1;
 
272
 
 
273
/* If this point is reached, nothing is drawn: */
 
274
return 0;
 
275
}
 
276
 
 
277
/*===========================================================================*/
 
278
 
 
279