Search in sources :

Example 66 with Leg

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

the class SurveyUpdater method reverseLeg.

public static void reverseLeg(final Survey survey, final Station toReverse) {
    Log.d("Reversing leg to " + toReverse.getName());
    SurveyTools.traverseLegs(survey, (origin, leg) -> {
        if (leg.hasDestination() && leg.getDestination() == toReverse) {
            Leg reversed = leg.reverse();
            Log.d("Reversed direction of leg " + leg + " to " + reversed);
            origin.getOnwardLegs().remove(leg);
            origin.addOnwardLeg(reversed);
            survey.replaceLegInRecord(leg, reversed);
            return true;
        } else {
            return false;
        }
    });
    survey.setSaved(false);
}
Also used : Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 67 with Leg

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

the class SurveyUpdater method averageLegs.

public static Leg averageLegs(List<Leg> repeats) {
    int count = repeats.size();
    float distance = 0.0f, inclination = 0.0f;
    float[] azimuths = new float[count];
    for (int i = 0; i < count; i++) {
        Leg leg = repeats.get(i);
        distance += leg.getDistance();
        inclination += leg.getInclination();
        azimuths[i] = leg.getAzimuth();
    }
    distance /= count;
    inclination /= count;
    return new Leg(distance, averageAzimuths(azimuths), inclination);
}
Also used : Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 68 with Leg

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

the class SurveyUpdater method createNewStationIfBacksight.

private static boolean createNewStationIfBacksight(Survey survey) {
    // Examine splays of the current active station to determine if the previous two were a
    // foreward and backsight; if so, promote to a new named station
    Station activeStation = survey.getActiveStation();
    List<Leg> activeLegs = activeStation.getOnwardLegs();
    if (activeLegs.size() < 2) {
        return false;
    }
    List<Leg> lastPair = survey.getLastNLegs(2);
    if (lastPair.size() < 2) {
        return false;
    }
    for (Leg leg : lastPair) {
        if (!activeLegs.contains(leg)) {
            return false;
        }
    }
    Leg fore = lastPair.get(lastPair.size() - 2);
    // TODO: check for "reverse mode" to see if backsight comes first?
    Leg back = lastPair.get(lastPair.size() - 1);
    if (areLegsBacksights(fore, back)) {
        Station newStation = new Station(getNextStationName(survey));
        newStation.setExtendedElevationDirection(activeStation.getExtendedElevationDirection());
        Leg newLeg = averageBacksights(fore, back);
        newLeg = Leg.manuallyUpgradeSplayToConnectedLeg(newLeg, newStation);
        survey.undoAddLeg();
        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 69 with Leg

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

the class SurveyUpdater method areLegsAboutTheSame.

private static boolean areLegsAboutTheSame(List<Leg> legs) {
    for (Leg leg : legs) {
        // full legs must be unique by definition
        if (leg.hasDestination()) {
            return false;
        }
    }
    float minDistance = Float.POSITIVE_INFINITY, maxDistance = Float.NEGATIVE_INFINITY;
    float minAzimuth = Float.POSITIVE_INFINITY, maxAzimuth = Float.NEGATIVE_INFINITY;
    float minInclination = Float.POSITIVE_INFINITY, maxInclination = Float.NEGATIVE_INFINITY;
    for (Leg leg : legs) {
        minDistance = Math.min(leg.getDistance(), minDistance);
        maxDistance = Math.max(leg.getDistance(), maxDistance);
        minAzimuth = Math.min(leg.getAzimuth(), minAzimuth);
        maxAzimuth = Math.max(leg.getAzimuth(), maxAzimuth);
        minInclination = Math.min(leg.getInclination(), minInclination);
        maxInclination = Math.max(leg.getInclination(), maxInclination);
    }
    float distanceDiff = maxDistance - minDistance;
    float azimuthDiff = maxAzimuth - minAzimuth;
    float inclinationDiff = maxInclination - minInclination;
    float maxDistanceDelta = getMaxDistanceDelta();
    float maxAngleDelta = getMaxAngleDelta();
    return distanceDiff <= maxDistanceDelta && azimuthDiff <= maxAngleDelta && inclinationDiff <= maxAngleDelta;
}
Also used : Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 70 with Leg

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

the class SurveyUpdater method deleteStation.

public static void deleteStation(final Survey survey, final Station toDelete) {
    if (toDelete == survey.getOrigin()) {
        return;
    }
    Leg referringLeg = survey.getReferringLeg(toDelete);
    survey.removeLegRecord(referringLeg);
    SurveyTools.traverseLegs(survey, (origin, leg) -> {
        if (leg.hasDestination() && leg.getDestination() == toDelete) {
            origin.getOnwardLegs().remove(leg);
            survey.checkSurveyIntegrity();
            return true;
        } else {
            return false;
        }
    });
    survey.setSaved(false);
}
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