use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.
the class PocketTopoTxtImporter method parseSketch.
private static Sketch parseSketch(String text) {
Sketch sketch = new Sketch();
Set<PathDetail> pathDetails = parsePolylines(text);
sketch.setPathDetails(pathDetails);
return sketch;
}
use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.
the class PocketTopoTxtImporter method parsePolylines.
public static Set<PathDetail> parsePolylines(String text) {
Set<PathDetail> paths = new HashSet<>();
boolean inPolyline = false;
Colour currentPathColour = null;
PathDetail currentPathDetail = null;
for (String line : TextTools.toArrayOfLines(text)) {
if (line.startsWith("POLYLINE")) {
if (inPolyline) {
paths.add(currentPathDetail);
currentPathDetail = null;
}
String colourText = line.substring("POLYLINE ".length());
if (colourText.equals("RED")) {
colourText = "PURPLE";
}
currentPathColour = Colour.valueOf(colourText);
inPolyline = true;
continue;
}
if (!inPolyline) {
continue;
}
String[] coords = line.split("\t");
double x = Double.parseDouble(coords[0]);
double y = Double.parseDouble(coords[1]);
Coord2D coord = new Coord2D(x, -y);
if (currentPathDetail == null) {
currentPathDetail = new PathDetail(coord, currentPathColour);
} else {
currentPathDetail.lineTo(coord);
}
}
if (currentPathDetail != null) {
paths.add(currentPathDetail);
}
return paths;
}
use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.
the class GraphView method handleErase.
private boolean handleErase(MotionEvent event) {
Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
Coord2D touchPointOnSurvey = viewCoordsToSurveyCoords(touchPointOnView);
boolean deleteLineFragments = PreferenceAccess.getBoolean(getContext(), "pref_delete_path_fragments", true);
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
SketchDetail closestDetail = sketch.findNearestDetailWithin(touchPointOnSurvey, DELETE_PATHS_WITHIN_N_PIXELS);
// you missed, try again :P
if (closestDetail == null) {
return true;
// you got part of the line
} else if (deleteLineFragments && closestDetail instanceof PathDetail) {
List<SketchDetail> fragments = ((PathDetail) closestDetail).getPathFragmentsOutsideRadius(touchPointOnSurvey, DELETE_PATHS_WITHIN_N_PIXELS / 4);
sketch.deleteDetail(closestDetail, fragments);
invalidate();
// bullseye!
} else {
sketch.deleteDetail(closestDetail);
invalidate();
}
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
break;
default:
return false;
}
return true;
}
use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.
the class PocketTopoTxtImporterTest method testParsePolylines.
@Test
public void testParsePolylines() {
String section = PocketTopoTxtImporter.getSection(FAKE_TEXT, "PLAN");
List<PathDetail> paths = PocketTopoTxtImporter.parsePolylines(section, Coord2D.ORIGIN);
PathDetail brownPath = null;
for (PathDetail path : paths) {
if (path.getColour() == Colour.BROWN) {
brownPath = path;
}
}
Assert.assertEquals(4.980, brownPath.getPath().get(0).x, 0.01);
Assert.assertEquals(55.180, brownPath.getPath().get(0).y, 0.01);
}
use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.
the class XviImporterTest method testParseSketchEntryParsesFirstEntry.
@Test
public void testParseSketchEntryParsesFirstEntry() throws Exception {
String simpleText = "red 0 0";
PathDetail pathDetail = XviImporter.parseSketchEntry(1, simpleText);
Assert.assertEquals(Coord2D.ORIGIN, pathDetail.getPath().get(0));
Assert.assertEquals(1, pathDetail.getPath().size());
}
Aggregations