Search in sources :

Example 16 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D 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(); ) {
        double x = Double.parseDouble(tokens.get(i++));
        double y = Double.parseDouble(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)

Example 17 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.

the class Space2DUtils method transformLine.

public static Line<Coord2D> transformLine(Line<Coord2D> line, Coord2D point) {
    Coord2D start = line.getStart();
    Coord2D end = line.getEnd();
    return new Line<Coord2D>(start.plus(point), end.plus(point));
}
Also used : Line(org.hwyl.sexytopo.model.graph.Line) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 18 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.

the class SpaceFlipper method flipVertically.

public static Space<Coord2D> flipVertically(Space<Coord2D> space) {
    Space<Coord2D> flippedSpace = new Space<>();
    Map<Station, Coord2D> stationMap = space.getStationMap();
    for (Station station : stationMap.keySet()) {
        Coord2D point = stationMap.get(station);
        flippedSpace.addStation(station, point.flipVertically());
    }
    Map<Leg, Line<Coord2D>> legMap = space.getLegMap();
    for (Leg leg : legMap.keySet()) {
        Line<Coord2D> line = legMap.get(leg);
        Coord2D start = line.getStart();
        Coord2D end = line.getEnd();
        Line flippedLine = new Line(start.flipVertically(), end.flipVertically());
        flippedSpace.addLeg(leg, flippedLine);
    }
    return flippedSpace;
}
Also used : Space(org.hwyl.sexytopo.model.graph.Space) Station(org.hwyl.sexytopo.model.survey.Station) Line(org.hwyl.sexytopo.model.graph.Line) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 19 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.

the class SpaceMover method move.

public static Space<Coord2D> move(Space<Coord2D> space, Coord2D delta) {
    Space moved = new Space<Coord2D>();
    Map<Station, Coord2D> stationMap = space.getStationMap();
    for (Station station : stationMap.keySet()) {
        Coord2D point = stationMap.get(station);
        moved.addStation(station, point.plus(delta));
    }
    Map<Leg, Line<Coord2D>> legMap = space.getLegMap();
    for (Leg leg : legMap.keySet()) {
        Line<Coord2D> line = space.getLegMap().get(leg);
        Line<Coord2D> shiftedLine = new Line<>(line.getStart().plus(delta), line.getEnd().plus(delta));
        moved.addLeg(leg, shiftedLine);
    }
    return moved;
}
Also used : Space(org.hwyl.sexytopo.model.graph.Space) Station(org.hwyl.sexytopo.model.survey.Station) Line(org.hwyl.sexytopo.model.graph.Line) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 20 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.

the class CrossSection method getProjection.

public Space<Coord2D> getProjection() {
    Space<Coord2D> projection = new Space<>();
    projection.addStation(station, Coord2D.ORIGIN);
    for (Leg leg : station.getUnconnectedOnwardLegs()) {
        // first of all normalise to match the angle of the cross section
        Leg rotated = leg.rotate(-angle);
        Coord3D coord3D = transformer.transform(Coord3D.ORIGIN, rotated);
        Coord2D coord2D = new Coord2D(coord3D.getX(), coord3D.getZ());
        Line<Coord2D> line = new Line<>(Coord2D.ORIGIN, coord2D);
        projection.addLeg(rotated, line);
    }
    return projection;
}
Also used : Space(org.hwyl.sexytopo.model.graph.Space) Line(org.hwyl.sexytopo.model.graph.Line) Coord3D(org.hwyl.sexytopo.model.graph.Coord3D) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Leg(org.hwyl.sexytopo.model.survey.Leg)

Aggregations

Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)40 Station (org.hwyl.sexytopo.model.survey.Station)10 Space (org.hwyl.sexytopo.model.graph.Space)8 Line (org.hwyl.sexytopo.model.graph.Line)6 PathDetail (org.hwyl.sexytopo.model.sketch.PathDetail)6 Survey (org.hwyl.sexytopo.model.survey.Survey)6 Test (org.junit.Test)6 Leg (org.hwyl.sexytopo.model.survey.Leg)5 Colour (org.hwyl.sexytopo.model.sketch.Colour)4 ArrayList (java.util.ArrayList)3 GraphActivity (org.hwyl.sexytopo.control.activity.GraphActivity)3 PlanActivity (org.hwyl.sexytopo.control.activity.PlanActivity)3 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)3 Paint (android.graphics.Paint)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 CrossSection (org.hwyl.sexytopo.model.sketch.CrossSection)2 CrossSectionDetail (org.hwyl.sexytopo.model.sketch.CrossSectionDetail)2 TextDetail (org.hwyl.sexytopo.model.sketch.TextDetail)2 JSONArray (org.json.JSONArray)2