Permalink
Browse files

Convert line angle node to Java.

  • Loading branch information...
1 parent 98b2580 commit 1326fa185deb89bdcc35cf9d9e016c3657c82dd7 @fdb fdb committed Jun 6, 2012
Showing with 30 additions and 5 deletions.
  1. +2 −2 libraries/corevector/corevector.ndbx
  2. +28 −3 src/java/nodebox/function/CoreVectorFunctions.java
@@ -189,10 +189,10 @@
<port type="point" name="point2" value="100,100"/>
</node>
- <node function="pyvector/line_angle" name="line_angle" image="line_angle.png" outputType="geometry"
+ <node function="corevector/lineAngle" name="line_angle" image="line_angle.png" outputType="geometry"
position="180,180"
prototype="generator" description="Draw a line between a point and angle and distance."
- handle="pyvector/handle_rotate">
+ handle="corevector/lineAngleHandle">
<port type="point" name="position" value="0,0"/>
<port type="float" name="angle" value="0.0"/>
<port type="float" name="distance" value="100.0"/>
@@ -9,6 +9,7 @@
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
+import static nodebox.function.MathFunctions.coordinates;
/**
* Core vector function library.
@@ -20,9 +21,9 @@
static {
LIBRARY = JavaLibrary.ofClass("corevector", CoreVectorFunctions.class,
"generator", "filter",
- "align", "arc", "centroid", "colorize", "connect", "ellipse", "freehand", "grid", "line", "rect",
- "toPoints", "valuesToPoint",
- "fourPointHandle", "freehandHandle", "lineHandle", "pointHandle");
+ "align", "arc", "centroid", "colorize", "connect", "ellipse", "freehand", "grid", "line", "lineAngle",
+ "rect", "toPoints", "valuesToPoint",
+ "fourPointHandle", "freehandHandle", "lineHandle", "pointHandle", "lineAngleHandle");
}
/**
@@ -315,6 +316,23 @@ public static Path line(Point p1, Point p2) {
}
/**
+ * Create a line at the given starting point with the end point calculated by the angle and distance.
+ *
+ * @param point The starting point of the line.
+ * @param angle The angle of the line.
+ * @param distance The distance of the line.
+ * @return A new line.
+ */
+ public static Path lineAngle(Point point, double angle, double distance) {
+ Point p2 = coordinates(point, angle, distance);
+ Path p = new Path();
+ p.line(point.x, point.y, p2.x, p2.y);
+ p.setFill(null);
+ p.setStroke(Color.BLACK);
+ return p;
+ }
+
+ /**
* Create a rectangle.
*
* @param position The center position of the rectangle.
@@ -362,4 +380,11 @@ public static Handle pointHandle() {
return new PointHandle();
}
+ public static Handle lineAngleHandle() {
+ CombinedHandle handle = new CombinedHandle();
+ handle.addHandle(new PointHandle());
+ handle.addHandle(new RotateHandle("angle", "position"));
+ return handle;
+ }
+
}

0 comments on commit 1326fa1

Please sign in to comment.