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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
.TH ADDPT 3
.SH NAME
addpt, subpt, mulpt, divpt, rectaddpt, rectsubpt, insetrect, canonrect, eqpt, eqrect, ptinrect, rectinrect, rectXrect, rectclip, combinerect, Dx, Dy, Pt, Rect, Rpt \- arithmetic on points and rectangles
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.br
.B #include <draw.h>
.PP
.B
Point addpt(Point p, Point q)
.PP
.B
Point subpt(Point p, Point q)
.PP
.B
Point mulpt(Point p, int a)
.PP
.B
Point divpt(Point p, int a)
.PP
.B
Rectangle rectaddpt(Rectangle r, Point p)
.PP
.B
Rectangle rectsubpt(Rectangle r, Point p)
.PP
.B
Rectangle insetrect(Rectangle r, int n)
.PP
.B
Rectangle canonrect(Rectangle r)
.PP
.B
int eqpt(Point p, Point q)
.PP
.B
int eqrect(Rectangle r, Rectangle s)
.PP
.B
int ptinrect(Point p, Rectangle r)
.PP
.B
int rectinrect(Rectangle r, Rectangle s)
.PP
.B
int rectXrect(Rectangle r, Rectangle s)
.PP
.B
int rectclip(Rectangle *rp, Rectangle b)
.PP
.B
void combinerect(Rectangle *rp, Rectangle b)
.PP
.B
int Dx(Rectangle r)
.PP
.B
int Dy(Rectangle r)
.PP
.B
Point Pt(int x, int y)
.PP
.B
Rectangle Rect(int x0, int y0, int x1, int y1)
.PP
.B
Rectangle Rpt(Point p, Point q)
.SH DESCRIPTION
The functions
.IR Pt ,
.I Rect
and
.I Rpt
construct geometrical data types from their components.
.PP
.I Addpt
returns the Point
sum of its arguments:
.BI Pt( p .x+ q .x,
.IB p .y+ q .y) \f1.
.I Subpt
returns the Point
difference of its arguments:
.BI Pt( p .x- q .x,
.IB p .y- q .y) \f1.
.I Mulpt
returns the Point
.BI Pt( p .x* a ,
.IB p .y* a ) \f1.
.I Divpt
returns the Point
.BI Pt( p .x/ a ,
.IB p .y/ a ) \f1.
.PP
.I Rectaddpt
returns the Rectangle
.BI Rect(add( r .min,
.IB p ) \f1,
.BI add( r .max,
.IB p )) \f1;
.I rectsubpt
returns the Rectangle
.BI Rpt(sub( r .min,
.IB p ),
.BI sub( r .max,
.IB p ))\fR.
.PP
.I Insetrect
returns the Rectangle
.BI Rect( r .min.x+ n \f1,
.IB r .min.y+ n \f1,
.IB r .max.x- n \f1,
.IB r .max.y- n ) \f1.
.PP
.I Canonrect
returns a rectangle with the same extent as
.IR r ,
canonicalized so that
.B min.x
≤
.BR max.x ,
and
.B min.y
≤
.BR max.y .
.PP
.I Eqpt
compares its argument Points and returns
0 if unequal,
1 if equal.
.I Eqrect
does the same for its argument Rectangles.
.PP
.I Ptinrect
returns 1 if
.I p
is a point within
.IR r ,
and 0 otherwise.
.PP
.I Rectinrect
returns 1 if all the pixels in
.I r
are also in
.IR s ,
and 0 otherwise.
.PP
.I RectXrect
returns 1 if
.I r
and
.I s
share any point, and 0 otherwise.
.PP
.I Rectclip
clips in place
the Rectangle pointed to by
.I rp
so that it is completely contained within
.IR b .
The return value is 1 if any part of
.RI * rp
is within
.IR b .
Otherwise, the return value is 0 and
.RI * rp
is unchanged.
.PP
.I Combinerect
overwrites
.B *rp
with the smallest rectangle sufficient to cover all the pixels of
.B *rp
and
.BR b .
.PP
The functions
.I Dx
and
.I Dy
give the width (Δx) and height (Δy) of a Rectangle.
They are implemented as macros.
.SH SOURCE
.B \*9/src/libdraw
.SH SEE ALSO
.MR graphics (3)
|