File: tag_position.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (112 lines) | stat: -rw-r--r-- 3,082 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				tag_position.c

Purpose:
	Find the tag position in screen coordinates.

Input:
	(1) Pointer to horizontal position of the left image.
	(2) Pointer to horizontal position of the right image.
	(3) Pointer to vertical position.
	(4) Pointer to MolComplexS structure.
	(5) The number of images (1 for mono, 2 for stereo).

Output:
	(1) Horizontal position set (two values for stereo mode).
	(2) Vertical position set.
	(3) Return value.

Return value:
	(1) Positive if macromol. complex contains at least one atom.
	(2) Zero, if there are no atoms.

========includes:============================================================*/

#include <stdio.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======find tag position:===================================================*/

int TagPosition_ (int *tag_screen_left_xP,
		  int *tag_screen_right_xP,
		  int *tag_screen_yP,
		  MolComplexS *curr_mol_complexSP,
		  int imagesN)
{
size_t		atomsN, atomI;
AtomS		*curr_atomSP;
int		screen_left_x_min, screen_left_x_max;
int		screen_right_x_min = 0, screen_right_x_max = 0;
int		screen_y_min, screen_y_max;
int		screen_left_x, screen_right_x, screen_y;

/* Return if there are no atoms: */
atomsN = curr_mol_complexSP->atomsN;
if (atomsN == 0) return 0;

/* Initialize extreme values using the screen coordinates of the first atom: */
screen_left_x_min = curr_mol_complexSP->atomSP->raw_atomS.screen_x[0];
screen_left_x_max = screen_left_x_min;
screen_y_min      = curr_mol_complexSP->atomSP->raw_atomS.screen_y;
screen_y_max      = screen_y_min;
if (imagesN == 2)
	{
	screen_right_x_min = curr_mol_complexSP->atomSP->raw_atomS.screen_x[1];
	screen_right_x_max = screen_right_x_min;
	}

/* Find new extreme values; skip the first atom: */
for (atomI = 1; atomI < atomsN; atomI++)
	{
	/** Current AtomS pointer: **/
	curr_atomSP = curr_mol_complexSP->atomSP + atomI;

	/** Min./max.: **/
	screen_left_x = curr_atomSP->raw_atomS.screen_x[0];
	screen_y      = curr_atomSP->raw_atomS.screen_y;
	if (screen_left_x < screen_left_x_min)
		{
		screen_left_x_min = screen_left_x;
		}
	if (screen_left_x > screen_left_x_max)
		{
		screen_left_x_max = screen_left_x;
		}
	if (screen_y < screen_y_min) screen_y_min = screen_y;
	if (screen_y > screen_y_max) screen_y_max = screen_y;
	if (imagesN == 2)
		{
		screen_right_x = curr_atomSP->raw_atomS.screen_x[1];
		if (screen_right_x < screen_right_x_min)
			{
			screen_right_x_min = screen_right_x;
			}
		if (screen_right_x > screen_right_x_max)
			{
			screen_right_x_max = screen_right_x;
			}
		}
	}

/* Set new values: */
*tag_screen_left_xP  = (screen_left_x_min  + screen_left_x_max)  / 2;
*tag_screen_right_xP = (screen_right_x_min + screen_right_x_max) / 2;
*tag_screen_yP       = screen_y_min;

/* Return 1 if this point is reached: */
return 1;
}

/*===========================================================================*/