wraparound-0.0.1.1: Convenient handling of points on a seamless 2-dimensional plane

Safe HaskellSafe-Infered

Data.WrapAround

Description

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!

https://frigidcode.com/donate/

Synopsis

Documentation

data WrapMap Source

Contains the contextual information necessary to convert a WrapPoint to coordinates and vice versa.

Instances

wrapmapSource

Arguments

:: Double

Width

-> Double

Height

-> WrapMap 

Generates a WrapMap.

data WrapPoint Source

A representation of a point location that allows for wrapping in the vertical or horizontal direction.

Instances

wrappointSource

Arguments

:: WrapMap

Corresponding WrapMap structure

-> (Double, Double)

x, y coordinates

-> WrapPoint 

Generates a WrapPoint.

addPointsSource

Arguments

:: WrapPoint

The first WrapPoint in the operation

-> WrapPoint

The WrapPoint to be added to the first WrapPoint

-> WrapPoint 

Adds two WrapPoints together (vector style).

addPoints'Source

Arguments

:: 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).

distanceSource

Arguments

:: WrapMap

The corresponding WrapMap structure

-> WrapPoint

The first WrapPoint

-> WrapPoint

The second WrapPoint

-> Double 

Finds the distance between two WrapPoints.

subtractPointsSource

Arguments

:: 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).

toCoordsSource

Arguments

:: WrapMap

Corresponding WrapMap structure

-> WrapPoint

WrapPoint to be converted

-> (Double, Double) 

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.

vectorRelationSource

Arguments

:: WrapMap

The corresponding WrapMap structure

-> WrapPoint

The first WrapPoint

-> WrapPoint

The second WrapPoint

-> (Double, Double) 

Returns the relationship between two WrapPoints as a pair of x, y coordinates (a vector).