testscene

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package testscene 提供后端一致性测试共用的“页面场景”与配套图元/度量: 同一段 DrawContext 绘制命令可依次作用到不同光栅后端,用于逐像素对照 与速度测试。它只依赖 geom 数学结构与一个与 render.DrawContext 结构 等价的本地接口(Renderer),因此不引入 render 包,避免内部测试包与插件 包之间的 import cycle。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendCircleGeom

func AppendCircleGeom(p *geom.Path, cx, cy, r float64) *geom.Path

AppendCircleGeom 在路径后追加一个圆。

func CirclePathGeom

func CirclePathGeom(cx, cy, r float64) *geom.Path

CirclePathGeom 返回近似圆的多边形路径。

func LoadTestFace

func LoadTestFace(t testing.TB, fontPath string) *canvas.FontFace

LoadTestFace 从字体文件加载测试字体 14px。

func MaskedChecker

func MaskedChecker() image.Image

MaskedChecker 返回带椭圆 alpha 掩码的棋盘图。

func OffscreenGradient

func OffscreenGradient() image.Image

OffscreenGradient 返回离屏预渲染的线性渐变图,用作按完整矩阵贴回的素材。

func PickTestFont

func PickTestFont() string

PickTestFont 依次尝试已知可用的本地字体路径,找不到时返回空串。

func RoundedRectPath

func RoundedRectPath(x0, y0, x1, y1, r float64) *geom.Path

RoundedRectPath 返回圆角矩形路径。

func SceneBackend

func SceneBackend(t testing.TB, b Renderer, fontPath string)

SceneBackend 用 Renderer(即 render.DrawContext 的实现)绘制与 SceneDirect 完全一致、仅方法调度方式不同的测试场景。

func SceneDirect

func SceneDirect(t testing.TB, ctx *canvas.Context, fontPath string)

SceneDirect 用 canvas.Context 的既有调用风格绘制测试场景(含背景、图片、 开放路径描边、EvenOdd 双圆、渐变矩形、布尔裁剪、字形文字、虚线圆角矩形、 离屏图贴回与描边复制)。

func WavePath

func WavePath() *geom.Path

WavePath 返回开放波浪样条路径。

Types

type DiffStat

type DiffStat struct {
	Changed  int     // 至少一个通道差异的像素数
	Hot      int     // 任一个通道差异 > 32 的像素数
	MaxDelta int     // 最大单通道差异(0..255)
	AvgDelta float64 // 平均单通道差异(全部字节)
}

DiffStat 统计两图逐通道(RRGGBBAA,premultiplied)差异。

func CalcDiff

func CalcDiff(t testing.TB, a, b *image.RGBA) DiffStat

CalcDiff 计算两图的逐像素差异统计,尺寸或像素长度不一致时测试失败。

type Renderer

type Renderer interface {
	SetFillColor(c color.Color)
	SetFillGradient(g geom.Gradient)
	SetFillRule(rule geom.FillRule)
	ClearFill()
	SetStrokeColor(c color.Color)
	SetStrokeWidth(w float64)
	SetStrokeCapper(cap geom.Capper)
	SetStrokeJoiner(join geom.Joiner)
	ClearStroke()
	SetDashes(offset float64, dashes ...float64)
	DrawPath(x, y float64, p *geom.Path)
	DrawImage(img image.Image, x, y float64, dpmm float64)
	TextPath(p *geom.Path, x, y float64)
	RenderImage(img image.Image, m geom.Matrix)
	CopyStrokeToFill()
	CurrentMatrix() geom.Matrix
}

Renderer 是本包场景所需的绘制操作面,方法签名与 render.DrawContext 中 对应方法完全一致。canvas 后端与各栅格插件后端(gogpu/gg、FloatTech/gg、 tinyskia)都满足该接口。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL