1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.geometry.io.euclidean.threed;
18
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Objects;
22
23 import org.apache.commons.geometry.euclidean.internal.EuclideanUtils;
24 import org.apache.commons.geometry.euclidean.threed.Vector3D;
25
26
27
28
29 public class SimpleFacetDefinition implements FacetDefinition {
30
31
32 private final List<Vector3D> vertices;
33
34
35 private final Vector3D normal;
36
37
38
39
40
41 public SimpleFacetDefinition(final List<Vector3D> vertices) {
42 this(vertices, null);
43 }
44
45
46
47
48
49
50 public SimpleFacetDefinition(final List<Vector3D> vertices, final Vector3D normal) {
51 Objects.requireNonNull(vertices, "Facet vertex list cannot be null");
52 if (vertices.size() < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
53 throw new IllegalArgumentException("Facet vertex list must contain at least " +
54 EuclideanUtils.TRIANGLE_VERTEX_COUNT + " points; found " + vertices.size());
55 }
56
57 this.vertices = Collections.unmodifiableList(vertices);
58 this.normal = normal;
59 }
60
61
62 @Override
63 public List<Vector3D> getVertices() {
64 return vertices;
65 }
66
67
68 @Override
69 public Vector3D getNormal() {
70 return normal;
71 }
72
73
74 @Override
75 public String toString() {
76 final StringBuilder sb = new StringBuilder();
77 sb.append(getClass().getSimpleName())
78 .append("[vertices= ")
79 .append(getVertices())
80 .append(", normal= ")
81 .append(getNormal())
82 .append(']');
83
84 return sb.toString();
85 }
86 }