sdf

package
v0.0.0-...-d2c143d Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sdf provides primitives for creating and manipulating Signed-Distance-Fields and Displacement-Fields with conversion utilities to and from images.

Index

Constants

View Source
const (
	// OpaqueAlpha is an alpha-threshold so only fully-opaque pixels will be within the stencil
	OpaqueAlpha = uint16(math.MaxUint16)
	// HalfAlpha is an alpha-threshold so 50% opaque pixels will be within the stencil
	HalfAlpha = uint16(math.MaxUint16 / 2)
)

Variables

This section is empty.

Functions

func DrawStencil

func DrawStencil(s Stencil, c color.Color, bg color.Color) *image.RGBA

DrawStencil renders a Stencil into a 2-color image. Using color c for pixels within the stencil and color bg for pixels outside.

func DrawStencilImage

func DrawStencilImage(s Stencil, srcImg image.Image, bg color.Color) *image.RGBA

DrawStencilImage stencils a given source image and returns a new image where pixels within the stencil are taken from the source image and pixels outside default to the given bg color.

Types

type DisplacementField

type DisplacementField struct {
	*SDF
	// contains filtered or unexported fields
}

DisplacementField is a vectorized Signed-Distance-Field where each field value is associated with its nearest boundary point.

func Calculate

func Calculate(s Stencil) *DisplacementField

Calculate a new DisplacementField from the given Stencil

func (*DisplacementField) NearestBoundaryAt

func (df *DisplacementField) NearestBoundaryAt(x, y int) (int, int)

NearestBoundaryAt returns X,Y coordinate of the nearest boundary point from the given point

type ImageAlphaStencil

type ImageAlphaStencil struct {
	Image image.Image
	Alpha uint16
}

ImageAlphaStencil implements a Stencil where the alpha channel of an image is thresholded against the Alpha value

func (ImageAlphaStencil) Size

func (s ImageAlphaStencil) Size() (int, int)

Size returns the width and height of the ImageAlphaStencil

func (ImageAlphaStencil) Within

func (s ImageAlphaStencil) Within(x, y int) bool

Within predicates whether the given coordinate is inside or outside of the stencil surface

type ImplicitSurfaceStencil

type ImplicitSurfaceStencil struct {
	SDF       *SDF
	Threshold float64
}

ImplicitSurfaceStencil implements a Stencil where a Signed-Distance-Field is thresholded against the Threshold value to define an implicit surface.

func (ImplicitSurfaceStencil) Size

func (s ImplicitSurfaceStencil) Size() (int, int)

Size returns the width and height of the ImplicitSurfaceStencil

func (ImplicitSurfaceStencil) Within

func (s ImplicitSurfaceStencil) Within(x, y int) bool

Within predicates whether the given coordinate is inside or outside of the stencil surface

type SDF

type SDF struct {
	Field  []float64
	Width  int
	Height int
}

SDF models a rectangular & discretized Signed Distance Field

func Lerp

func Lerp(a *SDF, b *SDF, t float64) (*SDF, error)

Lerp returns the linear interpolation between two SDFs, weighted by t in range [0, 1]

func New

func New(w, h int) *SDF

New returns a zeroed SDF of the given size

func (*SDF) At

func (sdf *SDF) At(x, y int) float64

At returns the field value at the given coordinate

func (*SDF) Draw

func (sdf *SDF) Draw() *image.Gray

Draw returns an 8-bit grayscale representation of a Signed-Distance-Field

func (*SDF) Set

func (sdf *SDF) Set(x, y int, v float64)

Set writes the field value at the given coordinate

type Stencil

type Stencil interface {
	// Within predicates whether the given coordinate is inside or outside of the stencil surface
	Within(x, y int) bool
	// Size returns the width and height of the Stencil
	Size() (int, int)
}

Stencil defines a binary surface where pixels are either inside or outside the stencil

Jump to

Keyboard shortcuts

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