@deprecated, see readme
Construct a Xy from first the x, the the y coordinate.
Construct a Xy from the same value for the x & y coordinates.
Xy.both 0 --> ( 0, 0 )Construct a Xy where the x & y coordinates are 0.
Xy.zero --> ( 0, 0 )Construct a Xy where the x & y coordinates are 1.
Xy.one --> ( 1, 1 )Express the angle as a unit vector.
Xy.direction (turns (1/6))
--> ( 0.5000000000000001, 0.8660254037844386 )
fromLengthAndRotation length rotation =
Xy.direction rotation
>> Xy.map ((*) length)Construct a Xy from the x and y fields contained in a record.
initialPosition : Xy Float
initialPosition =
Browser.getViewport
|> Task.perform (.viewport >> Xy.fromXY)Construct a Xy from the width and height fields contained in a record.
initialSize : Xy Float
initialSize =
Browser.getViewport
|> Task.perform (.viewport >> Xy.fromSize)The x coordinate.
( 3, 5 ) |> Xy.x --> 3The y coordinate.
( 3, 5 ) |> Xy.y --> 5The length of the hypotenuse
^
y|\
| \ length
| \
0--->
xUpdate the x coordinate based on its current value.
flipX =
XY.mapX (\x -> -x)Update the y coordinate based on its current value.
flipY =
XY.mapY (\y -> -y)Apply the same function to both coordinates.
( 4.567, 4.321 ) |> Xy.map round
--> ( 5, 4 ) : Xy Int
opposite =
Xy.map (\coord -> -coord)
scale factor =
Xy.map ((*) factor)Apply a different function to the x & y coordinate.
( 4.567, 4.321 ) |> Xy.mapXY floor ceiling
--> ( 4, 5 ) : Xy IntApply a function combining the x & y coordinates of 2 Xys.
Xy.map2 (\a b -> a - b) ( 10, 5 ) ( 5, 1 )
--> ( 5, 4 )
Xy.map2 (+) ( 10, 5 ) ( 5, 1 )
--> ( 15, 6 )The angle (in radians).
^
/|y
/ |
/⍺ |
0--->
xXy.toAngle ( 1, 1 ) --> pi/4 radians or 45°
Xy.toAngle ( -1, 1 ) --> 3*pi/4 radians or 135°
Xy.toAngle ( -1, -1 ) --> -3*pi/4 radians or 225°
Xy.toAngle ( 1, -1 ) --> -pi/4 radians or 315°Use the x and the y coordinate to return a result.
( 3, 4 ) |> Xy.to max --> 4Convert to a unit vector.
( 3, 4 ) |> Xy.normalize
--> ( 3/5, 4/5 )A Codec to serialize Xys.
serializePoint : Serialize.Codec error (Xy Int)
serializePoint =
Xy.serialize Serialize.intA Generator for random Xys.
randomSpeed =
Xy.random (XY.both (Random.float -1 1))
randomPoint =
Xy.random
( Random.float left right
, Random.float bottom top
)
A tuple, containing 2 coordinates of the same type.