1 package com.piro.bezier;
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.LinkedList;
6 import java.util.regex.Matcher;
7 import java.util.regex.Pattern;
9 import eu.mihosoft.vrl.v3d.Vector3d;
13 static final Matcher matchPoint = Pattern.compile(
"\\s*(\\d+)[^\\d]+(\\d+)\\s*").matcher(
"");
17 private ArrayList<Vector3d>
pointList =
new ArrayList<Vector3d>();
18 double resolution = 0.075;
39 final Matcher matchPathCmd = Pattern
40 .compile(
"([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)").matcher(list);
43 LinkedList<String> tokens =
new LinkedList<String>();
44 while (matchPathCmd.find()) {
45 tokens.addLast(matchPathCmd.group());
49 while (tokens.size() != 0) {
50 String curToken = tokens.removeFirst();
51 char initChar = curToken.charAt(0);
52 if ((initChar >=
'A' && initChar <=
'Z') || (initChar >=
'a' && initChar <=
'z')) {
55 tokens.addFirst(curToken);
75 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
79 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
84 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
90 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
96 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
101 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
108 for (
double i = resolution; i < 1; i += resolution) {
109 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
114 for (
double i = resolution; i < 1; i += resolution) {
115 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
120 for (
double i = resolution; i < 1; i += resolution) {
121 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
126 for (
double i = resolution; i < 1; i += resolution) {
127 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
133 for (
double i = resolution; i < 1; i += resolution) {
134 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
140 for (
double i = resolution; i < 1; i += resolution) {
141 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
146 for (
double i = resolution; i < 1; i += resolution) {
147 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
152 for (
double i = resolution; i < 1; i += resolution) {
153 pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
165 throw new RuntimeException(
"Invalid path element");
170 static protected float nextFloat(LinkedList<String> l) {
171 String s = l.removeFirst();
172 return Float.parseFloat(s);
182 interp = (float) 0.001;
184 interp = (float) 0.9999;
186 double curLength = path.curveLength * interp;
187 for (Iterator<Bezier> it = path.bezierSegs.iterator(); it.hasNext();) {
191 if (curLength < bezLength) {
192 double param = curLength / bezLength;
193 point = bez.eval(param);
197 curLength -= bezLength;
void curvetoQuadraticAbs(float x1, float y1, float x, float y)
void curvetoCubicSmoothRel(float x2, float y2, float x, float y)
void linetoHorizontalAbs(float x)
void curvetoCubicRel(float x1, float y1, float x2, float y2, float x, float y)
void linetoRel(float x, float y)
void linetoHorizontalRel(float x)
void curvetoCubicSmoothAbs(float x2, float y2, float x, float y)
void linetoVerticalAbs(float y)
void movetoAbs(float x, float y)
void curvetoCubicAbs(float x1, float y1, float x2, float y2, float x, float y)
void movetoRel(float x, float y)
void linetoAbs(float x, float y)
void curvetoQuadraticSmoothRel(float x, float y)
void curvetoQuadraticSmoothAbs(float x, float y)
ArrayList< Vector3d > pointList
void parsePathList(String list)
void parsePathString(String d)
static float nextFloat(LinkedList< String > l)
ArrayList< Vector3d > evaluate()
Vector3d eval(float interp)