Coordinate Systems and Transformation Functions
Every snippet placed on the page is positioned using a coordinate system, which includes position and rotation values. The page coordinate system determines where each snippet is rendered. In our system:
- The top left corner has the coordinates (0,0)
- The bottom right corner has the coordinates (1440,2000)
To convert these page coordinates to a device-specific view, we use a homogeneous coordinate transformation denoted as T. This allows us to perform translation, scaling, rotation, and other affine transformations consistently using matrix multiplication i.e. the user can zoom or translate the page with ease.
Let's consider a point on the page XP=(xP,yP,1), which is transformed to XS=(xS,yS,1) using the transformation matrix T
T=ab0cd0txty1Applying the Transformation
The transformed coordinates XS are obtained by multiplying the transformation matrix T with the original coordinates XP:
xSyS1=ab0cd0txty1xPyP1Types of Transformations
-
Translation:
- Moves a point from one location to another.
- Transformation matrix for translation by (tx,ty):
- Scaling:
- Changes the size of the object.
- Transformation matrix for scaling by factors sx and sy:
- Rotation:
- Rotates the object around the origin.
- Transformation matrix for rotation by an angle θ:
- Shearing:
- Skews the object in one direction.
- Transformation matrix for shearing along the x-axis by shx and along the y-axis by shy:
Composite Transformations
Multiple transformations can be combined by multiplying their matrices. The order of multiplication is crucial as matrix multiplication is not commutative.
Tcomposite=Tn⋅Tn−1⋅…⋅T1By applying these transformations, we can accurately position and orient snippets on the page, ensuring that they appear correctly on different devices.
Build in functions
All of the transform logic is handled in the ViewPort
class. The built-in functions, setZoom
, fitPage
, centerPage
and translatePage
, provide essential controls for rendering and viewing the page content dynamically. Additionally the viewport holds functions to convert positions from view to page coordinates and the other way around. They ensure that users can interact with the page intuitively, whether they need to zoom in for detailed scrutiny or fit the entire page within their viewport for an overview.
As a note the page coordinates are in theory also not fixed and changeable, this is not tested tho but could be used to create bigger pages.
Regarding zoom
Zoom levels are not fixed globally but rather a relative value based on the current viewport height vh and the page height ph. Any zoom z that is applied is multiplied by the ratio between the view and page to obtain the scaling factors a and d of the transform T.
a=d=phvh⋅zFurther to allow users to zoom using their current mouse position as origin point we translate to an origin point before and after applying the zoom scaling.