Coord
const coord = require("@vectarine/coord")A module for dealing with coordinate systems and switching between them.
Functions
Section titled “Functions”coord.px
Section titled “coord.px”coord.px( v_or_x: Vec.Vec2 | number, screen_size_px_or_y: number | Vec.Vec2?, screen_size_px_or_nil: Vec.Vec2?,): ScreenPositionConverts a Vec2 in pixels to a ScreenPosition The pixel convention has the origin (0,0) in the upper-left of the screen, with the lower-right at (screen_width-1, screen_height-1) This is the same convention as most other graphics APIs like HTML5 Canvas, Love2d, Processing, Raylib etc…
You can use either coord.px(10, 10) or coord.px(Vec.V2(10, 10)) to make ScreenPosition.
To perform the conversion, this function uses the screen size of the current drawing target (screen or canvas) unless screen_size_px is provided.
coord.pxVec
Section titled “coord.pxVec”coord.pxVec( v_or_x: Vec.Vec2 | number, screen_size_px_or_y: number | Vec.Vec2?, screen_size_px_or_nil: Vec.Vec2?,): ScreenVecConverts a Vec2 in pixels to a ScreenVec The pixel convention has the origin (0,0) in the upper-left of the screen
You can use either coord.pxVec(10, 10) or coord.pxVec(Vec.V2(10, 10)) to make a ScreenVec.
To perform the conversion, this function uses the screen size of the current drawing target (screen or canvas) unless screen_size_px is provided.
coord.gl
Section titled “coord.gl”coord.gl(v_or_x: Vec.Vec2 | number, y_or_nil: number | Vec.Vec2?): ScreenPositionConverts a Vec2 using the OpenGL convention to a ScreenPosition The OpenGL convention has the origin (0,0) in the center of the screen, with the bottom-left at (-1,-1) and the upper-right at (1,1)
coord.glVec
Section titled “coord.glVec”coord.glVec(v_or_x: Vec.Vec2 | number, y_or_nil: number | Vec.Vec2?): ScreenVecConverts a Vec2 using the OpenGL convention to a ScreenVec
coord.vw
Section titled “coord.vw”coord.vw( v_or_x: Vec.Vec2 | number, screen_size_px_or_y: number | Vec.Vec2?, screen_size_px_or_nil: Vec.Vec2?,): ScreenPositioncoord.vwVec
Section titled “coord.vwVec”coord.vwVec( v_or_x: Vec.Vec2 | number, screen_size_px_or_y: number | Vec.Vec2?, screen_size_px_or_nil: Vec.Vec2?,): ScreenVeccoord.vh
Section titled “coord.vh”coord.vh( v_or_x: Vec.Vec2 | number, screen_size_px_or_y: number | Vec.Vec2?, screen_size_px_or_nil: Vec.Vec2?,): ScreenPositioncoord.vhVec
Section titled “coord.vhVec”coord.vhVec( v_or_x: Vec.Vec2 | number, screen_size_px_or_y: number | Vec.Vec2?, screen_size_px_or_nil: Vec.Vec2?,): ScreenVecScreenVec
Section titled “ScreenVec”export type ScreenVec = ...Operators
a + b — (a: ScreenVec, b: ScreenVec): ScreenVec
a - b — (a: ScreenVec, b: ScreenVec): ScreenVec
ScreenVec:gl
Section titled “ScreenVec:gl”ScreenVec:gl(): Vec.Vec2ScreenVec:px
Section titled “ScreenVec:px”ScreenVec:px(): Vec.Vec2Returns the position as a Vec2 in the pixel coordinate system
ScreenVec:scale
Section titled “ScreenVec:scale”ScreenVec:scale(k: number): ScreenVecScreenPosition
Section titled “ScreenPosition”export type ScreenPosition = ...Represents somewhere on the screen. This is essentially a Vec2 with a unit.
You can use px, gl, vh, or vw to create a ScreenPosition from a Vec2 using your preferred coordinate system.
Operators
a + b — (a: ScreenPosition, b: ScreenVec): ScreenPosition
a - b — ((ScreenPosition, ScreenPosition) -> ScreenVec) & ((ScreenPosition, ScreenVec) -> ScreenPosition)
ScreenPosition:gl
Section titled “ScreenPosition:gl”ScreenPosition:gl(): Vec.Vec2Returns the position as a Vec2 in the OpenGL coordinate system
ScreenPosition:px
Section titled “ScreenPosition:px”ScreenPosition:px(screen_size: Vec.Vec2?): Vec.Vec2Returns the position as a Vec2 in the pixel coordinate system
Constants
Section titled “Constants”coord.CENTER
Section titled “coord.CENTER”coord.CENTER = ...coord.TOP_LEFT
Section titled “coord.TOP_LEFT”coord.TOP_LEFT = ...coord.TOP_RIGHT
Section titled “coord.TOP_RIGHT”coord.TOP_RIGHT = ...coord.BOTTOM_LEFT
Section titled “coord.BOTTOM_LEFT”coord.BOTTOM_LEFT = ...coord.BOTTOM_RIGHT
Section titled “coord.BOTTOM_RIGHT”coord.BOTTOM_RIGHT = ...