File: add.3

package info (click to toggle)
9term 1.6.6-5
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 2,340 kB
  • ctags: 2,035
  • sloc: ansic: 17,308; makefile: 220; sh: 178
file content (238 lines) | stat: -rw-r--r-- 3,758 bytes parent folder | download | duplicates (17)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
.de F
.B
.if !"\\$1"" \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6
..
.de L
.B
.if !"\\$1"" \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6
..
.de FR
.BR "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.de LR
.BR "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.de CW
.ft B
..
.\" This is gross but it avoids relying on internal implementation details
.\" of the -man macros.
.de TF
.IP "" \w'\fB\\$1\ \ \fP'u
.PD0
..
.de EX
.CW
.nf
..
.de EE
.fi
..
.\" delete above this point if your system has F, L, FR, LR, CW and TF macros
.TH ADD 3G
.SH NAME
add, sub, mul, divpt, raddp, rsubp, rmul, rdiv, rshift, inset, rcanon, eqpt, eqrect, ptinrect, rectinrect, rectXrect, rectclip, Dx, Dy, Pt, Rect, Rpt \- arithmetic on points and rectangles
.SH SYNOPSIS
.nf
.B
#include <libc.h>
.B
#include <libg.h>
.PP
.B
.ta 12n +12n +12n +12n +12n
Point	add(Point p, Point q)
.PP
.B
Point	sub(Point p, Point q)
.PP
.B
Point	mul(Point p, int a)
.PP
.B
Point	divpt(Point p, int a)
.PP
.B
Rectangle	raddp(Rectangle r, Point p)
.PP
.B
Rectangle	rsubp(Rectangle r, Point p)
.PP
.B
Rectangle	rmul(Rectangle r, int a)
.PP
.B
Rectangle	rdiv(Rectangle r, int a)
.PP
.B
Rectangle	rshift(Rectangle r, int a)
.PP
.B
Rectangle	inset(Rectangle r, int n)
.PP
.B
Rectangle	rcanon(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
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)
.fi
.SH DESCRIPTION
The functions
.IR Pt ,
.I Rect
and
.I Rpt
construct geometrical data types from their components.
These are implemented as functions.  (Under Plan 9
these are implemented as macros.)
.PP
.I Add
returns the Point
sum of its arguments:
.BI Pt( p .x+ q .x,
.IB p .y+ q .y).
.I Sub
returns the Point
difference of its arguments:
.BI Pt( p .x- q .x,
.IB p .y- q .y).
.I Mul
returns the Point
.BI Pt( p .x* a ,
.IB p .y* a ).
.I Divpt
returns the Point
.BI Pt( p .x/ a ,
.IB p .y/ a ).
.PP
.I Raddp
returns the Rectangle
.BI Rect(add( r .min,
.IB p ),
.BI add( r .max,
.IB p ))\fR;
.I rsubp
returns the Rectangle
.BI Rpt(sub( r .min,
.IB p ),
.BI sub( r .max,
.IB p ))\fR.
.I Rmul
returns the Rectangle
.BI Rpt(mul( r .min, a ),
.BI mul( r .max, a ))\fR;
.I Rdiv
returns the Rectangle
.BI Rpt(div( r .min, a ),
.BI div( r .max, a ))\fR.
.PP
.I Rshift
returns the rectangle
.I r
with all coordinates either left-shifted or right-shifted by
.IR a ,
depending on whether
.I a
is positive or negative, respectively.
.PP
.I Inset
returns the Rectangle
.BI Rect( r .min.x+ n ,
.IB r .min.y+ n ,
.IB r .max.x- n ,
.IB r .max.y- n ) .
.PP
.I Rcanon
returns a rectangle with the same extent as
.IR r ,
canonicalized so that
.B min.x
.if t \(<=
.if n <=
.BR max.x ,
and
.B min.y
.if t \(<=
.if n <=
.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
The functions
.I Dx
and
.I Dy
give the width (delta x) and height (delta y) of a Rectangle.
They are implemented as macros.
.SH SEE ALSO
.IR graphics (3).