20. Posn Util

Utility functions for posns. Accessing functions defined in other files.

The functions in 20.5 are all useful later. When you do them, you should save them in a file called posn-util.rkt. (Please use that name.)

The following functions should be in posn-util.rkt:

  • posn=?: posn posn -> boolean. Are both positions exactly the same? (Both corresponding coordinates match.)
  • posn-add: posn posn -> posn. Add corresponding coordinates.
  • posn-sub: posn posn -> posn. Subtract corresponding coordinates. First minus second.
  • posn-scale: number posn -> posn. Multiply both coordinates by the same number.
  • posn-distance: posn posn -> number. The distance in the plane between the points specified by the two posns.
  • place-image/posn: image posn image(background) -> image. Purpose: Place one image at a given set of coordinates on a given background.
  • Anything else you want to have available for re-use. (Maybe from physics or trig…)

You should write tests for yourself. You are going to use these functions for a month, so you do not want any mistakes. If you really need them, you can see some tests I wrote.

Last modified August 18, 2023: 2022-2023 End State (7352e87)