Search in sources :

Example 6 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class XviImporterTest method testParseSketchEntryParsesSecondEntry.

@Test
public void testParseSketchEntryParsesSecondEntry() throws Exception {
    String simpleText = "blue 0 0 1 0";
    PathDetail pathDetail = XviImporter.parseSketchEntry(1, simpleText);
    Assert.assertEquals(new Coord2D(1, 0), pathDetail.getPath().get(1));
    Assert.assertEquals(2, pathDetail.getPath().size());
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Test(org.junit.Test)

Example 7 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class XviImporterTest method testParseSketchEntryFailsForUnknownFirstCommand.

@Test(expected = IllegalArgumentException.class)
public void testParseSketchEntryFailsForUnknownFirstCommand() throws Exception {
    String simpleText = "connect 0 0";
    PathDetail pathDetail = XviImporter.parseSketchEntry(1, simpleText);
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Test(org.junit.Test)

Example 8 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class PocketTopoTxtImporter method parsePolylines.

public static List<PathDetail> parsePolylines(String text, Coord2D offset) {
    List<PathDetail> paths = new ArrayList<>();
    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());
            currentPathColour = interpretColour(colourText);
            inPolyline = true;
            continue;
        }
        if (!inPolyline) {
            continue;
        }
        String[] coords = line.split("\t");
        float x = Float.parseFloat(coords[0]) - offset.x;
        float y = Float.parseFloat(coords[1]) - offset.y;
        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;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) ArrayList(java.util.ArrayList) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) BrushColour(org.hwyl.sexytopo.model.sketch.BrushColour) Colour(org.hwyl.sexytopo.model.sketch.Colour)

Example 9 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class PocketTopoTxtImporter method parseSketch.

private static Sketch parseSketch(Survey survey, String text, Space<Coord2D> projection) {
    Sketch sketch = new Sketch();
    Coord2D offset = extractOffset(survey, text, projection);
    List<PathDetail> pathDetails = parsePolylines(text, offset);
    sketch.setPathDetails(pathDetails);
    return sketch;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 10 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class XviImporter method parseSketchEntry.

public static PathDetail parseSketchEntry(double scale, String entry) throws IllegalArgumentException {
    List<String> tokens = Arrays.asList(entry.split(" "));
    if (tokens.size() <= 1) {
        throw new IllegalArgumentException("Incomplete token? {" + entry + "}");
    }
    String first = tokens.get(0);
    if (first.equals("connect")) {
        throw new IllegalArgumentException("Not sure what to do with token {" + entry + "}");
    }
    if (tokens.size() % 2 != 1) {
        throw new IllegalArgumentException("There was an odd number of data points in the token (excluding first item): " + tokens.size());
    }
    Colour colour = Colour.valueOf(first.toUpperCase());
    List<Coord2D> points = new ArrayList<>(tokens.size() - 1);
    for (int i = 1; i < tokens.size(); ) {
        float x = Float.parseFloat(tokens.get(i++));
        float y = Float.parseFloat(tokens.get(i++));
        x /= scale;
        y /= scale;
        Coord2D coord2D = new Coord2D(x, -y);
        points.add(coord2D);
    }
    PathDetail pathDetail = new PathDetail(points.get(0), colour);
    for (Coord2D point : points.subList(1, points.size())) {
        pathDetail.lineTo(point);
    }
    return pathDetail;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) ArrayList(java.util.ArrayList) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Colour(org.hwyl.sexytopo.model.sketch.Colour)

Aggregations

PathDetail (org.hwyl.sexytopo.model.sketch.PathDetail)19 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Colour (org.hwyl.sexytopo.model.sketch.Colour)5 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)5 SymbolDetail (org.hwyl.sexytopo.model.sketch.SymbolDetail)3 TextDetail (org.hwyl.sexytopo.model.sketch.TextDetail)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 BrushColour (org.hwyl.sexytopo.model.sketch.BrushColour)2 CrossSectionDetail (org.hwyl.sexytopo.model.sketch.CrossSectionDetail)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 HashSet (java.util.HashSet)1 List (java.util.List)1 GraphActivity (org.hwyl.sexytopo.control.activity.GraphActivity)1 PlanActivity (org.hwyl.sexytopo.control.activity.PlanActivity)1 Space (org.hwyl.sexytopo.model.graph.Space)1