source: josm/trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/ArrowPaintHelper.java@ 10875

Last change on this file since 10875 was 10875, checked in by Don-vip, 8 years ago

fix #13413 - Clean ImproveWayAccuracyAction, add new class MapViewPath (patch by michael2402, modified) - gsoc-core

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm.visitor.paint;
3
4import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
5import org.openstreetmap.josm.gui.draw.MapPath2D;
6import org.openstreetmap.josm.tools.Utils;
7
8/**
9 * This class helps with painting arrows with fixed length along a path.
10 * @author Michael Zangl
11 * @since 10827
12 */
13public class ArrowPaintHelper {
14 private final double sin;
15 private final double cos;
16 private final double length;
17
18 /**
19 * Creates a new arrow helper.
20 * @param radians The angle of the arrow. 0 means that it lies on the current line. In radians
21 * @param length The length of the arrow lines.
22 */
23 public ArrowPaintHelper(double radians, double length) {
24 this.sin = Math.sin(radians);
25 this.cos = Math.cos(radians);
26 this.length = length;
27 }
28
29 /**
30 * Paint the arrow
31 * @param path The path to append the arrow to.
32 * @param point The point to paint the tip at
33 * @param fromDirection The direction the line is comming from.
34 */
35 public void paintArrowAt(MapPath2D path, MapViewPoint point, MapViewPoint fromDirection) {
36 double x = point.getInViewX();
37 double y = point.getInViewY();
38 double dx = fromDirection.getInViewX() - x;
39 double dy = fromDirection.getInViewY() - y;
40 double norm = Math.sqrt(dx * dx + dy * dy);
41 if (norm > 1e-10) {
42 dx *= length / norm;
43 dy *= length / norm;
44 path.moveTo(x + dx * cos + dy * sin, y + dx * -sin + dy * cos);
45 if (!Utils.equalsEpsilon(cos, 0)) {
46 path.lineTo(point);
47 }
48 path.lineTo(x + dx * cos + dy * -sin, y + dx * sin + dy * cos);
49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.