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

« back to all changes in this revision

Viewing changes to bond_style4_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_style4_quad3.c
 
6
 
 
7
Purpose:
 
8
        Draw bond which fits into quadrant 3 using style 4. See the file
 
9
        file bonds_style4.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 4:===============================*/
 
36
 
 
37
int BondStyle4Quadrant3_ (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
int                     edge_y, columnI;
 
47
static int              edge_maskAA[5][2] =
 
48
                                {{1, 0}, {1, 1}, {1, 1}, {1, 1}, {1, 0}};
 
49
 
 
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;
 
54
 
 
55
/* Scale factor required to calculate z (in atomic units) from screen_x: */
 
56
x_to_z_scale = aux1SP->atomic_delta_z * recip_denom;
 
57
 
 
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--)
 
61
        {
 
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])
 
65
                {
 
66
                continue;
 
67
                }
 
68
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
69
                {
 
70
                continue;
 
71
                }
 
72
 
 
73
        /* Relative position: */
 
74
        delta_x = screen_x - aux1SP->screen_x0;
 
75
 
 
76
        /* Find the corresponding screen_y: */
 
77
        d = aux1SP->screen_y0 + x_to_y_scale * delta_x;
 
78
        screen_y = (int) (d + 0.5);
 
79
 
 
80
        /* z value (in atomic units): */
 
81
        atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
 
82
        
 
83
        /* Loop which draws lines (vertical scan): */
 
84
        for (lineI = 0; lineI <= 6; lineI++)
 
85
                {
 
86
                /* Pixel position: */
 
87
                line_screen_y = screen_y +lineI - 3;
 
88
 
 
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)
 
92
                        {
 
93
                        continue;
 
94
                        }
 
95
                if (line_screen_y > aux1SP->configSP->image_screen_y1)
 
96
                        {
 
97
                        continue;
 
98
                        }
 
99
 
 
100
                /* Current pixel index: */
 
101
                pixelI = aux1SP->guiSP->main_win_free_area_width *
 
102
                         line_screen_y + screen_x;
 
103
 
 
104
                /* Check pixel index: */
 
105
                if (pixelI >= aux1SP->pixelsN) break;
 
106
 
 
107
                /* Pointer to  NearestAtomS struct. */
 
108
                /* assigned to current coordinates: */
 
109
                curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
110
 
 
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)
 
116
                        {
 
117
                        if (atomic_z >= curr_pixelSP->z) continue;
 
118
                        }
 
119
 
 
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);
 
125
 
 
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];
 
134
 
 
135
                /* Update the number of pixels drawn: */
 
136
                pixels_drawnN++;
 
137
                }
 
138
        }
 
139
 
 
140
/* Rounding the right end: */
 
141
edge_y  = aux1SP->screen_y0;
 
142
atomic_z = aux1SP->atomic_z0;
 
143
for (columnI = 0; columnI <= 1; columnI++)
 
144
        {
 
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])
 
148
                continue;
 
149
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
150
                continue;
 
151
 
 
152
        /* Vertical scan: */
 
153
        for (lineI = 0; lineI <= 4; lineI++)
 
154
                {
 
155
                /* Pixel y coordinate: */
 
156
                line_screen_y = edge_y + lineI - 2;
 
157
 
 
158
                /* Check line_screen_y: */
 
159
                if (line_screen_y < aux1SP->configSP->image_screen_y0)
 
160
                        continue;
 
161
                if (line_screen_y > aux1SP->configSP->image_screen_y1)
 
162
                        continue;
 
163
 
 
164
                /* Check the mask: */
 
165
                if (!edge_maskAA[lineI][columnI]) continue;
 
166
 
 
167
                /* Current pixel index: */
 
168
                pixelI = aux1SP->guiSP->main_win_free_area_width *
 
169
                         line_screen_y + screen_x;
 
170
 
 
171
                /* Check pixel index: */
 
172
                if (pixelI >= aux1SP->pixelsN) break;
 
173
 
 
174
                /* Pointer to  NearestAtomS struct. */
 
175
                /* assigned to current coordinates: */
 
176
                curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
177
 
 
178
                /* Check was this pixel used already in this drawing step : */
 
179
                if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
 
180
                        {
 
181
                        if (atomic_z >= curr_pixelSP->z) continue;
 
182
                        }
 
183
 
 
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);
 
189
 
 
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];
 
198
 
 
199
                /* Update the number of pixels drawn: */
 
200
                pixels_drawnN++;
 
201
                }
 
202
        }
 
203
 
 
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++)
 
210
        {
 
211
        /* Prepare and check screen_x: */
 
212
        screen_x = screen_x1 - columnI - 1;
 
213
        if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
 
214
                continue;
 
215
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
216
                continue;
 
217
 
 
218
        /* Vertical scan: */
 
219
        for (lineI = 0; lineI <= 4; lineI++)
 
220
                {
 
221
                /* Pixel y coordinate: */
 
222
                line_screen_y = edge_y + lineI - 2;
 
223
 
 
224
                /* Check line_screen_y: */
 
225
                if (line_screen_y < aux1SP->configSP->image_screen_y0)
 
226
                        continue;
 
227
                if (line_screen_y > aux1SP->configSP->image_screen_y1)
 
228
                        continue;
 
229
 
 
230
                /* Check the mask: */
 
231
                if (!edge_maskAA[lineI][columnI]) continue;
 
232
 
 
233
                /* Current pixel index: */
 
234
                pixelI = aux1SP->guiSP->main_win_free_area_width *
 
235
                        line_screen_y + screen_x;
 
236
 
 
237
                /* Check pixel index: */
 
238
                if (pixelI >= aux1SP->pixelsN) break;
 
239
 
 
240
                /* Pointer to  NearestAtomS struct. */
 
241
                /* assigned to current coordinates: */
 
242
                curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
243
 
 
244
                /* Check was this pixel used already in this drawing step : */
 
245
                if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
 
246
                        {
 
247
                        if (atomic_z >= curr_pixelSP->z) continue;
 
248
                        }
 
249
 
 
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);
 
255
 
 
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];
 
264
 
 
265
                /* Update the number of pixels drawn: */
 
266
                pixels_drawnN++;
 
267
                }
 
268
        }
 
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