/
shvidkuli
/
kkrjava
Обзор
Документация
Войти
/
shvidkuli
/
kkrjava
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/com/montecarlo/geometry/FigureDebf.java
88 строк
3 KB
kroc400
first_commit
30 апр 2026, 22:44
30 апр 2026, 22:44
2347fdb
Код
Авторство
О чём код?
package com.montecarlo.geometry; /** * The composite figure "debf": the union of a triangle (b–e–f) and a semicircle * (half-disk whose diameter is the chord f–e, opened towards point d). * * <h3>Geometry (default configuration)</h3> * <pre> * Rectangle ABCD = [0, 4] × [0, 4] * A = (0, 0) B = (4, 0) C = (4, 4) D = (0, 4) * E = (4, 2) — midpoint of side BC * F = (2, 0) — midpoint of side AB * * Triangle BEF : vertices B=(4,0), E=(4,2), F=(2,0) → area = 2 * Semicircle : diameter F→E, centre=(3,1), r=√2, D-side → area = π * ────────────────────────────────────────────────────────────────────── * Total analytical area = 2 + π ≈ 5.14159265… * </pre> * * <p>The triangle and semicircle share only the chord F–E as their common boundary and * lie on strictly opposite sides of it, so their areas simply add without overlap.</p> * * <p>To use a different figure, change the coordinates in {@code config.ini}. The * {@link com.montecarlo.utils.ConfigReader} will rebuild both components automatically.</p> */ public class FigureDebf implements Shape { private final Triangle triangle; private final Arc arc; /** * Constructs the figure "debf" from its two constituent shapes. * * @param triangle the filled triangle b–e–f * @param arc the filled semicircle on the d-side of chord f–e */ public FigureDebf(Triangle triangle, Arc arc) { this.triangle = triangle; this.arc = arc; } /** @return the triangle component */ public Triangle getTriangle() { return triangle; } /** @return the semicircle component */ public Arc getArc() { return arc; } /** * Returns {@code true} if the point is inside the triangle OR inside the semicircle. * * @param p the point to test * @return {@code true} if inside the figure */ @Override public boolean contains(Point p) { return triangle.contains(p) || arc.contains(p); } /** * Returns the exact analytical area of the figure. * * <p>Valid when the triangle and semicircle do not overlap (which is guaranteed * when the semicircle's diameter is exactly the hypotenuse of the triangle and * the semicircle opens away from the opposite vertex).</p> * * @return area(triangle) + area(semicircle) */ @Override public double analyticalArea() { return triangle.analyticalArea() + arc.analyticalArea(); } /** * Returns the smallest axis-aligned bounding box enclosing both the triangle * and the semicircle. * * @return merged bounding box */ @Override public BoundingBox getBoundingBox() { return triangle.getBoundingBox().merge(arc.getBoundingBox()); } @Override public String toString() { return String.format("FigureDebf{%s | %s}", triangle, arc); } }