Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Give the meaning of Calculation formula to draw line, or object #12

Open
Tracked by #2
1chooo opened this issue Jun 13, 2024 · 0 comments
Open
Tracked by #2
Assignees
Labels
enhancement New feature or request

Comments

@1chooo
Copy link
Owner

1chooo commented Jun 13, 2024

Take Generalization Line as an example, the current "calculation formula" containing in the draw(); however, at the first glance, we cannot identify what this calculation formula doing; therefore, we can wrap them as the function to be called by draw().

// TODO: Change the arrow to hollow (outline), ensuring the line does not pass through the arrow.
public void draw(Graphics g) {
int width = 10, height = 10;
int dx = x2 - x1, dy = y2 - y1;
double D = Math.sqrt(dx * dx + dy * dy);
double xm = D - width, xn = xm;
double ym = height, yn = -height;
double x;
double sin = dy / D, cos = dx / D;
x = xm * cos - ym * sin + x1;
ym = xm * sin + ym * cos + y1;
xm = x;
x = xn * cos - yn * sin + x1;
yn = xn * sin + yn * cos + y1;
xn = x;
int[] xpoints = { x2, (int) xm, (int) xn };
int[] ypoints = { y2, (int) ym, (int) yn };
g.drawLine(x1, y1, x2, y2);
g.drawPolygon(xpoints, ypoints, 3);
}

related: #11

@1chooo 1chooo added the enhancement New feature or request label Jun 13, 2024
@1chooo 1chooo self-assigned this Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant