MCPcopy
hub / github.com/tdewolff/canvas / NewShapeHatch

Function NewShapeHatch

patterns.go:169–184  ·  view source on GitHub ↗

NewShapeHatch returns a new shape hatch that repeats the given shape over a rhombus primitive cell with sides of length distance. Thickness is the stroke thickness applied to the shape; stroking is ignored with thickness is zero.

(ifill any, shape *Path, distance, thickness float64)

Source from the content-addressed store, hash-verified

167
168// NewShapeHatch returns a new shape hatch that repeats the given shape over a rhombus primitive cell with sides of length distance. Thickness is the stroke thickness applied to the shape; stroking is ignored with thickness is zero.
169func NewShapeHatch(ifill any, shape *Path, distance, thickness float64) *HatchPattern {
170 d := distance * math.Sin(60.0*math.Pi/180.0)
171 cell := SquareCell(1.0)
172 return NewHatchPattern(ifill, thickness, cell, func(x0, y0, x1, y1 float64) *Path {
173 p := &Path{}
174 for y := math.Floor(y0/distance) * distance; y <= y1; y += 2.0 * d {
175 for x := math.Floor(x0/distance) * distance; x <= x1; x += distance {
176 p = p.Append(shape.Copy().Translate(x, y))
177 }
178 for x := (math.Floor(x0/distance) + 0.5) * distance; x <= x1; x += distance {
179 p = p.Append(shape.Copy().Translate(x, y+d))
180 }
181 }
182 return p
183 })
184}
185
186// ImagePattern is an image tiling pattern of an image drawn from an origin with a certain resolution. Higher resolution will give smaller tilings.
187//type ImagePattern struct {

Callers 1

mainFunction · 0.92

Calls 5

AppendMethod · 0.95
SquareCellFunction · 0.85
NewHatchPatternFunction · 0.85
TranslateMethod · 0.45
CopyMethod · 0.45

Tested by

no test coverage detected