-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathPlus.java
91 lines (70 loc) · 2.42 KB
/
PathPlus.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package SwansonLibrary;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.graphics.Point;
import android.graphics.PointF;
/**
* Created by Brandon on 5/1/14.
*/
public class PathPlus extends Path {
private PathMeasure mPathMeasuere = new PathMeasure(this,false);
public PathMeasure measure(){return mPathMeasuere;}
private boolean isClosed=false;
private boolean isClosed(){return isClosed;}
public PathPlus() {
}
public PathPlus(Path src, boolean forceClosed) {
super(src);
isClosed=true;
}
public Path makeLine(Point start, Point end){
ViewTools.Line line = new ViewTools.Line(start,end);
return makeLine(line);
}
public PathPlus makeLine(ViewTools.Line line){
moveTo(line.start.x,line.start.y);
lineTo(line.end.x,line.end.y);
return this;
}
public PathPlus makeLine(PointF start, PointF end){
moveTo(start.x,start.y);
lineTo(end.x,end.y);
return this;
}
public static PathPlus textLine(Point start, Point end){
return textLine(new ViewTools.Line(start, end));
}
public static PathPlus textLine(ViewTools.Line line){
return new PathPlus().makeLine(line);
}
public static PathPlus textLine(PointF start, PointF end){
return new PathPlus().makeLine(start,end);
}
public static void getDrawableSegment(Path segment, Path dstPath){
getDrawableSegment(segment,dstPath,.1f);
}
public static void getDrawableSegment(Path segment, Path dstPath, float granularity){
dstPath.rewind();
PathMeasure pathMeasure = new PathMeasure(segment,false);
float length = pathMeasure.getLength();
ViewTools.PathPosition pathPosition = ViewTools.getPathPosition(pathMeasure,0);
dstPath.moveTo(pathPosition.position.x,pathPosition.position.y);
for(float distance=0;distance<=length;distance+=granularity){
pathPosition=ViewTools.getPathPosition(pathMeasure,distance);
dstPath.lineTo(pathPosition.position.x,pathPosition.position.y);
}
}
/*public void Close(){
if(isClosed) return;
float pos[] = new float[2];
float tan[] = new float[2];
mPathMeasuere.getPosTan(0,pos,tan);
lineTo(pos[0],pos[1]);
isClosed=true;
}*/
@Override
public void close(){
super.close();
isClosed=true;
}
}