1 /* Copyright (C) 2000-2002 Damir Zucic */
2 
3 /*=============================================================================
4 
5 				bond_style1_quad4.c
6 
7 Purpose:
8 	Draw bond which fits into quadrant 4 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 	(2) Bond index.
14 
15 Output:
16 	(1) A single bond drawn.
17 	(2) Return value.
18 
19 Return value:
20 	(1) One if at least one pixel is drawn.
21 	(2) Zero otherwise.
22 
23 =============================================================================*/
24 
25 #include <stdio.h>
26 #include <math.h>
27 
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
30 #include <X11/Xos.h>
31 #include <X11/Xatom.h>
32 
33 #include "defines.h"
34 #include "typedefs.h"
35 
36 /*======draw bond in quadrant 4 using style 1:===============================*/
37 
BondStyle1Quadrant4_(Aux1S * aux1SP,int bondI)38 int BondStyle1Quadrant4_ (Aux1S *aux1SP, int bondI)
39 {
40 long			pixels_drawnN = 0;
41 double			recip_denom, y_to_x_scale, y_to_z_scale;
42 int			screen_x, screen_y, screen_y1, delta_y;
43 double			d, atomic_z;
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 	/* Check is this pixel inside the area reserved for the */
72 	/* current image (there are two images in stereo mode): */
73 	if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI])
74 		{
75 		continue;
76 		}
77 	if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI])
78 		{
79 		continue;
80 		}
81 
82 	/* z value (in atomic units): */
83 	atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y;
84 
85 	/* Current pixel index: */
86 	pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x;
87 
88 	/* Check pixel index: */
89 	if (pixelI >= aux1SP->pixelsN) break;
90 
91 	/* Pointer to  NearestAtomS struct. */
92 	/* assigned to current coordinates: */
93 	curr_pixelSP = aux1SP->nearest_atomSP + pixelI;
94 
95 	/* Check was  this pixel used  already in */
96 	/* this drawing step;  if it was, compare */
97 	/* the z value of the current atom with z */
98 	/* value previously stored to this pixel: */
99 	if (aux1SP->refreshI == curr_pixelSP->last_refreshI)
100 		{
101 		if (atomic_z >= curr_pixelSP->z) continue;
102 		}
103 
104 	/* If this point is reached, draw the pixel: */
105 	XDrawPoint (aux1SP->guiSP->displaySP,
106 		    aux1SP->guiSP->main_hidden_pixmapID,
107 		    aux1SP->guiSP->theGCA[0],
108 		    screen_x, screen_y);
109 
110 	/* Refresh the content of NearestAtomS */
111 	/* array  associated  with this pixel: */
112 	curr_pixelSP->styleI = 1;
113 	curr_pixelSP->last_refreshI = aux1SP->refreshI;
114 	curr_pixelSP->mol_complexI = aux1SP->mol_complexI;
115 	curr_pixelSP->atomI = aux1SP->atomI;
116 	curr_pixelSP->bondI = bondI;
117 	curr_pixelSP->z = atomic_z;
118 	curr_pixelSP->colorID = aux1SP->colorIDA[0];
119 
120 	/* Update the number of pixels drawn: */
121 	pixels_drawnN++;
122 	}
123 
124 /* Check is at least one pixel drawn: */
125 if (pixels_drawnN > 0) return 1;
126 
127 /* If this point is reached, nothing is drawn: */
128 return 0;
129 }
130 
131 /*===========================================================================*/
132 
133 
134