darwin.util.math.composits.Path Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package darwin.util.math.composits;
import java.util.*;
import darwin.util.math.base.vector.Vector;
/**
*
* @author daniel
*/
public class Path> implements Iterable {
private final List positions = new ArrayList<>();
public void addPathElement(E position) {
if (!positions.contains(position)) {
positions.add(position);
}
}
public int size() {
return positions.size();
}
public Iterator> getLineSegmentIterator() {
return new Iterator>() {
Iterator iter = positions.iterator();
E prev, next = iter.next();
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public LineSegment next() {
prev = next;
next = iter.next();
return new LineSegment(prev, next);
}
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet.");
}
};
}
public Iterable> getLineSegmentIterable() {
return new Iterable>() {
@Override
public Iterator> iterator() {
return getLineSegmentIterator();
}
};
}
public LineSegment getClosingSegment() {
return new LineSegment<>(positions.get(positions.size() - 1), positions.get(0));
}
@Override
public Iterator iterator() {
return positions.iterator();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy