line.java
来自「ErGo是一个很早的Java通用围棋服务器(IGS/NNGS)客户端程序。有全部」· Java 代码 · 共 117 行
JAVA
117 行
package ergo.ui;
// $Id: Line.java,v 1.3 1999/08/15 01:40:28 sigue Exp $
/*
* Copyright (C) 1999 Carl L. Gay and Antranig M. Basman.
* See the file copyright.txt, distributed with this software,
* for further information.
*/
class Line {
int d; // this is mod 2*v1 (x-coord).
int x0, y0; // 0-based current coordinates.
int v1, v2; // 0-based target.
boolean up = false;
ZappoMat zm = new ZappoMat();
public void brezinit(int x1, int y1, int x2, int y2) {
// String s = " ";
// System.out.println("Brezinit: "+x1+s+x2+s+x2+s+y2);
zm.setorig(x1, y1);
v1 = x2 - x1;
v2 = y2 - y1;
x0 = 0; y0 = 0;
if (v1 < 0) zm.compose (-1,0,0,1);
if (v2 < 0) zm.compose (1,0,0,-1);
v1 = v1*zm.a; v2 = v2*zm.d;
if (v2 > v1) {
zm.compose(0,1,1,0);
int t = v1; v1 = v2; v2 = t;
}
d = v1;
if (zm.weirdo()==1) up = true;
else up = false;
// System.out.println(up);
// System.out.println(zm);
// System.out.println(zm.weirdo());
}
public void copy (Line other) {
d = other.d; x0 = other.x0; y0 = other.y0;
v1 = other.v1; v2 = other.v2;
up = other.up;
zm.copy(other.zm);
}
public boolean breznext() {
++x0;
// System.out.println(v1);
if (x0 > v1) return false;
d += 2*v2;
if (d>2*v1 || up && d==2*v1) {
d -= 2*v1;
++y0;
}
// System.out.println("X: "+x0+" Y: "+y0+" D: "+d);
return true;
}
public int waity(int reqy) {
int lastx = 0;
// System.out.println("Init Wait for "+reqy+", at "+zm.getx(x0,y0)+", "+zm.gety(x0,y0));
while (zm.gety(x0, y0) == reqy) {
lastx = zm.getx(x0, y0);
// System.out.println("Wait for "+reqy+", at "+zm.getx(x0,y0)+", "+zm.gety(x0,y0));
if (!breznext()) {
System.out.println("Error: required wait for "+reqy+", got to "+zm.gety(x0,y0));
break;
}
}
return lastx;
}
public void line(RawImage imag, int color, int x1, int y1, int x2, int y2) {
brezinit(x1, y1, x2, y2);
do {
zm.setZapPixel(imag, color, x0, y0);
}
while (breznext());
}
class ZappoMat {
int a=1, b=0, c=0, d=1;
// premultiply.....! want first things to happen first....
ZappoMat compose(int a1, int b1, int c1, int d1) {
int a2 = a1*a + b1*c; int b2 = a1*b + b1*d;
int c2 = c1*a + d1*c; int d2 = b1*c + d1*d;
a = a2; b = b2; c = c2; d = d2;
return this;
}
int xorig, yorig;
void init() {
a=1; b=0; c=0; d=1;
}
int weirdo() {
return a+b;
}
void setorig(int xorig1, int yorig1) {
init();
xorig = xorig1; yorig = yorig1;
}
void setZapPixel(RawImage imag, int color, int x, int y) {
int x3 = xorig + (a*x + c*y); int y3 = yorig + (b*x + d*y);
// System.out.println("Trans: x="+x3+", y="+y3);
imag.setpixel(color, x3, y3);
}
int gety(int x, int y) {
return yorig + (b*x + d*y);
}
int getx(int x, int y) {
return xorig + (a*x + c*y);
}
public String toString() {
return ""+a+" "+b+" "+c+" "+d;
}
void copy(ZappoMat other) {
a = other.a; b = other.b; c = other.c; d = other.d;
xorig = other.xorig; yorig = other.yorig;
}
} // end inner class ZappoMat
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?