File: plane_extent.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 (141 lines) | stat: -rw-r--r-- 4,861 bytes parent folder | download | duplicates (5)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* Copyright (C) 2000 Damir Zucic */

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

				plane_extent.c

Purpose:
	Find  plane extent for  the current image of  the current plane.  If
	drawing in stereo mode, there are two images of each plane. For mono
	mode, there is only one image.

Input:
	(1) Pointer to minimal value of x, in screen units.
	(2) Pointer to maximal value of x, in screen units.
	(3) Pointer to minimal value of y, in screen units.
	(4) Pointer to maximal value of y, in screen units.
	(5) Pointer to PlaneS structure,  with data about the current plane.
	(6) Pointer to ConfigS structure, with configuration data.
	(7) The current image index (0 or 1).

Output:
	(1) Plane extent prepared (four integers).

Return value:
	No return value.

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

#include <stdio.h>

#include <limits.h>
#include <math.h>

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

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

/*======find plane extent:===================================================*/

void PlaneExtent_ (int *screen_x_minP, int *screen_x_maxP,
		   int *screen_y_minP, int *screen_y_maxP,
		   PlaneS *curr_planeSP, ConfigS *configSP, int curr_imageI)
{
int		left_edge, right_edge;
int		center_screen_x, center_screen_y;
double		angle, sin_angle, cos_angle;
double		x1, y1, x2, y2, x3, y3, x4, y4;
double		x1rot, y1rot, x2rot, y2rot, x3rot, y3rot, x4rot, y4rot;
double		x_min, x_max, y_min, y_max;

/* Left and right edge of the current image: */
left_edge  = configSP->image_screen_x0[curr_imageI];
right_edge = configSP->image_screen_x1[curr_imageI];

/* Position of the window free area center: */
center_screen_x = curr_planeSP->center_screen_x[curr_imageI];
center_screen_y = curr_planeSP->center_screen_y;

/* The shifted phi angle, used to rotate the "plane" bounding rectangle: */
angle = curr_planeSP->normal_phi[curr_imageI] - 4.712389;

/* Sine and cosine of this angle: */
sin_angle = sin (angle);
cos_angle = cos (angle);

/* Four rectangle corners before rotation and translation: */
x1 =  curr_planeSP->screen_a;
y1 =  curr_planeSP->screen_b[curr_imageI];
x2 = -curr_planeSP->screen_a;
y2 =  curr_planeSP->screen_b[curr_imageI];
x3 = -curr_planeSP->screen_a;
y3 = -curr_planeSP->screen_b[curr_imageI];
x4 =  curr_planeSP->screen_a;
y4 = -curr_planeSP->screen_b[curr_imageI];

/* Four rectangle corners after rotation and translation: */
x1rot = x1 * cos_angle - y1 * sin_angle + center_screen_x;
y1rot = x1 * sin_angle + y1 * cos_angle + center_screen_y;
x2rot = x2 * cos_angle - y2 * sin_angle + center_screen_x;
y2rot = x2 * sin_angle + y2 * cos_angle + center_screen_y;
x3rot = x3 * cos_angle - y3 * sin_angle + center_screen_x;
y3rot = x3 * sin_angle + y3 * cos_angle + center_screen_y;
x4rot = x4 * cos_angle - y4 * sin_angle + center_screen_x;
y4rot = x4 * sin_angle + y4 * cos_angle + center_screen_y;

/* Find extreme values: */
x_min = x1rot;
if (x2rot < x_min) x_min = x2rot;
if (x3rot < x_min) x_min = x3rot;
if (x4rot < x_min) x_min = x4rot;
x_max = x1rot;
if (x2rot > x_max) x_max = x2rot;
if (x3rot > x_max) x_max = x3rot;
if (x4rot > x_max) x_max = x4rot;
y_min = y1rot;
if (y2rot < y_min) y_min = y2rot;
if (y3rot < y_min) y_min = y3rot;
if (y4rot < y_min) y_min = y4rot;
y_max = y1rot;
if (y2rot > y_max) y_max = y2rot;
if (y3rot > y_max) y_max = y3rot;
if (y4rot > y_max) y_max = y4rot;

/* Check extreme values: */
if (x_min < (double) left_edge)		x_min = left_edge;
if (x_min > (double) right_edge)	x_min = right_edge;
if (x_max < (double) left_edge)		x_max = left_edge;
if (x_max > (double) right_edge)	x_max = right_edge;
if (y_min < (double) configSP->image_screen_y0)
					y_min = configSP->image_screen_y0;
if (y_min > (double) configSP->image_screen_y1)
					y_min = configSP->image_screen_y1;
if (y_max < (double) configSP->image_screen_y0)
					y_max = configSP->image_screen_y0;
if (y_max > (double) configSP->image_screen_y1)
					y_max = configSP->image_screen_y1;

/* Extra check, to avoid overflow: */
if (x_min > (double) INT_MAX / 4) x_min = (double) INT_MAX / 4;
if (x_min < (double) INT_MIN / 4) x_min = (double) INT_MIN / 4;
if (x_max > (double) INT_MAX / 4) x_max = (double) INT_MAX / 4;
if (x_max < (double) INT_MIN / 4) x_max = (double) INT_MIN / 4;
if (y_min > (double) INT_MAX / 4) y_min = (double) INT_MAX / 4;
if (y_min < (double) INT_MIN / 4) y_min = (double) INT_MIN / 4;
if (y_max > (double) INT_MAX / 4) y_max = (double) INT_MAX / 4;
if (y_max < (double) INT_MIN / 4) y_max = (double) INT_MIN / 4;

/* Copy extreme values: */
*screen_x_minP = (int) x_min;
*screen_x_maxP = (int) x_max;
*screen_y_minP = (int) y_min;
*screen_y_maxP = (int) y_max;
}

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