以下のコードは、2 つの線の交点を見つけて、ポイント オブジェクトを返します。ポイントがIntersectionOf2Linesクラスによってのみ作成される場合、ポイントをネストされたクラスにする必要がありますか? そうでない場合は、なぜですか?ありがとう
class Point {
private final int x;
private final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
int getX() {
return x;
}
int getY() {
return y;
}
}
public class IntersectionOf2Lines {
public static Point calculateIntersection(Line line1, Line line2) {
int x = (line2.getConstant() - line1.getConstant()) / (line1.getSlope() - line2.getSlope());
int y = line1.getSlope() * x + line1.getConstant();
return new Point(x, y);
}