Last active
September 27, 2017 00:05
-
-
Save busti/7b57037fe3ebde162c5bd7e6a7ff3da2 to your computer and use it in GitHub Desktop.
Reference implementation of a "collection" where elements are accessible by a positional offset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Path { | |
private List<Element> elements = new ArrayList<>(); | |
public class Element { | |
public double lenght; | |
} | |
public void addElement(Element element) { | |
elements.add(element); | |
} | |
public Element getElementAtOffset(double offset) { | |
double pos = 0; | |
for (Element element: elements) { | |
pos += element.lenght; | |
if (pos >= offset) | |
return element; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment