
org.jeometry.simple.geom3D.primitive.SimpleLineSet3D Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jeometry-simple Show documentation
Show all versions of jeometry-simple Show documentation
Jeometry, a Mathematic and Geometry library for Java
The newest version!
package org.jeometry.simple.geom3D.primitive;
import java.util.ArrayList;
import java.util.List;
import org.jeometry.Jeometry;
import org.jeometry.geom3D.point.Point3D;
import org.jeometry.geom3D.point.Point3DContainer;
import org.jeometry.geom3D.primitive.Line3D;
import org.jeometry.geom3D.primitive.LineSet3D;
/**
* A simple implementation of the {@link LineSet3D} interface.
* @param The type of the underlying 3D points
* @author Julien Seinturier - COMEX S.A. - [email protected] - https://github.com/jorigin/jeometry
* @version {@value Jeometry#version} build {@value Jeometry#BUILD}
* @since 1.0.0
*
*/
public class SimpleLineSet3D implements LineSet3D{
/**
* The serial version UID.
*/
private static final long serialVersionUID = Jeometry.BUILD;
/** The points of lines composing the line set. The order of the points is very important as it's
* specify how the lines are created
*/
private Point3DContainer points;
/**
* The segment representing each line of the line set.
*/
private ArrayList> segments;
@Override
public Point3DContainer getVertices(){
return points;
}
/**
* Set the {@link Point3DContainer 3D points} that compose this line set. Every successive pair of points compose a line.
* @param points {@link Point3DContainer 3D points} that compose this line set.
*/
public void setVertices(Point3DContainer points){
this.points = points;
segments = new ArrayList>();
if ((points != null) && (points.size() > 1)){
for(int i = 0; i < points.size() - 1; i++){
segments.add(new SimpleLine3D(points.get(i), points.get(i+1)));
}
}
}
@Override
public List> getSegments(){
return segments;
}
@Override
public void plot(T point) {
int lastPointIndex = points.size() - 1;
points.add(point);
if (lastPointIndex >= 0) {
segments.add(new SimpleLine3D(points.get(lastPointIndex), points.get(lastPointIndex + 1)));
}
}
@Override
public String toString(){
String str = "";
Point3D pt = null;
if ((points == null) || (points.size() < 1)){
str = getClass().getSimpleName()+" [ No vertex ]";
} else {
str = getClass().getSimpleName()+" ("+points.size()+" points) [";
for(int i = 0; i < points.size()- 1; i++){
pt = points.get(i);
str +=" ("+pt.getX()+", "+pt.getY()+", "+pt.getZ()+"),";
}
pt = points.get(points.size() - 1);
str +=" ("+pt.getX()+", "+pt.getY()+", "+pt.getZ()+") ]";
}
return str;
}
/**
* Construct a new line set from a {@link Point3DContainer set of 3D points}. The lines are created following
* the order of the points.
* @param points {@link Point3DContainer 3D points} that compose this line set.
*/
public SimpleLineSet3D(Point3DContainer points){
setVertices(points);
}
/**
* Create a default line set 3D, with no line.
*/
public SimpleLineSet3D(){
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy