Skip to content

Transform

lerax.render.Transform

Bases: eqx.Module

Affine mapping from world coords to screen pixels.

Has a constant scale for all axis to avoid distortion.

Attributes:

Name Type Description
width Int[Array, '']

Width of the screen in pixels.

height Int[Array, '']

Height of the screen in pixels.

scale Float[Array, '']

Scale factor from world units to pixels.

offset Float[Array, 2]

Offset to add after scaling.

y_up bool

If True, the y-axis points up in world space.

Parameters:

Name Type Description Default
width Int[ArrayLike, '']

Width of the screen in pixels.

required
height Int[ArrayLike, '']

Height of the screen in pixels.

required
scale Float[ArrayLike, '']

Scale factor from world units to pixels.

required
offset Float[ArrayLike, 2]

Offset to add after scaling.

required
y_up bool

If True, the y-axis points up in world space.

True

width instance-attribute

width: Int[Array, ''] = jnp.asarray(width)

height instance-attribute

height: Int[Array, ''] = jnp.asarray(height)

scale instance-attribute

scale: Float[Array, ''] = jnp.asarray(scale)

offset instance-attribute

offset: Float[Array, 2] = jnp.asarray(offset)

y_up class-attribute instance-attribute

y_up: bool = y_up

__init__

__init__(
    width: Int[ArrayLike, ""],
    height: Int[ArrayLike, ""],
    scale: Float[ArrayLike, ""],
    offset: Float[ArrayLike, 2],
    y_up: bool = True,
)

world_to_px

world_to_px(point: Float[ArrayLike, 2]) -> Int[Array, 2]

Return pixel coordinates corresponding to a point in world space.

Parameters:

Name Type Description Default
point Float[ArrayLike, 2]

A point in world space.

required

Returns:

Type Description
Int[Array, 2]

The corresponding pixel coordinates.

scale_length

scale_length(
    length: Float[ArrayLike, ""],
) -> Float[Array, ""]

Scale a length in world space to pixel space.

Parameters:

Name Type Description Default
length Float[ArrayLike, '']

A length in world space.

required

Returns:

Type Description
Float[Array, '']

The corresponding length in pixel space.