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