addpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. .TH ADDPT 2
  2. .SH NAME
  3. 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
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .br
  9. .B #include <draw.h>
  10. .PP
  11. .B
  12. Point addpt(Point p, Point q)
  13. .PP
  14. .B
  15. Point subpt(Point p, Point q)
  16. .PP
  17. .B
  18. Point mulpt(Point p, int a)
  19. .PP
  20. .B
  21. Point divpt(Point p, int a)
  22. .PP
  23. .B
  24. Rectangle rectaddpt(Rectangle r, Point p)
  25. .PP
  26. .B
  27. Rectangle rectsubpt(Rectangle r, Point p)
  28. .PP
  29. .B
  30. Rectangle insetrect(Rectangle r, int n)
  31. .PP
  32. .B
  33. Rectangle canonrect(Rectangle r)
  34. .PP
  35. .B
  36. int eqpt(Point p, Point q)
  37. .PP
  38. .B
  39. int eqrect(Rectangle r, Rectangle s)
  40. .PP
  41. .B
  42. int ptinrect(Point p, Rectangle r)
  43. .PP
  44. .B
  45. int rectinrect(Rectangle r, Rectangle s)
  46. .PP
  47. .B
  48. int rectXrect(Rectangle r, Rectangle s)
  49. .PP
  50. .B
  51. int rectclip(Rectangle *rp, Rectangle b)
  52. .PP
  53. .B
  54. void combinerect(Rectangle *rp, Rectangle b)
  55. .PP
  56. .B
  57. int Dx(Rectangle r)
  58. .PP
  59. .B
  60. int Dy(Rectangle r)
  61. .PP
  62. .B
  63. Point Pt(int x, int y)
  64. .PP
  65. .B
  66. Rectangle Rect(int x0, int y0, int x1, int y1)
  67. .PP
  68. .B
  69. Rectangle Rpt(Point p, Point q)
  70. .SH DESCRIPTION
  71. The functions
  72. .IR Pt ,
  73. .I Rect
  74. and
  75. .I Rpt
  76. construct geometrical data types from their components.
  77. .PP
  78. .I Addpt
  79. returns the Point
  80. sum of its arguments:
  81. .BI Pt( p .x+ q .x,
  82. .IB p .y+ q .y) \f1.
  83. .I Subpt
  84. returns the Point
  85. difference of its arguments:
  86. .BI Pt( p .x- q .x,
  87. .IB p .y- q .y) \f1.
  88. .I Mulpt
  89. returns the Point
  90. .BI Pt( p .x* a ,
  91. .IB p .y* a ) \f1.
  92. .I Divpt
  93. returns the Point
  94. .BI Pt( p .x/ a ,
  95. .IB p .y/ a ) \f1.
  96. .PP
  97. .I Rectaddpt
  98. returns the Rectangle
  99. .BI Rect(add( r .min,
  100. .IB p ) \f1,
  101. .BI add( r .max,
  102. .IB p )) \f1;
  103. .I rectsubpt
  104. returns the Rectangle
  105. .BI Rpt(sub( r .min,
  106. .IB p ),
  107. .BI sub( r .max,
  108. .IB p ))\fR.
  109. .PP
  110. .I Insetrect
  111. returns the Rectangle
  112. .BI Rect( r .min.x+ n \f1,
  113. .IB r .min.y+ n \f1,
  114. .IB r .max.x- n \f1,
  115. .IB r .max.y- n ) \f1.
  116. .PP
  117. .I Canonrect
  118. returns a rectangle with the same extent as
  119. .IR r ,
  120. canonicalized so that
  121. .B min.x
  122. .BR max.x ,
  123. and
  124. .B min.y
  125. .BR max.y .
  126. .PP
  127. .I Eqpt
  128. compares its argument Points and returns
  129. 0 if unequal,
  130. 1 if equal.
  131. .I Eqrect
  132. does the same for its argument Rectangles.
  133. .PP
  134. .I Ptinrect
  135. returns 1 if
  136. .I p
  137. is a point within
  138. .IR r ,
  139. and 0 otherwise.
  140. .PP
  141. .I Rectinrect
  142. returns 1 if all the pixels in
  143. .I r
  144. are also in
  145. .IR s ,
  146. and 0 otherwise.
  147. .PP
  148. .I RectXrect
  149. returns 1 if
  150. .I r
  151. and
  152. .I s
  153. share any point, and 0 otherwise.
  154. .PP
  155. .I Rectclip
  156. clips in place
  157. the Rectangle pointed to by
  158. .I rp
  159. so that it is completely contained within
  160. .IR b .
  161. The return value is 1 if any part of
  162. .RI * rp
  163. is within
  164. .IR b .
  165. Otherwise, the return value is 0 and
  166. .RI * rp
  167. is unchanged.
  168. .PP
  169. .I Combinerect
  170. overwrites
  171. .B *rp
  172. with the smallest rectangle sufficient to cover all the pixels of
  173. .B *rp
  174. and
  175. .BR b .
  176. .PP
  177. The functions
  178. .I Dx
  179. and
  180. .I Dy
  181. give the width (Δx) and height (Δy) of a Rectangle.
  182. They are implemented as macros.
  183. .SH SOURCE
  184. .B /sys/src/libdraw
  185. .SH SEE ALSO
  186. .IR graphics (2)