vector.sl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. % {DSK}VECTOR.PSL;1 4-MAR-83 16:25:56
  2. (GLISPOBJECTS
  3. (DEGREES REAL
  4. PROP ((RADIANS (self* (3.1415926/180.0))
  5. RESULT RADIANS)
  6. (DISPLAYPROPS (T))))
  7. (GRAPHICSOBJECT (LIST (SHAPE ATOM)
  8. (START VECTOR)
  9. (SIZE VECTOR))
  10. PROP ((LEFT (START:X))
  11. (BOTTOM (START:Y))
  12. (RIGHT (LEFT+WIDTH))
  13. (TOP (BOTTOM+HEIGHT))
  14. (WIDTH (SIZE:X))
  15. (HEIGHT (SIZE:Y))
  16. (CENTER (START+SIZE/2))
  17. (AREA (WIDTH*HEIGHT)))
  18. MSG ((DRAW ((APPLY* (GETPROP SHAPE 'DRAWFN)
  19. self
  20. 'PAINT)))
  21. (ERASE ((APPLY* (GETPROP SHAPE 'DRAWFN)
  22. self
  23. 'ERASE)))
  24. (MOVE GRAPHICSOBJECTMOVE OPEN T)))
  25. (RADIANS REAL
  26. PROP ((DEGREES (self* (180.0/3.1415926))
  27. RESULT DEGREES)
  28. (DISPLAYPROPS (T))))
  29. (REGION (LIST (START VECTOR)
  30. (SIZE VECTOR))
  31. PROP ((LEFT (START:X))
  32. (BOTTOM (START:Y))
  33. (RIGHT (LEFT+WIDTH))
  34. (TOP (BOTTOM+HEIGHT))
  35. (WIDTH (SIZE:X))
  36. (HEIGHT (SIZE:Y))
  37. (CENTER (START+SIZE/2))
  38. (TOPCENTER ((A VECTOR WITH X = LEFT+WIDTH/2 Y = TOP)))
  39. (BOTTOMCENTER ((A VECTOR WITH X = LEFT+WIDTH/2 Y = BOTTOM)))
  40. (AREA (WIDTH*HEIGHT)))
  41. ADJ ((EMPTY (WIDTH IS ZERO OR HEIGHT IS ZERO))
  42. (ZERO (self IS EMPTY)))
  43. MSG ((CONTAINS? REGION-CONTAINS OPEN T)
  44. (SETPOSITION REGION-SETPOSITION OPEN T)
  45. (CENTEROFFSET REGION-CENTEROFFSET OPEN T)))
  46. (RVECTOR (LIST (X REAL)
  47. (Y REAL))
  48. SUPERS (VECTOR))
  49. (SYMMETRY INTEGER
  50. PROP ((SWAPXY ((LOGAND self 4)
  51. <>0))
  52. (INVERTY ((LOGAND self 2)
  53. <>0))
  54. (INVERTX ((LOGAND self 1)
  55. <>0))))
  56. (VECTOR (LIST (X INTEGER)
  57. (Y INTEGER))
  58. PROP ((MAGNITUDE ((SQRT X^2 + Y^2)))
  59. (IMAGNITUDE ((FIX MAGNITUDE + .9999)))
  60. (ANGLE ((ARCTAN2 Y X T))
  61. RESULT RADIANS)
  62. (UNITVECTOR ((A RVECTOR WITH X = X/MAGNITUDE Y = Y/MAGNITUDE))))
  63. ADJ ((ZERO (X IS ZERO AND Y IS ZERO))
  64. (NORMALIZED (MAGNITUDE = 1.0)))
  65. MSG ((+ VECTORPLUS OPEN T ARGTYPES (VECTOR))
  66. (- VECTORDIFF OPEN T ARGTYPES (VECTOR))
  67. (* VECTORTIMES OPEN T ARGTYPES (NUMBER))
  68. (* VECTORDOTPRODUCT OPEN T ARGTYPES (VECTOR))
  69. (/ VECTORQUOTIENT OPEN T ARGTYPES (NUMBER))
  70. (> VECTORGREATERP OPEN T ARGTYPES (VECTOR))
  71. (<= VECTORLEQP OPEN T ARGTYPES (VECTOR))
  72. (_+ VECTORMOVE OPEN T ARGTYPES (VECTOR))
  73. (PRIN1 ((PRIN1 "(")
  74. (PRIN1 X)
  75. (PRIN1 ",")
  76. (PRIN1 Y)
  77. (PRIN1 ")")))
  78. (PRINT ((_ self PRIN1)
  79. (TERPRI)))))
  80. )
  81. % edited: 11-JAN-82 12:40
  82. (DG DRAWRECT ((A GRAPHICSOBJECT)
  83. DSPOP:ATOM)
  84. (PROG (OLDDS)
  85. (OLDDS _ (CURRENTDISPLAYSTREAM DSPS))
  86. (DSPOPERATION DSPOP)
  87. (MOVETO LEFT BOTTOM)
  88. (DRAWTO LEFT TOP)
  89. (DRAWTO RIGHT TOP)
  90. (DRAWTO RIGHT BOTTOM)
  91. (DRAWTO LEFT BOTTOM)
  92. (CURRENTDISPLAYSTREAM OLDDS)))
  93. % edited: 11-JAN-82 16:07
  94. (DG GRAPHICSOBJECTMOVE (self:GRAPHICSOBJECT DELTA:VECTOR)
  95. (_ self ERASE)(START _+ DELTA)(_ self DRAW))
  96. % GSN 30-JAN-83 15:44
  97. % Transform the starting point of an object as appropriate for the
  98. % specified symmetry transform.
  99. (DG NEWSTART (START:VECTOR SIZE:VECTOR SYM:SYMMETRY)
  100. (PROG (W H TMP)
  101. (W_SIZE:X)
  102. (H_SIZE:Y)
  103. (IF SYM:SWAPXY THEN TMP_W W_H H_TMP)
  104. (IF ~SYM:INVERTY THEN H_0)
  105. (IF ~SYM:INVERTX THEN W_0)
  106. (RETURN (A (TYPEOF START)
  107. WITH X = START:X+W Y = START:Y+H))))
  108. % GSN 30-JAN-83 15:44
  109. % Transform a given relative POINT for specified symmetry transform.
  110. (DG NEWPOINT (START:VECTOR POINT:VECTOR SYM:SYMMETRY)
  111. (PROG (W H TMP)
  112. (W_POINT:X)
  113. (H_POINT:Y)
  114. (IF SYM:SWAPXY THEN TMP_W W_H H_TMP)
  115. (IF ~SYM:INVERTY THEN H _ - H)
  116. (IF ~SYM:INVERTX THEN W _ - W)
  117. (RETURN (A (TYPEOF POINT)
  118. WITH X = START:X+W Y = START:Y+H))))
  119. % GSN 2-FEB-83 14:00
  120. (DG REGION-CENTEROFFSET (R:REGION V:VECTOR)
  121. (A (TYPEOF V)
  122. WITH X = (R:WIDTH - V:X)
  123. /2 Y = (R:HEIGHT - V:Y)
  124. /2))
  125. % edited: 26-OCT-82 11:45
  126. % Test whether an area contains a point P.
  127. (DG REGION-CONTAINS (AREA P)
  128. (P:X>=AREA:LEFT AND P:X<=AREA:RIGHT AND P:Y>=AREA:BOTTOM AND P:Y<=AREA:TOP))
  129. % GSN 28-FEB-83 16:03
  130. (DG REGION-INTERSECT (P:AREA Q:AREA)
  131. (RESULT (TYPEOF P))
  132. % Produce an AREA which is the intersection of two given AREAs.
  133. (PROG (NEWBOTTOM NEWLEFT NEWAREA XSIZE YSIZE)
  134. (NEWBOTTOM _ (IMAX P:BOTTOM Q:BOTTOM))
  135. (YSIZE _ (IMIN P:TOP Q:TOP)
  136. - NEWBOTTOM)
  137. (NEWLEFT _ (IMAX P:LEFT Q:LEFT))
  138. (XSIZE _ (IMIN P:RIGHT Q:RIGHT)
  139. - NEWLEFT)
  140. (NEWAREA _ (A (TYPEOF P)))
  141. (IF XSIZE>0 AND YSIZE>0 THEN NEWAREA:LEFT_NEWLEFT
  142. NEWAREA:BOTTOM_NEWBOTTOM NEWAREA:WIDTH_XSIZE NEWAREA:HEIGHT_YSIZE)
  143. (RETURN NEWAREA)))
  144. % GSN 14-JAN-83 11:52
  145. % Change the START point of AREA so that the position APOS relative to
  146. % the area will have the position NEWPOS.
  147. (DG REGION-SETPOSITION (AREA APOS:VECTOR NEWPOS:VECTOR)
  148. (AREA:START _+ NEWPOS - APOS))
  149. % GSN 28-FEB-83 16:04
  150. (DG REGION-UNION (P:AREA Q:AREA)
  151. (RESULT (TYPEOF P))
  152. % Produce an AREA which is the union of two given AREAs.
  153. (PROG (NEWBOTTOM NEWLEFT XSIZE YSIZE NEWAREA)
  154. (NEWBOTTOM _ (IMIN P:BOTTOM Q:BOTTOM))
  155. (YSIZE _ (IMAX P:TOP Q:TOP)
  156. - NEWBOTTOM)
  157. (NEWLEFT _ (IMIN P:LEFT Q:LEFT))
  158. (XSIZE _ (IMAX P:RIGHT Q:RIGHT)
  159. - NEWLEFT)
  160. (NEWAREA _ (A (TYPEOF P)))
  161. (NEWAREA:LEFT_NEWLEFT)
  162. (NEWAREA:BOTTOM_NEWBOTTOM)
  163. (NEWAREA:WIDTH_XSIZE)
  164. (NEWAREA:HEIGHT_YSIZE)
  165. (RETURN NEWAREA)))
  166. % GSN 10-FEB-83 13:41
  167. (DG VECTORPLUS (V1:VECTOR V2:VECTOR)
  168. (A (TYPEOF V1)
  169. WITH X = V1:X + V2:X Y = V1:Y + V2:Y))
  170. % GSN 10-FEB-83 13:41
  171. (DG VECTORDIFF (V1:VECTOR V2:VECTOR)
  172. (A (TYPEOF V1)
  173. WITH X = V1:X - V2:X Y = V1:Y - V2:Y))
  174. % GSN 10-FEB-83 13:42
  175. (DG VECTORDOTPRODUCT (V1:VECTOR V2:VECTOR)
  176. (A (TYPEOF V1)
  177. WITH X = V1:X * V2:X Y = V1:Y * V2:Y))
  178. % GSN 14-JAN-83 12:33
  179. % This version of > tests whether one box will fit inside the other.
  180. (DG VECTORGREATERP (U:VECTOR V:VECTOR)
  181. (U:X>V:X OR U:Y>V:Y))
  182. % GSN 14-JAN-83 12:31
  183. (DG VECTORLEQP (U:VECTOR V:VECTOR)
  184. (U:X<=V:X AND U:Y<=V:Y))
  185. % GSN 10-FEB-83 13:41
  186. (DG VECTORTIMES (V:VECTOR N:NUMBER)
  187. (A (TYPEOF V)
  188. WITH X = X*N Y = Y*N))
  189. % GSN 10-FEB-83 13:42
  190. (DG VECTORQUOTIENT (V:VECTOR N:NUMBER)
  191. (A (TYPEOF V)
  192. WITH X = X/N Y = Y/N))
  193. % GSN 10-FEB-83 13:43
  194. (DG VECTORMOVE (V:VECTOR DELTA:VECTOR)
  195. (V:X _+ DELTA:X)(V:Y _+ DELTA:Y)V)
  196. (PUT 'RECTANGLE
  197. 'DRAWFN
  198. 'DRAWRECT)