test

package
v0.0.0-...-405cb25 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package test provides test helpers for BruteRay.

  • comparing rendered images to golden testdata
  • minimal implementations of a few shapes and materials

Rendered images and golden testdata are saved under directories testdata/got and testdata/, respectively.

The minimal implementations of Sphere and Flat material allow tests without complex dependencies between packages like objects, materials, textures.

Index

Constants

View Source
const (
	DefaultTolerance = 1e-5
	DefaultWidth     = 300
	DefaultHeight    = 200
)

Variables

View Source
var (
	Blue    = WithShadows(colorf.Blue)
	Cyan    = WithShadows(colorf.Cyan)
	Gray    = WithShadows(colorf.Gray(0.5))
	Green   = WithShadows(colorf.Green)
	Magenta = WithShadows(colorf.Magenta)
	White   = WithShadows(colorf.White)
	Yellow  = WithShadows(colorf.Yellow)

	Checkers1 = Checkers(White, Magenta)
	Checkers2 = Checkers(White, Cyan)
	Checkers3 = Checkers(White, Green)
	Checkers4 = Checkers(WithShadows(colorf.Gray(0.4)), WithShadows(colorf.Gray(0.7)))
)
View Source
var Normal Material = &normal{1, 1, 1}

Normal is a non-physical material that reveals the component of the normal vector that points towards the camera. The normal pointing perpendicular to the direction of view is rendered as black. Away from the viewing direction is rendered as red to draw attention to visible backfaces.

View Source
var Normal2 = normal2{}

Functions

func Benchmark

func Benchmark(b *testing.B, s *Scene, c Camera, tolerance float64)

func Check

func Check(t testing.TB, err error)

func Checkers

func Checkers(a, b Material) Material

Checkers alternates between materials a and b in a checkerboard pattern with period 1.

func Compare

func Compare(t testing.TB, tolerance float64, img image.Image)

func Diff

func Diff(A, B image.Image) float64

func DiffImg

func DiffImg(t testing.TB, a, b string) float64

func NPass

func NPass(t *testing.T, s *Scene, c Camera, numPass int, tolerance float64)

NPass is like OnePass but allows to set the number of monte-carlo passes.

func NPassSize

func NPassSize(t *testing.T, s *Scene, c Camera, numPass, width, height int, tolerance float64)

NPassSize is like NPass, but allows to set the image size. Intended to run costly tests at lower resolution.

func OnePass

func OnePass(t *testing.T, s *Scene, c Camera, tolerance float64)

OnePass renders a scene with default size and one monte-carlo pass, and compares the result to testdata.

func PointLight

func PointLight(pos Vec) Light

func QuadView

func QuadView(t *testing.T, s *Scene, c Camera, fov float64, tolerance float64)

QuadView renders the scene from 4 points of view

  • the camera
  • the X, Y and Z direction, orthgraphically

and compares the result to testdata.

func QuadViewN

func QuadViewN(t *testing.T, s *Scene, c Camera, fov float64, nPass int, tolerance float64)

QuadViewN is like QuadView but allows to set the number of passes.

func Save

func Save(t testing.TB, img image.Image, fname string)

func Sheet

func Sheet(m Material, height float64) Object

func Sphere

func Sphere(m Material, diam float64, origin geom.Vec) Object

Sphere returns a minimal implementation of a sphere. Intended for tests that should not depend on package objects/

func TestName

func TestName() string

TestName returns a name based on the calling Test function. E.g.:

github.com/barnex/bruteray/object.TestSphere -> object.sphere

func Testdata

func Testdata() string

Testdata walks up the filesystem starting from the working directory in search of an existing subdirectory called "testdata".

func Transparent

func Transparent(trans, add Color) Material

func WithShadows

func WithShadows(c Color) Material

WithShadows returns a non-physical material similar to Normal, but overlayed with shadows.

Types

type Convergence

type Convergence struct {
	*tracer.Sampler
	Golden imagef.Image
	Output []Row
	// contains filtered or unexported fields
}

func (*Convergence) Error

func (c *Convergence) Error() Row

func (*Convergence) MustWrite

func (c *Convergence) MustWrite(fname string)

func (*Convergence) Sample

func (c *Convergence) Sample(nPass int)

func (*Convergence) Write

func (c *Convergence) Write(w io.Writer) error

type Flat

type Flat Color

Flat is a minimal implementation of material.Flat, a non-physical material that always evaluates to the same color. Intended for tests that should not depend on package materials.

func (Flat) Shade

func (m Flat) Shade(_ *Ctx, _ *Scene, r *Ray, h HitCoords) Color

Eval implements Material.

type Row

type Row struct {
	Pass  int
	Error float64
}

Jump to

Keyboard shortcuts

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