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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations