-
Notifications
You must be signed in to change notification settings - Fork 16
/
builder.go
99 lines (80 loc) · 2.32 KB
/
builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package geometries
import (
"errors"
uuid "github.com/satori/go.uuid"
"github.com/deepvalue-network/software/treedee/domain/worlds/scenes/nodes/models/geometries/primitives"
"github.com/deepvalue-network/software/treedee/domain/worlds/scenes/nodes/models/geometries/shaders"
"github.com/deepvalue-network/software/treedee/domain/worlds/scenes/nodes/models/geometries/vertices"
)
type builder struct {
id *uuid.UUID
isTriangle bool
primitive primitives.Primitive
shader shaders.Shader
vertices []vertices.Vertex
}
func createBuilder() Builder {
out := builder{
id: nil,
isTriangle: false,
primitive: nil,
shader: nil,
vertices: nil,
}
return &out
}
// Create initializes the builder
func (app *builder) Create() Builder {
return createBuilder()
}
// WithID adds an ID to the builder
func (app *builder) WithID(id *uuid.UUID) Builder {
app.id = id
return app
}
// WithPrimitive adds a primitive to the builder
func (app *builder) WithPrimitive(primitive primitives.Primitive) Builder {
app.primitive = primitive
return app
}
// WithVertices add vertices to the builder
func (app *builder) WithVertices(vertices []vertices.Vertex) Builder {
app.vertices = vertices
return app
}
// WithShader adds a shader to the builder
func (app *builder) WithShader(shader shaders.Shader) Builder {
app.shader = shader
return app
}
// IsTriangle flags the builder as triangles
func (app *builder) IsTriangle() Builder {
app.isTriangle = true
return app
}
// Now builds a new Geometry instance
func (app *builder) Now() (Geometry, error) {
if app.id == nil {
return nil, errors.New("the ID is mandatory in order to build a Geometry instance")
}
if app.primitive != nil {
return nil, errors.New("finish the primitives loading in geometries")
}
if app.shader == nil {
return nil, errors.New("the shader is mandatory in order to build a Geometry instance")
}
if app.vertices != nil && len(app.vertices) <= 0 {
app.vertices = nil
}
if app.vertices == nil {
return nil, errors.New("the vertices are mandatory in order to build a Geometry instance")
}
var typ Type
if app.isTriangle {
typ = createTypeWithTriangle()
}
if typ == nil {
return nil, errors.New("the type is mandatory in order to build a Geometry instance")
}
return createGeometry(app.id, typ, app.shader, app.vertices), nil
}