[wadalabfont-kit] / java / Bezier.java  

Annotation of /java/Bezier.java

Parent Directory | Revision Log

Revision: 1.2 - (view) (download) (as text)

1 : ktanaka 1.1 import java.util.*;
2 :    
3 :     public class Bezier extends OutlineComponent{
4 :     Point p0,p1,p2,p3;
5 :     public Bezier(Point p0,Point p1,Point p2,Point p3){
6 :     this.p0=p0; this.p1=p1; this.p2=p2; this.p3=p3;
7 :     }
8 :     public Bezier[] divide(){
9 :     Bezier[] ret=new Bezier[2];
10 :     Point midp=p0.inter(p3,0.5).inter(p1.inter(p2,0.5),0.75);
11 :     ret[0]=new Bezier(p0,p0.inter(p1,0.5),
12 :     p0.inter(p2,0.5).inter(p1,0.5),midp);
13 :     ret[1]=new Bezier(midp,p3.inter(p1,0.5).inter(p2,0.5),
14 :     p3.inter(p2,0.5),p3);
15 :     return ret;
16 :     }
17 :     public void render(Vector ret,double limit){
18 :     ret.addElement(p0);
19 :     if(p0.distance(p3)<limit){
20 :     ret.addElement(p3);
21 :     }
22 :     else{
23 :     Bezier[] div=divide();
24 :     div[0].render(ret,limit);
25 :     div[1].render(ret,limit);
26 :     }
27 :     }
28 : ktanaka 1.2 public OutlineComponent plus(Point point){
29 :     return new Bezier(p0.plus(point),p1.plus(point),p2.plus(point),p3.plus(point));
30 :     }
31 :     public OutlineComponent rot(double theta){
32 :     return new Bezier(p0.rot(theta),p1.rot(theta),p2.rot(theta),p3.rot(theta));
33 :     }
34 :     public OutlineComponent times(double ratio){
35 :     return new Bezier(p0.times(ratio),p1.times(ratio),p2.times(ratio),p3.times(ratio));
36 :     }
37 :     public OutlineComponent timesY(double ratio){
38 :     return new Bezier(p0.timesY(ratio),p1.timesY(ratio),p2.timesY(ratio),p3.timesY(ratio));
39 :     }
40 :     public Point firstPoint(){ return p0;}
41 :     public Point lastPoint(){ return p3;}
42 :     public String toString(){
43 :     return "Bezier("+p0+","+p1+","+p2+","+p3+")";
44 :     }
45 : ktanaka 1.1 }

ktanaka

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help