Search in sources :

Example 71 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class SurveyUpdater method createNewStationIfTripleShot.

private static boolean createNewStationIfTripleShot(Survey survey, boolean backsightMode) {
    int requiredNumber = SexyTopo.NUM_OF_REPEATS_FOR_NEW_STATION;
    Station activeStation = survey.getActiveStation();
    List<Leg> activeLegs = activeStation.getOnwardLegs();
    if (activeLegs.size() < requiredNumber) {
        return false;
    }
    List<Leg> lastNLegs = survey.getLastNLegs(requiredNumber);
    if (lastNLegs.size() < requiredNumber) {
        return false;
    }
    // check all the last legs are from the active station
    for (Leg leg : lastNLegs) {
        if (!activeLegs.contains(leg)) {
            return false;
        }
    }
    if (areLegsAboutTheSame(lastNLegs)) {
        Station newStation = new Station(getNextStationName(survey));
        newStation.setExtendedElevationDirection(activeStation.getExtendedElevationDirection());
        Leg newLeg = averageLegs(lastNLegs);
        newLeg = Leg.upgradeSplayToConnectedLeg(newLeg, newStation, lastNLegs.toArray(new Leg[] {}));
        if (backsightMode) {
            newLeg = newLeg.reverse();
        }
        for (int i = 0; i < requiredNumber; i++) {
            survey.undoAddLeg();
        }
        activeStation.getOnwardLegs().add(newLeg);
        survey.addLegRecord(newLeg);
        survey.setActiveStation(newStation);
        return true;
    }
    return false;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 72 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class SurveyUpdater method setDirectionOfSubtree.

public static void setDirectionOfSubtree(Station station, Direction direction) {
    station.setExtendedElevationDirection(direction);
    for (Leg leg : station.getConnectedOnwardLegs()) {
        Station destination = leg.getDestination();
        setDirectionOfSubtree(destination, direction);
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 73 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class Space2DUtils method transform.

@SuppressWarnings("ConstantConditions")
public static Space<Coord2D> transform(Space<Coord2D> space, Coord2D point) {
    Space<Coord2D> newSpace = new Space<>();
    Map<Station, Coord2D> stations = space.getStationMap();
    for (Station station : stations.keySet()) {
        Coord2D coord = stations.get(station);
        Coord2D newCoord = coord.plus(point);
        newSpace.addStation(station, newCoord);
    }
    Map<Leg, Line<Coord2D>> legs = space.getLegMap();
    for (Leg leg : legs.keySet()) {
        Line<Coord2D> line = legs.get(leg);
        Line<Coord2D> newLine = transformLine(line, point);
        newSpace.addLeg(leg, newLine);
    }
    return newSpace;
}
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 74 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class SurveyStats method calcShortestLeg.

public static float calcShortestLeg(Survey survey) {
    List<Leg> legs = survey.getAllLegs();
    if (legs.isEmpty()) {
        return 0;
    }
    float min = Float.POSITIVE_INFINITY;
    for (Leg leg : legs) {
        min = Math.min(leg.getDistance(), min);
    }
    return min;
}
Also used : Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 75 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class SurveyStats method calcTotalLength.

// This would all be so much easier with Java 8: lambdas, streaming API...
// TODO: rewrite when Android moves to Java 8
public static float calcTotalLength(Survey survey) {
    List<Leg> legs = survey.getAllLegs();
    float total = 0.0f;
    for (Leg leg : legs) {
        if (leg.hasDestination()) {
            total += leg.getDistance();
        }
    }
    return total;
}
Also used : Leg(org.hwyl.sexytopo.model.survey.Leg)

Aggregations

Leg (org.hwyl.sexytopo.model.survey.Leg)94 Station (org.hwyl.sexytopo.model.survey.Station)30 Test (org.junit.Test)30 Survey (org.hwyl.sexytopo.model.survey.Survey)23 Coord3D (org.hwyl.sexytopo.model.graph.Coord3D)17 Line (org.hwyl.sexytopo.model.graph.Line)8 ArrayList (java.util.ArrayList)7 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)7 JSONArray (org.json.JSONArray)6 JSONObject (org.json.JSONObject)6 Space (org.hwyl.sexytopo.model.graph.Space)4 TextView (android.widget.TextView)3 GraphToListTranslator (org.hwyl.sexytopo.control.util.GraphToListTranslator)3 TableCol (org.hwyl.sexytopo.model.table.TableCol)3 JSONException (org.json.JSONException)3 AlertDialog (android.app.AlertDialog)2 ParseException (java.text.ParseException)2 HashMap (java.util.HashMap)2 LRUD (org.hwyl.sexytopo.model.table.LRUD)2 SuppressLint (android.annotation.SuppressLint)1