MCPcopy
hub / github.com/fogleman/primitive / Mutate

Method Mutate

primitive/triangle.go:49–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47}
48
49func (t *Triangle) Mutate() {
50 w := t.Worker.W
51 h := t.Worker.H
52 rnd := t.Worker.Rnd
53 const m = 16
54 for {
55 switch rnd.Intn(3) {
56 case 0:
57 t.X1 = clampInt(t.X1+int(rnd.NormFloat64()*16), -m, w-1+m)
58 t.Y1 = clampInt(t.Y1+int(rnd.NormFloat64()*16), -m, h-1+m)
59 case 1:
60 t.X2 = clampInt(t.X2+int(rnd.NormFloat64()*16), -m, w-1+m)
61 t.Y2 = clampInt(t.Y2+int(rnd.NormFloat64()*16), -m, h-1+m)
62 case 2:
63 t.X3 = clampInt(t.X3+int(rnd.NormFloat64()*16), -m, w-1+m)
64 t.Y3 = clampInt(t.Y3+int(rnd.NormFloat64()*16), -m, h-1+m)
65 }
66 if t.Valid() {
67 break
68 }
69 }
70}
71
72func (t *Triangle) Valid() bool {
73 const minDegrees = 15

Callers 1

NewRandomTriangleFunction · 0.95

Calls 2

ValidMethod · 0.95
clampIntFunction · 0.85

Tested by

no test coverage detected