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