Safe Haskell | Safe-Infered |
---|
WrapAround is a convenience module which helps you perform calculations with points that are supposed to exist on a 2-dimensional, finite, unbounded plane. (Or infinite, bounded plane, depending on who you ask.) On such a plane, space wraps around so that an object travelling vertically or horizontally eventually comes back to the place where it started. This allows you to move objects around on a seamless map. For example, in some video games when an object crosses the bottom of the screen it reappears at the top.
WrapAround represents the points and handles the common calculations properly
so you don't have to bother with the messy math and edge cases. This is done
with two data structures: a WrapMap
, which stores information about the size
of the plane, and a WrapPoint
, which stores information about the location of
the point.
When you need the actual x, y coordinates, use the toCoords
conversion
function.
A WrapPoint is represented internally as a pair of angles, like in a torus. The WrapMap and WrapPoint structures are kept separate because some WrapPoint calculations can be performed without a WrapMap context. Functions typically only need a WrapMap when a WrapPoint must be converted to actual x, y coordinates or vice versa. Typically you do not want perform calculations with WrapPoints that were generated with different WrapMaps, but this is possible and sometimes useful.
If you are grateful for this software, I gladly accept donations!
- data WrapMap
- wrapmap :: Double -> Double -> WrapMap
- data WrapPoint
- wrappoint :: WrapMap -> (Double, Double) -> WrapPoint
- addPoints :: WrapPoint -> WrapPoint -> WrapPoint
- addPoints' :: WrapMap -> WrapPoint -> (Double, Double) -> WrapPoint
- distance :: WrapMap -> WrapPoint -> WrapPoint -> Double
- subtractPoints :: WrapPoint -> WrapPoint -> WrapPoint
- toCoords :: WrapMap -> WrapPoint -> (Double, Double)
- vectorRelation :: WrapMap -> WrapPoint -> WrapPoint -> (Double, Double)
Documentation
Contains the contextual information necessary to convert a WrapPoint to coordinates and vice versa.
A representation of a point location that allows for wrapping in the vertical or horizontal direction.
Generates a WrapPoint
.
:: WrapPoint | The first WrapPoint in the operation |
-> WrapPoint | The WrapPoint to be added to the first WrapPoint |
-> WrapPoint |
Adds two WrapPoints together (vector style).
:: WrapMap | The corresponding WrapMap structure |
-> WrapPoint | The WrapPoint in the operation |
-> (Double, Double) | The x, y coordinates to be added to the WrapPoint |
-> WrapPoint |
Adds a WrapPoint and a pair of x, y coordinates (vector style).
:: WrapMap | The corresponding WrapMap structure |
-> WrapPoint | The first WrapPoint |
-> WrapPoint | The second WrapPoint |
-> Double |
Finds the distance between two WrapPoints.
:: WrapPoint | The first WrapPoint in the operation |
-> WrapPoint | The WrapPoint to be subtracted from the first WrapPoint |
-> WrapPoint |
Subtracts a WrapPoint from a WrapPoint (vector style).
Converts a WrapPoint to x, y coordinates. Generally you will only will only want to use this function for informational purposes, for example, to print out the x, y coordinates or to feed the coordinates to a graphics display function. If you convert a WrapPoint to x, y coordinates so that you can perform calculations with the coordinates, you must handle the wrapping math yourself and you are doing the work the module is supposed to do for you.