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

« back to all changes in this revision

Viewing changes to bond_style1_quad1.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_style1_quad1.c
 
6
 
 
7
Purpose:
 
8
        Draw bond which fits into quadrant 1 using style 1. See the file
 
9
        file bonds_style1.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 1 using style 1:===============================*/
 
36
 
 
37
int BondStyle1Quadrant1_ (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;
 
42
double                  d, atomic_z;
 
43
size_t                  pixelI;
 
44
NearestAtomS            *curr_pixelSP;
 
45
 
 
46
/* Scale factor required to calculate screen_y from screen_x: */
 
47
if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x;
 
48
else recip_denom = 0.0;
 
49
x_to_y_scale = aux1SP->screen_delta_y * recip_denom;
 
50
 
 
51
/* Scale factor required to calculate z (in atomic units) from screen_x: */
 
52
x_to_z_scale = aux1SP->atomic_delta_z * recip_denom;
 
53
 
 
54
/* Horizontal scan, from left to right: */
 
55
screen_x1 = aux1SP->screen_x0 + (aux1SP->screen_delta_x + 1) / 2;
 
56
for (screen_x = aux1SP->screen_x0; screen_x <= screen_x1; screen_x++)
 
57
        {
 
58
        /* Check is this pixel inside the area reserved for the */
 
59
        /* current image (there are two images in stereo mode): */
 
60
        if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
 
61
                {
 
62
                continue;
 
63
                }
 
64
        if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
 
65
                {
 
66
                continue;
 
67
                }
 
68
 
 
69
        /* Relative position: */
 
70
        delta_x = screen_x - aux1SP->screen_x0;
 
71
 
 
72
        /* Find the corresponding screen_y: */
 
73
        d = aux1SP->screen_y0 + x_to_y_scale * delta_x;
 
74
        screen_y = (int) (d + 0.5);
 
75
 
 
76
        /* Check is this pixel inside the area reserved for the */
 
77
        /* current image (there are two images in stereo mode): */
 
78
        if (screen_y < aux1SP->configSP->image_screen_y0) continue;
 
79
        if (screen_y > aux1SP->configSP->image_screen_y1) continue;
 
80
 
 
81
        /* z value (in atomic units): */
 
82
        atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x;
 
83
 
 
84
        /* Current pixel index: */
 
85
        pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
 
86
 
 
87
        /* Check pixel index: */
 
88
        if (pixelI >= aux1SP->pixelsN) break;
 
89
 
 
90
        /* Pointer to  NearestAtomS struct. */
 
91
        /* assigned to current coordinates: */
 
92
        curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
 
93
 
 
94
        /* Check was  this pixel used  already in */
 
95
        /* this drawing step;  if it was, compare */
 
96
        /* the z value of the current atom with z */
 
97
        /* value previously stored to this pixel: */
 
98
        if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
 
99
                {
 
100
                if (atomic_z >= curr_pixelSP->z) continue;
 
101
                }
 
102
 
 
103
        /* If this point is reached, draw the pixel: */
 
104
        XDrawPoint (aux1SP->guiSP->displaySP,
 
105
                    aux1SP->guiSP->main_hidden_pixmapID,
 
106
                    aux1SP->guiSP->theGCA[0],
 
107
                    screen_x, screen_y);
 
108
 
 
109
        /* Refresh the content of NearestAtomS */
 
110
        /* array  associated  with this pixel: */
 
111
        curr_pixelSP->styleI = 1;
 
112
        curr_pixelSP->last_refreshI = aux1SP->refreshI;
 
113
        curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
 
114
        curr_pixelSP->atomI = aux1SP->atomI;
 
115
        curr_pixelSP->z = atomic_z;
 
116
        curr_pixelSP->colorID = aux1SP->colorIDA[0];
 
117
 
 
118
        /* Update the number of pixels drawn: */
 
119
        pixels_drawnN++;
 
120
        }
 
121
 
 
122
/* Check is at least one pixel drawn: */
 
123
if (pixels_drawnN > 0) return 1;
 
124
 
 
125
/* If this point is reached, nothing is drawn: */
 
126
return 0;
 
127
}
 
128
 
 
129
/*===========================================================================*/
 
130
 
 
131