| package org.eclipse.apogy.common.math.quickhull3d; |
| |
| /******************************************************************************** |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * Contributors: Pierre Allard (Pierre.Allard@canada.ca), Regent L'Archeveque |
| * (Regent.Larcheveque@canada.ca), Sebastien Gemme (Sebastien.Gemme@canada.ca), |
| * Canadian Space Agency (CSA) - Initial API and implementation |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 1.0 which is available at |
| * http://www.eclipse.org/legal/epl-v10.html. |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| ********************************************************************************/ |
| |
| class VertexList { |
| private Vertex head; |
| private Vertex tail; |
| |
| /** |
| * Clears this list. |
| */ |
| public void clear() { |
| this.head = this.tail = null; |
| } |
| |
| /** |
| * Adds a vertex to the end of this list. |
| */ |
| public void add(Vertex vtx) { |
| if (this.head == null) { |
| this.head = vtx; |
| } else { |
| this.tail.next = vtx; |
| } |
| vtx.prev = this.tail; |
| vtx.next = null; |
| this.tail = vtx; |
| } |
| |
| /** |
| * Adds a chain of vertices to the end of this list. |
| */ |
| public void addAll(Vertex vtx) { |
| if (this.head == null) { |
| this.head = vtx; |
| } else { |
| this.tail.next = vtx; |
| } |
| vtx.prev = this.tail; |
| while (vtx.next != null) { |
| vtx = vtx.next; |
| } |
| this.tail = vtx; |
| } |
| |
| /** |
| * Deletes a vertex from this list. |
| */ |
| public void delete(Vertex vtx) { |
| if (vtx.prev == null) { |
| this.head = vtx.next; |
| } else { |
| vtx.prev.next = vtx.next; |
| } |
| if (vtx.next == null) { |
| this.tail = vtx.prev; |
| } else { |
| vtx.next.prev = vtx.prev; |
| } |
| } |
| |
| /** |
| * Deletes a chain of vertices from this list. |
| */ |
| public void delete(Vertex vtx1, Vertex vtx2) { |
| if (vtx1.prev == null) { |
| this.head = vtx2.next; |
| } else { |
| vtx1.prev.next = vtx2.next; |
| } |
| if (vtx2.next == null) { |
| this.tail = vtx1.prev; |
| } else { |
| vtx2.next.prev = vtx1.prev; |
| } |
| } |
| |
| /** |
| * Inserts a vertex into this list before another specificed vertex. |
| */ |
| public void insertBefore(Vertex vtx, Vertex next) { |
| vtx.prev = next.prev; |
| if (next.prev == null) { |
| this.head = vtx; |
| } else { |
| next.prev.next = vtx; |
| } |
| vtx.next = next; |
| next.prev = vtx; |
| } |
| |
| /** |
| * Returns the first element in this list. |
| */ |
| public Vertex first() { |
| return this.head; |
| } |
| |
| /** |
| * Returns true if this list is empty. |
| */ |
| public boolean isEmpty() { |
| return this.head == null; |
| } |
| } |