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

Safe HaskellSafe-Inferred

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.

wmSource

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.

wpSource

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

addSource

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

add'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).

diffSource

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

subtractPoints'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 

Subtracts coordinates from a WrapPoint (vector style).

diff'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 

Subtracts coordinates from a WrapPoint (vector style).

toCoordsSource

Arguments

:: WrapMap

Corresponding WrapMap structure

-> WrapPoint

WrapPoint to be converted

-> (Double, Double) 

Converts a WrapPoint to coordinates.

coordsSource

Arguments

:: WrapMap

Corresponding WrapMap structure

-> WrapPoint

WrapPoint to be converted

-> (Double, Double) 

Converts a WrapPoint to coordinates.

vecSource

Arguments

:: WrapMap

Corresponding WrapMap structure

-> WrapPoint

WrapPoint to be converted

-> (Double, Double) 

Converts a WrapPoint to coordinates.

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

relationSource

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