Skip to content

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.

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.

ReturnsSignatureSummary
PixelGridof(float[] projection, float[] modelView, int viewportWidth, int viewportHeight) factoryComputes the grid of a column-major projection and model-view and of a viewport size in pixels.

ReturnsSignatureSummary
doublesnapX(double x)Returns the design X of the screen pixel boundary closest to x.
doublesnapY(double y)Returns the design Y of the screen pixel boundary closest to y.
doublesnapRight(double left, double right)Returns the snapped far edge of a span from left to right.
doublesnapBottom(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.
doublesnapWidth(double left, double width)Returns the far edge of a stroke that starts at left and extends by width, which may be negative.
doublesnapHeight(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.
ReturnsSignatureSummary
BoundingBoxgetVisibleArea(double margin)Returns the area of the design space that the viewport shows, widened by margin screen pixels on each side.
doubletoScreenX(double x)Converts a design X to a screen X, in pixels of the viewport.
doubletoScreenY(double y)Converts a design Y to a screen Y, in pixels of the viewport counted from its bottom.
inttoPixelWidth(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.
inttoPixelHeight(double height)Returns how many screen pixels a design height covers, rounded up and at least one.
doublegetPixelSize()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.
doublegetUnitX()Returns the signed number of screen pixels that one design pixel moves along X.
doublegetUnitY()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.
doublegetSkewX()Returns the number of screen pixels along X that one design pixel along Y moves; 0 without rotation nor shear.
doublegetSkewY()Returns the number of screen pixels along Y that one design pixel along X moves; 0 without rotation nor shear.
doublegetScaleX()Returns the length, in screen pixels, of one design pixel along X, whatever the rotation.
doublegetScaleY()Returns the length, in screen pixels, of one design pixel along Y, whatever the rotation.
doublegetOriginX()Returns the screen X of the design origin.
doublegetOriginY()Returns the screen Y of the design origin, counted from the bottom of the viewport.
intgetViewportWidth()Returns the width of the viewport, in pixels.
intgetViewportHeight()Returns the height of the viewport, in pixels.
booleanisFlat()If true, the transform has no perspective: the plane of the drawing stays parallel to the screen.
booleanisAligned()If true, the design axes are parallel to the screen axes and the snapping methods move edges onto whole pixels.
ReturnsSignatureSummary
SpanspanX(double x, double width)Returns the horizontal PixelGrid.Span that draws a shape from x over width.
SpanspanY(double y, double height)Returns the vertical PixelGrid.Span that draws a shape from y over height, by the same rules as spanX.
doublequantizeX(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.
doublequantizeY(double offset)Rounds a vertical motion in design pixels to a whole number of screen pixels.
doublefromScreenX(double screenX)Converts a screen X back to a design X.
doublefromScreenY(double screenY)Converts a screen Y, counted from the bottom of the viewport, back to a design Y.

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.

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. 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.

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. 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.

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.

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.

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. 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.

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.


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

Report a problem with this page