Search in sources :

Example 26 with Coord2D

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

the class PathDetailTest method testIntersectsRectangleReturnsTrueForRectangleThatEntersBoundingBox.

@Test
public void testIntersectsRectangleReturnsTrueForRectangleThatEntersBoundingBox() {
    PathDetail pathDetail = new PathDetail(Coord2D.ORIGIN, Colour.BLACK);
    pathDetail.lineTo(new Coord2D(1.5, 1.5));
    Assert.assertTrue(pathDetail.intersectsRectangle(new Coord2D(1, 1), new Coord2D(2, 2)));
}
Also used : Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Test(org.junit.Test)

Example 27 with Coord2D

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

the class GraphView method drawSketch.

private void drawSketch(Canvas canvas, Sketch sketch, int alpha) {
    for (PathDetail pathDetail : sketch.getPathDetails()) {
        if (!couldBeOnScreen(pathDetail)) {
            continue;
        }
        List<Coord2D> path = pathDetail.getPath();
        Coord2D from = null;
        for (Coord2D point : path) {
            if (from == null) {
                from = surveyCoordsToViewCoords(point);
                continue;
            } else {
                Coord2D to = surveyCoordsToViewCoords(point);
                drawPaint.setColor(pathDetail.getColour().intValue);
                drawPaint.setAlpha(alpha);
                canvas.drawLine((float) from.getX(), (float) from.getY(), (float) to.getX(), (float) to.getY(), drawPaint);
                from = to;
            }
        }
    }
    for (TextDetail textDetail : sketch.getTextDetails()) {
        Coord2D location = surveyCoordsToViewCoords(textDetail.getPosition());
        String text = textDetail.getText();
        labelPaint.setColor(textDetail.getColour().intValue);
        canvas.drawText(text, (float) location.getX(), (float) location.getY(), labelPaint);
    }
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 28 with Coord2D

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

the class GraphView method drawStations.

private void drawStations(Survey survey, Canvas canvas, Space<Coord2D> space, int alpha) {
    stationPaint.setAlpha(alpha);
    int crossDiameter = PreferenceAccess.getInt(this.getContext(), "pref_station_diameter", CROSS_DIAMETER);
    for (Map.Entry<Station, Coord2D> entry : space.getStationMap().entrySet()) {
        Station station = entry.getKey();
        Coord2D translatedStation = surveyCoordsToViewCoords(entry.getValue());
        int x = (int) (translatedStation.getX());
        int y = (int) (translatedStation.getY());
        drawStationCross(canvas, stationPaint, x, y, crossDiameter, alpha);
        if (station == survey.getActiveStation()) {
            highlightActiveStation(canvas, x, y);
        }
        int spacing = crossDiameter / 2;
        int nextX = x + crossDiameter;
        if (getDisplayPreference(GraphActivity.DisplayPreference.SHOW_STATION_LABELS)) {
            String name = station.getName();
            if (station == survey.getOrigin()) {
                name = name + " (" + survey.getName() + ")";
            }
            canvas.drawText(name, nextX, y + STATION_LABEL_OFFSET, stationPaint);
            nextX += stationPaint.measureText(name) + spacing;
        }
        List<Bitmap> icons = new LinkedList<>();
        if (station.hasComment()) {
            icons.add(commentIcon);
        }
        if (survey.hasLinkedSurveys(station)) {
            icons.add(linkIcon);
        }
        for (Bitmap icon : icons) {
            int yTop = y - crossDiameter / 2;
            Rect rect = new Rect(nextX, yTop, nextX + crossDiameter, yTop + crossDiameter);
            canvas.drawBitmap(icon, null, rect, stationPaint);
            nextX += crossDiameter + spacing;
        }
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Map(java.util.Map) HashMap(java.util.HashMap) Paint(android.graphics.Paint) LinkedList(java.util.LinkedList)

Example 29 with Coord2D

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

the class GraphView method handleMove.

private boolean handleMove(MotionEvent event) {
    Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
    switch(event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            actionDownPointOnView = touchPointOnView;
            actionDownViewpointOffset = viewpointOffset;
            break;
        case MotionEvent.ACTION_MOVE:
            Coord2D surveyDelta = touchPointOnView.minus(actionDownPointOnView).scale(1 / surveyToViewScale);
            viewpointOffset = actionDownViewpointOffset.minus(surveyDelta);
            invalidate();
        // fall through
        case MotionEvent.ACTION_UP:
            break;
        default:
            return false;
    }
    return true;
}
Also used : Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 30 with Coord2D

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

the class GraphView method handlePositionCrossSection.

private boolean handlePositionCrossSection(MotionEvent event) {
    Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
    Coord2D touchPointOnSurvey = viewCoordsToSurveyCoords(touchPointOnView);
    final Station station = survey.getActiveStation();
    CrossSection crossSection = CrossSectioner.section(survey, station);
    sketch.addCrossSection(crossSection, touchPointOnSurvey);
    setSketchTool(previousSketchTool);
    invalidate();
    return true;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection)

Aggregations

Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)40 Station (org.hwyl.sexytopo.model.survey.Station)10 Space (org.hwyl.sexytopo.model.graph.Space)8 Line (org.hwyl.sexytopo.model.graph.Line)6 PathDetail (org.hwyl.sexytopo.model.sketch.PathDetail)6 Survey (org.hwyl.sexytopo.model.survey.Survey)6 Test (org.junit.Test)6 Leg (org.hwyl.sexytopo.model.survey.Leg)5 Colour (org.hwyl.sexytopo.model.sketch.Colour)4 ArrayList (java.util.ArrayList)3 GraphActivity (org.hwyl.sexytopo.control.activity.GraphActivity)3 PlanActivity (org.hwyl.sexytopo.control.activity.PlanActivity)3 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)3 Paint (android.graphics.Paint)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 CrossSection (org.hwyl.sexytopo.model.sketch.CrossSection)2 CrossSectionDetail (org.hwyl.sexytopo.model.sketch.CrossSectionDetail)2 TextDetail (org.hwyl.sexytopo.model.sketch.TextDetail)2 JSONArray (org.json.JSONArray)2