PixelGrid
final class PixelGrid
Package: dev.joid.lib.bridge.render.matrix · Module: core · Source: PixelGrid.java
Maps design pixels onto the screen pixels of the current projection, model-view and viewport, and snaps edges, sizes and motions onto whole pixels.
Description
Section titled “Description”A PixelGrid is a snapshot of how the current matrices place a design pixel on the target.
getPixelGrid() of the render bridge computes it on each call; the drawing code, the resources and the shader passes read it to put every edge on a pixel boundary, so a line of one pixel stays one sharp pixel at any interface scale.
Screen coordinates are pixels of the viewport with the origin at the bottom-left corner, as in OpenGL: under the projection of a UI, the screen Y grows upward while the design Y grows downward.
Snapping happens only on an aligned grid: under a rotation other than a half turn, a shear or a perspective, every snap, span and quantize method returns its input unchanged; a mirror or a half turn stays aligned.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
PixelGrid | of(float[] projection, float[] modelView, int viewportWidth, int viewportHeight) factory | Computes the grid of a column-major projection and model-view and of a viewport size in pixels. |
Methods
Section titled “Methods”Drag and drop
Section titled “Drag and drop”| Returns | Signature | Summary |
|---|---|---|
double | snapX(double x) | Returns the design X of the screen pixel boundary closest to x. |
double | snapY(double y) | Returns the design Y of the screen pixel boundary closest to y. |
double | snapRight(double left, double right) | Returns the snapped far edge of a span from left to right. |
double | snapBottom(double top, double bottom) | Returns the snapped far edge of a span from top to bottom, one pixel away from the near edge when both would snap together. |
double | snapWidth(double left, double width) | Returns the far edge of a stroke that starts at left and extends by width, which may be negative. |
double | snapHeight(double top, double height) | Returns the far edge of a stroke that starts at top and extends by height, which may be negative, rounded to a whole number of pixels and at least one. |
Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
BoundingBox | getVisibleArea(double margin) | Returns the area of the design space that the viewport shows, widened by margin screen pixels on each side. |
double | toScreenX(double x) | Converts a design X to a screen X, in pixels of the viewport. |
double | toScreenY(double y) | Converts a design Y to a screen Y, in pixels of the viewport counted from its bottom. |
int | toPixelWidth(double width) | Returns how many screen pixels a design width covers, rounded up and at least one: the size of an off-screen buffer that holds it without loss. |
int | toPixelHeight(double height) | Returns how many screen pixels a design height covers, rounded up and at least one. |
double | getPixelSize() | Returns the size of one screen pixel in design pixels, on the axis where the scale is largest: the width that the shaders give to an antialiased edge. |
double | getUnitX() | Returns the signed number of screen pixels that one design pixel moves along X. |
double | getUnitY() | Returns the signed number of screen pixels that one design pixel moves along Y; it is negative under the projection of a UI, whose Y goes down. |
double | getSkewX() | Returns the number of screen pixels along X that one design pixel along Y moves; 0 without rotation nor shear. |
double | getSkewY() | Returns the number of screen pixels along Y that one design pixel along X moves; 0 without rotation nor shear. |
double | getScaleX() | Returns the length, in screen pixels, of one design pixel along X, whatever the rotation. |
double | getScaleY() | Returns the length, in screen pixels, of one design pixel along Y, whatever the rotation. |
double | getOriginX() | Returns the screen X of the design origin. |
double | getOriginY() | Returns the screen Y of the design origin, counted from the bottom of the viewport. |
int | getViewportWidth() | Returns the width of the viewport, in pixels. |
int | getViewportHeight() | Returns the height of the viewport, in pixels. |
boolean | isFlat() | If true, the transform has no perspective: the plane of the drawing stays parallel to the screen. |
boolean | isAligned() | If true, the design axes are parallel to the screen axes and the snapping methods move edges onto whole pixels. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
Span | spanX(double x, double width) | Returns the horizontal PixelGrid.Span that draws a shape from x over width. |
Span | spanY(double y, double height) | Returns the vertical PixelGrid.Span that draws a shape from y over height, by the same rules as spanX. |
double | quantizeX(double offset) | Rounds a horizontal motion in design pixels to a whole number of screen pixels, so that a moving node lands on the grid. |
double | quantizeY(double offset) | Rounds a vertical motion in design pixels to a whole number of screen pixels. |
double | fromScreenX(double screenX) | Converts a screen X back to a design X. |
double | fromScreenY(double screenY) | Converts a screen Y, counted from the bottom of the viewport, back to a design Y. |
Creation details
Section titled “Creation details”PixelGrid of(float[] projection, float[] modelView, int viewportWidth, int viewportHeight) factory
Computes the grid of a column-major projection and model-view and of a viewport size in pixels.
Method details
Section titled “Method details”double snapX(double x)
Returns the design X of the screen pixel boundary closest to x.
double snapY(double y)
Returns the design Y of the screen pixel boundary closest to y.
snapRight
Section titled “snapRight”double snapRight(double left, double right)
Returns the snapped far edge of a span from left to right.
When both edges would snap to the same boundary, the far edge moves one pixel away, so a shape that is not empty never vanishes.
snapBottom
Section titled “snapBottom”double snapBottom(double top, double bottom)
Returns the snapped far edge of a span from top to bottom, one pixel away from the near edge when both would snap together.
snapWidth
Section titled “snapWidth”double snapWidth(double left, double width)
Returns the far edge of a stroke that starts at left and extends by width, which may be negative.
The stroke covers a whole number of pixels, at least one, so a border keeps the same thickness on every side and at every position.
snapHeight
Section titled “snapHeight”double snapHeight(double top, double height)
Returns the far edge of a stroke that starts at top and extends by height, which may be negative, rounded to a whole number of pixels and at least one.
getVisibleArea
Section titled “getVisibleArea”BoundingBox getVisibleArea(double margin)
Returns the area of the design space that the viewport shows, widened by margin screen pixels on each side.
Returns null under a perspective, or when the transform flattens the plane.
toScreenX
Section titled “toScreenX”double toScreenX(double x)
Converts a design X to a screen X, in pixels of the viewport.
toScreenY
Section titled “toScreenY”double toScreenY(double y)
Converts a design Y to a screen Y, in pixels of the viewport counted from its bottom.
toPixelWidth
Section titled “toPixelWidth”int toPixelWidth(double width)
Returns how many screen pixels a design width covers, rounded up and at least one: the size of an off-screen buffer that holds it without loss.
toPixelHeight
Section titled “toPixelHeight”int toPixelHeight(double height)
Returns how many screen pixels a design height covers, rounded up and at least one.
getPixelSize
Section titled “getPixelSize”double getPixelSize()
Returns the size of one screen pixel in design pixels, on the axis where the scale is largest: the width that the shaders give to an antialiased edge.
getUnitX
Section titled “getUnitX”double getUnitX()
Returns the signed number of screen pixels that one design pixel moves along X.
getUnitY
Section titled “getUnitY”double getUnitY()
Returns the signed number of screen pixels that one design pixel moves along Y; it is negative under the projection of a UI, whose Y goes down.
getSkewX
Section titled “getSkewX”double getSkewX()
Returns the number of screen pixels along X that one design pixel along Y moves; 0 without rotation nor shear.
getSkewY
Section titled “getSkewY”double getSkewY()
Returns the number of screen pixels along Y that one design pixel along X moves; 0 without rotation nor shear.
getScaleX
Section titled “getScaleX”double getScaleX()
Returns the length, in screen pixels, of one design pixel along X, whatever the rotation.
getScaleY
Section titled “getScaleY”double getScaleY()
Returns the length, in screen pixels, of one design pixel along Y, whatever the rotation.
getOriginX
Section titled “getOriginX”double getOriginX()
Returns the screen X of the design origin.
getOriginY
Section titled “getOriginY”double getOriginY()
Returns the screen Y of the design origin, counted from the bottom of the viewport.
getViewportWidth
Section titled “getViewportWidth”int getViewportWidth()
Returns the width of the viewport, in pixels.
getViewportHeight
Section titled “getViewportHeight”int getViewportHeight()
Returns the height of the viewport, in pixels.
isFlat
Section titled “isFlat”boolean isFlat()
If true, the transform has no perspective: the plane of the drawing stays parallel to the screen.
isAligned
Section titled “isAligned”boolean isAligned()
If true, the design axes are parallel to the screen axes and the snapping methods move edges onto whole pixels.
If false, they return their input, and the core draws with smooth edges instead.
Span spanX(double x, double width)
Returns the horizontal PixelGrid.Span that draws a shape from x over width.
A span thinner than three pixels keeps its rounded pixel thickness and stays centered on the shape; a span thinner than one pixel draws one pixel with a coverage below 1F, so a hairline fades instead of disappearing.
Span spanY(double y, double height)
Returns the vertical PixelGrid.Span that draws a shape from y over height, by the same rules as spanX.
quantizeX
Section titled “quantizeX”double quantizeX(double offset)
Rounds a horizontal motion in design pixels to a whole number of screen pixels, so that a moving node lands on the grid.
quantizeY
Section titled “quantizeY”double quantizeY(double offset)
Rounds a vertical motion in design pixels to a whole number of screen pixels.
fromScreenX
Section titled “fromScreenX”double fromScreenX(double screenX)
Converts a screen X back to a design X.
fromScreenY
Section titled “fromScreenY”double fromScreenY(double screenY)
Converts a screen Y, counted from the bottom of the viewport, back to a design Y.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
