Module

Gesso.Geometry.Scaler

Package
purescript-gesso
Repository
smilack/purescript-gesso

#(*~>) Source

Operator alias for Gesso.Geometry.Scaler.to (non-associative / precedence 2)

Convert an arbitrary record to the coordinate system of a Scaler:

line' = { x1: 0.0, y1: 0.0, x2: 1.0, y2: 1.0 } *~> canvas
circle' = { x: 0.0, y: 0.0, r: 1.0 } *~> canvas

#(-~>) Source

Operator alias for Gesso.Geometry.Scaler.xTo (non-associative / precedence 2)

Convert a single x value to the coordinate system of a Scaler:

x' = x -~> canvas

#(/~>) Source

Operator alias for Gesso.Geometry.Scaler.lengthTo (non-associative / precedence 2)

Convert a single length value to the coordinate system of a Scaler:

l' = l /~> canvas

#(<~*) Source

Operator alias for Gesso.Geometry.Scaler.from (non-associative / precedence 2)

to with arguments flipped:

line' = canvas <~* { x1: 0.0, y1: 0.0, x2: 1.0, y2: 1.0 }
circle' = canvas <~* { x: 0.0, y: 0.0, r: 1.0 }

#(<~-) Source

Operator alias for Gesso.Geometry.Scaler.xFrom (non-associative / precedence 2)

xTo with arguments flipped:

x' = canvas <~- x

#(<~/) Source

Operator alias for Gesso.Geometry.Scaler.lengthFrom (non-associative / precedence 2)

lengthTo with arguments flipped:

l' = canvas <~/ l

#(<~|) Source

Operator alias for Gesso.Geometry.Scaler.yFrom (non-associative / precedence 2)

yTo with arguments flipped:

y' = canvas <~| y

#(|~>) Source

Operator alias for Gesso.Geometry.Scaler.yTo (non-associative / precedence 2)

Convert a single y value to the coordinate system of a Scaler:

y' = y |~> canvas

#Scaler Source

type Scaler = Record (Rectangular Number) + (rect :: Rect, scaling :: { all :: forall rl r. RowToList r rl => Scalable rl r Number => Record r -> Builder (Record ()) (Record r) | ScalingFunctions })

Data and functions for working with a coordinate system:

The x, y, width, and height fields are the origin and size of the system. The rect field contains all of them as well - sometimes it's easier to access them indiviually, and sometimes it's easier to access them as a complete Rect.

scaling contains functions to scale x, y, length, and entire records, but they're more convenient to use with the to and from functions rather than being called directly:

-- this:
{ x: 1.0, y: 2.0 } `to` canvas

-- not:
canvas.scaling.all { x: 1.0, y: 2.0 }

#ScalingFunctions Source

type ScalingFunctions :: Row Typetype ScalingFunctions = (Position (Number -> Number)) + (length :: Number -> Number)

x, y, and length Number -> Number functions for converting between coordinate systems.

#Scalable Source

class Scalable :: RowList Type -> Row Type -> Type -> Constraintclass (RowToList r rl) <= Scalable rl r a | rl -> r where

Typeclass for an arbitrary record. scale walks through the fields of a record, and if any value :: a, checks if the map has a function with the same key. If so, applies the function to the value.

Members

Instances

#from Source

from :: forall rl r. RowToList r rl => Scalable rl r Number => Scaler -> Record r -> Record r

to with arguments flipped:

line' = canvas `from` { x1: 0.0, y1: 0.0, x2: 1.0, y2: 1.0 }
circle' = canvas `from` { x: 0.0, y: 0.0, r: 1.0 }

#lengthFrom Source

lengthFrom :: Scaler -> Number -> Number

lengthTo with arguments flipped:

l' = canvas `lengthFrom` l

#lengthTo Source

lengthTo :: Number -> Scaler -> Number

Convert a single length value to the coordinate system of a Scaler:

l' = l `lengthTo` canvas

#mkScaler Source

mkScaler :: Rect -> Record ScalingFunctions -> Scaler

Create a Scaler record for a coordinate system using its dimensions and x, y, and length scaling functions.

#to Source

to :: forall rl r. RowToList r rl => Scalable rl r Number => Record r -> Scaler -> Record r

Convert fields in an arbitrary record to the coordinate system of a Scaler. If any of these fields is found and has type Number, it will be converted:

  • x fields: x, x1, x2
  • y fields: y, y1, y2
  • length fields: width, w, height, h, radius, r, length, len, l
line' = { x1: 0.0, y1: 0.0, x2: 1.0, y2: 1.0 } `to` canvas
circle' = { x: 0.0, y: 0.0, r: 1.0 } `to` canvas

#xFrom Source

xFrom :: Scaler -> Number -> Number

xTo with arguments flipped:

x' = canvas `xFrom` x

#xTo Source

xTo :: Number -> Scaler -> Number

Convert a single x value to the coordinate system of a Scaler:

x' = x `xTo` canvas

#yFrom Source

yFrom :: Scaler -> Number -> Number

yTo with arguments flipped:

y' = canvas `yFrom` y

#yTo Source

yTo :: Number -> Scaler -> Number

Convert a single y value to the coordinate system of a Scaler:

y' = y `yTo` canvas