Donner SVG main
0.8.0 ยท 766e862a0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
GeodeAnchoredSampling.h File Reference

Bilinear texel mapping that a whole-pixel move of the target or the source cannot change. More...

#include <array>
#include <optional>
#include "donner/base/Transform.h"
#include "donner/base/Vector2.h"
Include dependency graph for GeodeAnchoredSampling.h:

Classes

struct  donner::geode::AnchoredTexelRows
 Maps a target pixel position p to source texel coordinates as texel = linear * (p - anchor) + fraction + whole, where linear is the single-precision linear part of the inverse transform, fraction lies in [0, 1) and whole is an integer texel offset. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

std::optional< AnchoredTexelRows > donner::geode::AnchoredTexelRowsFor (const Transform2d &targetFromTexel, const Vector2i &anchor)
 Splits the texel mapping of targetFromTexel at anchor.
std::optional< Vector2i > donner::geode::AnchorPixelFor (const Vector2d &position)
 The target pixel containing position, for use as an anchor that moves with content placed at position.

Detailed Description

Bilinear texel mapping that a whole-pixel move of the target or the source cannot change.

Function Documentation

◆ AnchoredTexelRowsFor()

std::optional< AnchoredTexelRows > donner::geode::AnchoredTexelRowsFor ( const Transform2d & targetFromTexel,
const Vector2i & anchor )

Splits the texel mapping of targetFromTexel at anchor.

The fraction is computed in double precision from the anchor's exact texel coordinate, so moving the source by whole texels changes only whole, and moving the target and the anchor together by whole pixels changes nothing. Bilinear weights computed from these rows are then the same for corresponding pixels of two renders that differ by such a move, which a texture coordinate interpolated across the quad, or a single-precision transform of the absolute pixel position, does not guarantee.

Parameters
targetFromTexelTransform from source texel coordinates to target pixels.
anchorA target pixel that moves with the content the target pixels are aligned to.
Returns
The rows, or std::nullopt when the transform is not invertible or the anchor's texel coordinate does not fit a 32-bit integer.

◆ AnchorPixelFor()

std::optional< Vector2i > donner::geode::AnchorPixelFor ( const Vector2d & position)

The target pixel containing position, for use as an anchor that moves with content placed at position.

A position on a pixel boundary up to double rounding counts as that boundary's pixel, so two placements a whole number of pixels apart select anchors the same distance apart.

Parameters
positionTarget-space position of a point fixed to the content.
Returns
The pixel, or std::nullopt when it does not fit a 32-bit integer or position is not finite; the caller then has no anchor to sample through.