Skip to content

Commit 90825cd

Browse files
committed
clean up dirts
1 parent 095441f commit 90825cd

14 files changed

Lines changed: 1629 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

src/hk/microos/data/Flags.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package hk.microos.data;
2+
3+
public class Flags {
4+
public static boolean GLOABAL_DEBUG = true;
5+
public static boolean FUNC_INVOKE_PRINT = true;
6+
public static double minStroke = 2;
7+
public static double maxStroke = 5;
8+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package hk.microos.data;
2+
3+
import java.util.ArrayList;
4+
5+
import hk.microos.tools.UniversalTool;
6+
7+
public class LinearLine {
8+
private boolean vertical = false;
9+
private boolean horizontal = false;
10+
public double k, b;
11+
12+
public LinearLine(double k, double b) {
13+
this.k = k;
14+
this.b = b;
15+
}
16+
17+
public LinearLine(double k, double b, boolean vertical, boolean horizontal) {
18+
this.k = k;
19+
this.b = b;
20+
this.vertical = vertical;
21+
this.horizontal = horizontal;
22+
}
23+
24+
public LinearLine(Point_ a, Point_ b) {
25+
if (Math.abs(a.y-b.y) < 0.0000001) {
26+
horizontal = true;
27+
}else if (Math.abs(a.x-b.x) < 0.0000001) {
28+
vertical = true;
29+
} else {
30+
this.k = (a.y - b.y) / (a.x - b.x);
31+
this.b = a.y - this.k * a.x;
32+
}
33+
}
34+
public double calY(double X){
35+
return this.k*X+b;
36+
}
37+
public double calX(double Y){
38+
return (Y-this.b)/this.k;
39+
}
40+
public Point_ projectOnLine(double x0, double y0, int minX, int minY, int maxX, int maxY){
41+
if(this.vertical){
42+
return new Point_(this.b, y0);
43+
}
44+
if(this.horizontal){
45+
return new Point_(x0, this.b);
46+
}
47+
Point_ p = Math.abs(this.k) < 1?new Point_(x0, this.calY(x0)): new Point_(this.calX(y0),y0);
48+
if(UniversalTool.inBound(p, minX, minY, maxX, maxY)){
49+
return p;
50+
}else{
51+
double imgTan = (maxY-minY)/(maxX-minX);
52+
Point_ intersect1, intersect2;
53+
if(Math.abs(this.k) >= imgTan){
54+
intersect1 = new Point_(this.calX(minY),minY);
55+
intersect2 = new Point_(this.calX(maxY),maxY);
56+
}else{
57+
intersect1 = new Point_(minX, calY(minX));
58+
intersect2 = new Point_(maxX, calY(maxX));
59+
}
60+
return (UniversalTool.distance(p,intersect1) < UniversalTool.distance(p,intersect2))?intersect1:intersect2;
61+
}
62+
63+
64+
}
65+
public Point_[] getPerpendicularLineEndPoints(double x0, double y0, double halfLong) {
66+
if(halfLong < 0.5) {
67+
System.out.println("HL "+halfLong);
68+
halfLong = 5;
69+
}
70+
Point_[] ends = new Point_[2];
71+
if(this.horizontal){
72+
ends[0] = new Point_(x0, y0+halfLong);
73+
ends[1] = new Point_(x0, y0-halfLong);
74+
return ends;
75+
}
76+
if(this.vertical){
77+
ends[0] = new Point_(x0-halfLong, y0);
78+
ends[1] = new Point_(x0+halfLong, y0);
79+
return ends;
80+
}
81+
LinearLine pll = this.getPependicularLinearLineAt(x0, y0);
82+
double offsetX = Math.sqrt((halfLong*halfLong)/(1+pll.k*pll.k));
83+
double x1 = x0+offsetX;
84+
double y1 = pll.calY(x1);
85+
double x2 = x0-offsetX;
86+
double y2 = pll.calY(x2);
87+
ends[0] = new Point_(x1, y1);
88+
ends[1] = new Point_(x2, y2);
89+
return ends;
90+
}
91+
92+
public LinearLine getPependicularLinearLineAt(double x0, double y0) {
93+
// if this line is vertical
94+
if (this.vertical) {
95+
//return a horizontal line
96+
return new LinearLine(0, y0, false, true);
97+
}
98+
//if this line is horizontal
99+
if (this.horizontal) {
100+
//return a vertical line
101+
return new LinearLine(0, x0, true, false);
102+
}
103+
double k_ = -1 / this.k;
104+
double b_ = y0 - k_ * x0;
105+
return new LinearLine(k_, b_);
106+
}
107+
108+
public String toString() {
109+
String s = "LinearLine: ";
110+
s += " k=" + this.k;
111+
s += " b=" + this.b;
112+
s += " V=" + this.vertical;
113+
s += " H=" + this.horizontal;
114+
return s;
115+
}
116+
}

src/hk/microos/data/MyImage.java

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package hk.microos.data;
2+
3+
import java.awt.image.BufferedImage;
4+
import java.io.File;
5+
import java.util.ArrayList;
6+
7+
import hk.microos.tools.ImageTool;
8+
9+
public class MyImage {
10+
private String path;
11+
private BufferedImage bi;
12+
private int w = -1, h = -1;
13+
private ArrayList<Ellipse> elpses = new ArrayList<>();
14+
private ArrayList<Ellipse> elpsesStatic = null;
15+
16+
public MyImage(File f) {
17+
this.path = f.getAbsolutePath();
18+
// this.bi = ImageTool.openImage(f);
19+
// this.w = bi.getWidth();
20+
// this.h = bi.getHeight();
21+
}
22+
23+
public int w() {
24+
if (w == -1)
25+
w = getImage().getWidth();
26+
return w;
27+
}
28+
29+
public int h() {
30+
if (h == -1)
31+
h = getImage().getHeight();
32+
33+
return h;
34+
}
35+
36+
public void setElpsFromString(String s) {
37+
// load annotation from string with a specific format
38+
}
39+
40+
public BufferedImage getImage() {
41+
42+
return bi == null ? ImageTool.openImage(new File(path)) : bi;
43+
}
44+
45+
public void addElps(Ellipse e) {
46+
elpses.add(e);
47+
}
48+
49+
public ArrayList<Ellipse> getElpses() {
50+
return elpses;
51+
}
52+
53+
public ArrayList<Ellipse> getEllipseStatic() {
54+
return elpsesStatic;
55+
}
56+
57+
public ArrayList<String> getElpsesStrings() {
58+
ArrayList<String> strs = new ArrayList<>();
59+
for (Ellipse e : elpses) {
60+
strs.add(e.toRowFormatString());
61+
}
62+
return strs;
63+
}
64+
65+
public ArrayList<String> getStaticElpsesStrings() {
66+
if (elpsesStatic == null) {
67+
return null;
68+
}
69+
ArrayList<String> strs = new ArrayList<>();
70+
for (Ellipse e : elpsesStatic) {
71+
strs.add(e.toRowFormatString());
72+
}
73+
return strs;
74+
}
75+
76+
public ArrayList<String> getAllElpsesStrings() {
77+
ArrayList<String> strs = new ArrayList<>();
78+
for (Ellipse e : elpses) {
79+
strs.add(e.toRowFormatString());
80+
}
81+
if (elpsesStatic != null) {
82+
for (Ellipse e : elpsesStatic) {
83+
strs.add(e.toRowFormatString());
84+
}
85+
}
86+
87+
return strs;
88+
}
89+
90+
public String getPath() {
91+
return this.path;
92+
}
93+
94+
@Override
95+
public boolean equals(Object obj) {
96+
MyImage img = (MyImage) obj;
97+
return img.path.equals(this.path);
98+
}
99+
100+
public String getMarkNumString() {
101+
int elpsesStaticSize = (elpsesStatic == null) ? 0 : elpsesStatic.size();
102+
return String.format("%d+%d", elpsesStaticSize, elpses.size());
103+
}
104+
105+
public void setElpsesStatic(ArrayList<Ellipse> elps) {
106+
this.elpsesStatic = elps;
107+
}
108+
109+
}

src/hk/microos/data/Point_.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package hk.microos.data;
2+
3+
public class Point_ {
4+
public double x,y;
5+
public Point_(double x,double y){
6+
this.x = x;
7+
this.y = y;
8+
}
9+
public Point_(int x,int y){
10+
this.x = x;
11+
this.y = y;
12+
}
13+
public Point_(float x,float y){
14+
this.x = x;
15+
this.y = y;
16+
}
17+
public String toString(){
18+
return "("+this.x+", "+this.y+")";
19+
}
20+
}

0 commit comments

Comments
 (0)