JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
Triangle.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.graph.geom;
29
30import com.jogamp.math.VectorUtil;
31import com.jogamp.math.geom.plane.AffineTransform;
32
33public class Triangle {
34 private final Vertex[] vertices = new Vertex[3];
35 private final boolean[] boundaryEdges = new boolean[3];
36 private boolean[] boundaryVertices = null;
37 private int id;
38
39 public Triangle(final Vertex v1, final Vertex v2, final Vertex v3, final boolean[] boundaryVertices) {
40 id = Integer.MAX_VALUE;
41 vertices[0] = v1;
42 vertices[1] = v2;
43 vertices[2] = v3;
44 this.boundaryVertices = boundaryVertices;
45 }
46
47 public Triangle(final Triangle src) {
48 id = src.id;
49 vertices[0] = src.vertices[0].copy();
50 vertices[1] = src.vertices[1].copy();
51 vertices[2] = src.vertices[2].copy();
52 System.arraycopy(src.boundaryEdges, 0, boundaryEdges, 0, 3);
53 boundaryVertices = new boolean[3];
54 System.arraycopy(src.boundaryVertices, 0, boundaryVertices, 0, 3);
55 }
56
57 private Triangle(final int id, final boolean[] boundaryEdges, final boolean[] boundaryVertices){
58 this.id = id;
59 System.arraycopy(boundaryEdges, 0, this.boundaryEdges, 0, 3);
60 this.boundaryVertices = new boolean[3];
61 System.arraycopy(boundaryVertices, 0, this.boundaryVertices, 0, 3);
62 }
63
64 /**
65 * Returns a transformed copy of this instance using the given AffineTransform.
66 */
68 final Triangle tri = new Triangle(id, boundaryEdges, boundaryVertices);
69 tri.vertices[0] = t.transform(vertices[0], new Vertex());
70 tri.vertices[1] = t.transform(vertices[1], new Vertex());
71 tri.vertices[2] = t.transform(vertices[2], new Vertex());
72 return tri;
73 }
74
75 /**
76 * Returns true if all vertices are on-curve, otherwise false.
77 */
78 public final boolean isOnCurve() {
79 return vertices[0].isOnCurve() && vertices[1].isOnCurve() && vertices[2].isOnCurve();
80 }
81
82 /**
83 * Returns true if all vertices are lines, i.e. zero tex-coord, otherwise false.
84 */
85 public final boolean isLine() {
86 return VectorUtil.isVec2Zero(vertices[0].getTexCoord()) &&
87 VectorUtil.isVec2Zero(vertices[1].getTexCoord()) &&
88 VectorUtil.isVec2Zero(vertices[2].getTexCoord()) ;
89 }
90
91 public int getId() {
92 return id;
93 }
94
95 public void setId(final int id) {
96 this.id = id;
97 }
98
99 /** Returns array of 3 vertices, denominating the triangle. */
100 public Vertex[] getVertices() {
101 return vertices;
102 }
103
104 public boolean isEdgesBoundary() {
105 return boundaryEdges[0] || boundaryEdges[1] || boundaryEdges[2];
106 }
107
108 public boolean isVerticesBoundary() {
109 return boundaryVertices[0] || boundaryVertices[1] || boundaryVertices[2];
110 }
111
112 public boolean[] getEdgeBoundary() {
113 return boundaryEdges;
114 }
115
116 public boolean[] getVerticesBoundary() {
117 return boundaryVertices;
118 }
119
120 public void setVerticesBoundary(final boolean[] boundaryVertices) {
121 this.boundaryVertices = boundaryVertices;
122 }
123
124 @Override
125 public String toString() {
126 return "Tri ID: " + id + ", onCurve "+isOnCurve()+"\n\t" +
127 vertices[0] + ", bound "+boundaryVertices[0]+"\n\t" +
128 vertices[1] + ", bound "+boundaryVertices[1]+"\n\t" +
129 vertices[2] + ", bound "+boundaryVertices[2];
130 }
131}
Triangle(final Triangle src)
Definition: Triangle.java:47
void setVerticesBoundary(final boolean[] boundaryVertices)
Definition: Triangle.java:120
final boolean isOnCurve()
Returns true if all vertices are on-curve, otherwise false.
Definition: Triangle.java:78
Vertex[] getVertices()
Returns array of 3 vertices, denominating the triangle.
Definition: Triangle.java:100
final boolean isLine()
Returns true if all vertices are lines, i.e.
Definition: Triangle.java:85
Triangle transform(final AffineTransform t)
Returns a transformed copy of this instance using the given AffineTransform.
Definition: Triangle.java:67
Triangle(final Vertex v1, final Vertex v2, final Vertex v3, final boolean[] boundaryVertices)
Definition: Triangle.java:39
void setId(final int id)
Definition: Triangle.java:95
A Vertex exposing Vec3f vertex- and texture-coordinates.
Definition: Vertex.java:37
final boolean isOnCurve()
Definition: Vertex.java:146
static boolean isVec2Zero(final Vec3f vec)
Return true if 2D vector components are zero, no FloatUtil#EPSILON is taken into consideration.
Definition: VectorUtil.java:39
final AABBox transform(final AABBox src, final AABBox dst)