[menya] 1 new revision pushed by berger.max on 2009-08-06 09:45 GMT

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 6, 2009, 5:45:56 AM8/6/09
to menya...@googlegroups.com
Revision: 1b7616e3ba
Author: Max Berger <m...@berger.name>
Date: Thu Aug 6 02:45:34 2009
Log: Added basic smoothing algorithm
http://code.google.com/p/menya/source/detail?r=1b7616e3ba

Modified:
/src/main/java/menya/core/model/Curve.java
/src/main/java/menya/gui/SketchPane.java

=======================================
--- /src/main/java/menya/core/model/Curve.java Wed Aug 5 15:01:06 2009
+++ /src/main/java/menya/core/model/Curve.java Thu Aug 6 02:45:34 2009
@@ -53,6 +53,8 @@

private static final int THREE_DATA_POINTS = 6;

+ private static final float DISTANCE_THRESHOLD = 3.5f;
+
private final List<Point> path = new ArrayList<Point>();

/**
@@ -153,4 +155,27 @@
}
return bos.toByteArray();
}
-}
+
+ /**
+ * This method reduces the number of points in the curve.
+ * <p>
+ * TODO: extract functionality and provide external <a
+ *
href="http://en.wikipedia.org/wiki/Smooth_Operator">smooth-operators</a>.
+ * <p>
+ * TODO: This is a very basic smoothing algorithm.
+ */
+ public void smoothPath() {
+ Point prev = this.path.get(0);
+ // Never smooth first or last point!
+ for (int i = 1; i < this.path.size() - 1; i++) {
+ Point cur = this.path.get(i);
+ while (cur.distanceTo(prev) < Curve.DISTANCE_THRESHOLD
+ && i < this.path.size() - 1) {
+ this.path.remove(i);
+ cur = this.path.get(i);
+ System.out.println("Removing " + i);
+ }
+ prev = cur;
+ }
+ }
+}
=======================================
--- /src/main/java/menya/gui/SketchPane.java Wed Aug 5 15:01:06 2009
+++ /src/main/java/menya/gui/SketchPane.java Thu Aug 6 02:45:34 2009
@@ -177,7 +177,7 @@
return;
}
this.currentCurve.add(p);
- // TODO: Smooth Path
+ this.currentCurve.smoothPath();
this.activeLayer.addCurve(this.currentCurve);
this.currentCurve = null;
// TODO: Maybe erase path that was drawn during drag.

Reply all
Reply to author
Forward
0 new messages