/
shvidkuli
/
kkrjava
Обзор
Документация
Войти
/
shvidkuli
/
kkrjava
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/com/montecarlo/geometry/Point.java
58 строк
1 KB
kroc400
first_commit
30 апр 2026, 22:44
30 апр 2026, 22:44
2347fdb
Код
Авторство
О чём код?
package com.montecarlo.geometry; /** * Immutable 2D point with Cartesian coordinates. * * <p>Used as the fundamental building block for all geometric shapes in this project.</p> */ public class Point { private final double x; private final double y; /** * Constructs a Point with the given Cartesian coordinates. * * @param x the x-coordinate * @param y the y-coordinate */ public Point(double x, double y) { this.x = x; this.y = y; } /** * Returns the x-coordinate of this point. * * @return x-coordinate */ public double getX() { return x; } /** * Returns the y-coordinate of this point. * * @return y-coordinate */ public double getY() { return y; } /** * Computes the Euclidean distance between this point and another. * * @param other the other point * @return non-negative Euclidean distance */ public double distanceTo(Point other) { double dx = this.x - other.x; double dy = this.y - other.y; return Math.sqrt(dx * dx + dy * dy); } @Override public String toString() { return String.format("(%.4f, %.4f)", x, y); } }