Search in sources :

Example 1 with Line

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

the class GraphView method drawLegs.

private void drawLegs(Canvas canvas, Space<Coord2D> space, int baseAlpha) {
    boolean showSplays = getDisplayPreference(GraphActivity.DisplayPreference.SHOW_SPLAYS);
    boolean highlightLatestLeg = PreferenceAccess.getBoolean(getContext(), "pref_key_highlight_latest_leg", true);
    boolean fadingNonActive = getDisplayPreference(GraphActivity.DisplayPreference.FADE_NON_ACTIVE);
    Map<Leg, Line<Coord2D>> legMap = space.getLegMap();
    for (Leg leg : legMap.keySet()) {
        if (!showSplays && !leg.hasDestination()) {
            continue;
        }
        Line<Coord2D> line = legMap.get(leg);
        // noinspection ConstantConditions
        Coord2D start = surveyCoordsToViewCoords(line.getStart());
        Coord2D end = surveyCoordsToViewCoords(line.getEnd());
        if (!isLineOnCanvas(start, end)) {
            continue;
        }
        boolean fade = baseAlpha == FADED_ALPHA || (fadingNonActive && !isAttachedToActive(leg));
        Paint paint;
        if (highlightLatestLeg && survey.getMostRecentLeg() == leg) {
            paint = fade ? fadedLatestLegPaint : latestLegPaint;
        } else if (!leg.hasDestination()) {
            paint = fade ? fadedSplayPaint : splayPaint;
        } else {
            paint = fade ? fadedLegPaint : legPaint;
        }
        if (projectionType.isLegInPlane(leg)) {
            canvas.drawLine(start.x, start.y, end.x, end.y, paint);
        } else {
            drawDashedLine(canvas, start, end, DASHED_LINE_INTERVAL, paint);
        }
    }
}
Also used : Line(org.hwyl.sexytopo.model.graph.Line) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Paint(android.graphics.Paint) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 2 with Line

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

the class ExtendedElevationProjectionTest method testProject1MNorth1MEast.

@Test
public void testProject1MNorth1MEast() {
    Survey survey = BasicTestSurveyCreator.create5MEast();
    Space<Coord2D> space = Projection2D.EXTENDED_ELEVATION.project(survey);
    Map<Station, Coord2D> stationMap = space.getStationMap();
    Map<Leg, Line<Coord2D>> legMap = space.getLegMap();
    Station two = survey.getStationByName("2");
    Coord2D twoCoord = stationMap.get(two);
    Coord2D expected = new Coord2D(5, 0);
    Assert.assertEquals(expected, twoCoord);
    Leg splayLeft = two.getUnconnectedOnwardLegs().get(0);
    Line<Coord2D> splayLeftLine = legMap.get(splayLeft);
    expected = new Coord2D(5, 0);
    assert splayLeftLine != null;
    Assert.assertEquals(expected, splayLeftLine.getEnd());
    Leg splayRight = two.getUnconnectedOnwardLegs().get(1);
    Line<Coord2D> splayRightLine = legMap.get(splayRight);
    expected = new Coord2D(5, 0);
    assert splayRightLine != null;
    Assert.assertEquals(expected, splayRightLine.getEnd());
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Line(org.hwyl.sexytopo.model.graph.Line) Survey(org.hwyl.sexytopo.model.survey.Survey) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Leg(org.hwyl.sexytopo.model.survey.Leg) Test(org.junit.Test)

Example 3 with Line

use of org.hwyl.sexytopo.model.graph.Line 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<>(start.plus(point), end.plus(point));
}
Also used : Line(org.hwyl.sexytopo.model.graph.Line) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 4 with Line

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

the class Space3DTransformerForElevation method updateLeg.

protected void updateLeg(Space<Coord3D> space, Leg leg, Coord3D start) {
    Leg adjustedLeg;
    if (leg.getDestination().getExtendedElevationDirection() == Direction.LEFT) {
        adjustedLeg = leg.adjustAzimuth(180);
    } else {
        adjustedLeg = leg.adjustAzimuth(0);
    }
    float delta = adjustedLeg.getAzimuth() - leg.getAzimuth();
    Coord3D end = Space3DUtils.toCartesian(start, adjustedLeg);
    Line<Coord3D> line = new Line<>(start, end);
    space.addLeg(leg, line);
    if (leg.hasDestination()) {
        update(space, leg.getDestination(), end, delta);
    }
}
Also used : Line(org.hwyl.sexytopo.model.graph.Line) Coord3D(org.hwyl.sexytopo.model.graph.Coord3D) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 5 with Line

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

the class Space3DTransformerForElevation method updateSplay.

protected void updateSplay(Space<Coord3D> space, Leg leg, Coord3D start, float rotation) {
    Leg adjustedLeg = leg.rotate(rotation);
    Coord3D end = Space3DUtils.toCartesian(start, adjustedLeg);
    Line<Coord3D> line = new Line<>(start, end);
    space.addLeg(leg, line);
}
Also used : Line(org.hwyl.sexytopo.model.graph.Line) Coord3D(org.hwyl.sexytopo.model.graph.Coord3D) Leg(org.hwyl.sexytopo.model.survey.Leg)

Aggregations

Line (org.hwyl.sexytopo.model.graph.Line)10 Leg (org.hwyl.sexytopo.model.survey.Leg)8 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)7 Coord3D (org.hwyl.sexytopo.model.graph.Coord3D)4 Space (org.hwyl.sexytopo.model.graph.Space)4 Station (org.hwyl.sexytopo.model.survey.Station)4 Paint (android.graphics.Paint)1 Survey (org.hwyl.sexytopo.model.survey.Survey)1 Test (org.junit.Test)1