static Point on(Point from, Point to, double dist) { final double length = PointUtil.length(from, to); final double ratio = dist / length; final double invRatio = 1 - ratio; final double x = to.x * ratio + invRatio * from.x; final double y = to.y * ratio + invRatio * from.y; return new Point(x, y); }
if (PointUtil.length(e) > SHORT_CONNECTION_LENGTH * vehicleLength) { final Point start1 = PointUtil.on(e, vehicleLength); final Point end1 = PointUtil.on(e, vehicleLength + arrowDimensions.y * 2); adapter.drawArrow(start1, end1, arrowDimensions.x, arrowDimensions.y); final Point start2 = PointUtil.on(e.to(), e.from(), vehicleLength + arrowDimensions.y * 2); final Point end2 = PointUtil.on(e.to(), e.from(), vehicleLength); adapter.drawArrow(start2, end2, arrowDimensions.x, arrowDimensions.y); } else { final double center = PointUtil.length(e) / 2d; final Point start1 = PointUtil.on(e, center - arrowDimensions.y); final Point end1 = PointUtil.on(e, center + arrowDimensions.y); adapter.drawArrow(start1, end1, arrowDimensions.x, arrowDimensions.y); final double length = PointUtil.length(e); final Point a = PointUtil.perp(e, vehicleLength, halfRoadWidth); final Point b = PointUtil.perp(e, length - vehicleLength, halfRoadWidth); adapter.drawLine(a, b); final Point c = PointUtil.perp(e, vehicleLength, -halfRoadWidth); final Point d = PointUtil.perp(e, length - vehicleLength, -halfRoadWidth); adapter.drawLine(c, d);
final Point c1 = PointUtil.perp(p, n, -vehicleLength, -halfRoadWidth); final Point c2 = PointUtil.perp(p, n, -vehicleLength, halfRoadWidth); final Point o1 = PointUtil.perp(p, n, vehicleLength, -halfRoadWidth); final Point o2 = PointUtil.perp(p, n, vehicleLength, halfRoadWidth); adapter.setForegroundSysCol(SWT.COLOR_GRAY); adapter.drawPolyline(o1, c1, c2, o2); break; final Point a = PointUtil.perp(p, n, vehicleLength, -halfRoadWidth); final Point a2 = PointUtil .perp(p, n, vehicleLength + 1, -halfRoadWidth); final Point b = PointUtil.perp(p, it.peek(), vehicleLength, halfRoadWidth); final Point b2 = PointUtil.perp(p, it.peek(), vehicleLength + 1, halfRoadWidth); final Optional<Point> intersect = PointUtil.intersectionPoint(a, a2, b, b2);
static Point on(Connection<?> conn, double dist) { return PointUtil.on(conn.from(), conn.to(), dist); }
static Point unit(Point from, Point to) { return normalize(Point.diff(from, to)); }
static Point perp(Connection<?> conn, double distOnLine, double distFromLine) { return PointUtil.perp(conn.from(), conn.to(), distOnLine, distFromLine); }
static Point unit(Connection<?> conn) { return unit(conn.from(), conn.to()); }
void drawArrow(Point from, Point to, int width, int height) { final double w = vp.get().invScale(width); final double h = vp.get().invScale(height); final Point left = PointUtil.perp(to, from, h, w / 2d); final Point right = PointUtil.perp(to, from, h, -w / 2d); drawLine(from, PointUtil.on(from, to, h)); fillPolygon(left, right, to); }
@Override public void renderDynamic(GC gc, ViewPort vp, long time) { helper.adapt(gc, vp); if (showRelativeSpeedDynamic) { final Set<Connection<? extends ConnectionData>> set = ImmutableSet.copyOf(updatedConnections); for (final Connection<? extends ConnectionData> e : set) { final double dist = Point.distance(e.from(), e.to()); final Point f = PointUtil.on(e, dist * ARROW_REL_FROM_TO.x); final Point t = PointUtil.on(e, dist * ARROW_REL_FROM_TO.y); final MultiAttributeData data = (MultiAttributeData) e.data().get(); final double ratio = data.getMaxSpeed().get() / Double.parseDouble((String) data.getAttributes().get("ts")); final Color color = new Color(gc.getDevice(), (int) Math.max(Math.min(-510 * ratio + 510, 255), 0), (int) Math.max(Math.min(510 * ratio, 255), 0), 0); helper.setBackgroundSysCol(color); helper.drawArrow(f, t, ARROW_HEAD_SIZE, ARROW_HEAD_SIZE); color.dispose(); } // updatedConnections.clear(); } }
@Override public Optional<ViewRect> getViewRect() { checkState(!model.getGraph().isEmpty(), "graph may not be empty at this point"); final List<Point> extremes = Graphs.getExtremes(model.getGraph()); return Optional.of(new ViewRect( PointUtil.sub(extremes.get(0), margin), PointUtil.add(extremes.get(1), margin))); }
static double angle(Connection<?> connection) { return angle(connection.from(), connection.to()); }
static Point normalize(Point p) { return Point.divide(p, PointUtil.length(p)); }
final Point f = PointUtil.on(e, dist * ARROW_REL_FROM_TO.x); final Point t = PointUtil.on(e, dist * ARROW_REL_FROM_TO.y); helper.setBackgroundSysCol(SWT.COLOR_GRAY); helper.drawArrow(f, t, ARROW_HEAD_SIZE, ARROW_HEAD_SIZE); final Point f = PointUtil.on(e, dist * ARROW_REL_FROM_TO.x); final Point t = PointUtil.on(e, dist * ARROW_REL_FROM_TO.y); final MultiAttributeData data = (MultiAttributeData) e.data().get(); final double ratio =
angle = angle(conn.get());
static double length(Connection<?> conn) { return length(conn.from(), conn.to()); }