forked from smcameron/space-nerds-in-space
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liang-barsky.h
56 lines (46 loc) · 1.85 KB
/
liang-barsky.h
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
#ifndef LIANG_BARSKY_H__
#define LIANG_BARSKY_H__
/*
Copyright (C) 2013 Hin Jang, Stephen M. Cameron
This file is part of Spacenerds In Space.
Spacenerds in Space is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Spacenerds in Space is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Spacenerds in Space; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Liang-Barsky clipping algorithm.
* Adapted from Hin Jang's C++ implementation found here:
* http://hinjang.com/articles/04.html#eight
*/
#ifdef DEFINE_LIANG_BARSKY_GLOBALS
#define GLOBAL
#else
#define GLOBAL extern
#endif
struct liang_barsky_clip_window {
float x1, y1, x2, y2;
};
/* clip_line()
* modifies parameters in place to clip the line,
* returns 0 if line is totally outside clip window
* returns 1 if line is not totally outside clip window
*/
GLOBAL int clip_line(struct liang_barsky_clip_window *c,
int *x1, int *y1, int *x2, int *y2);
/* clip_line_copy()
* first four params are input line coords
* last four params are clipped output line coords
* returns 0 if line is totally outside clip window
* returns 1 if line is not totally outside clip window
*/
GLOBAL int clip_line_copy(struct liang_barsky_clip_window *c,
int x1, int y1, int x2, int y2,
int *ox1, int *oy1, int *ox2, int *oy2);
#endif