Merge remote-tracking branch 'origin/sub_laptop_4' into main_laptop_1
This commit is contained in:
@@ -37,6 +37,10 @@ def plane(x: float, y: float) -> float:
|
||||
return 0.1 * x
|
||||
|
||||
|
||||
def bumps(x: float, y: float) -> float:
|
||||
return 5 * math.sin(x / 10)
|
||||
|
||||
|
||||
LINE = [[0.0, 0.0], [30.0, 40.0], [30.0, 100.0], [90.0, 180.0]] # 50 + 60 + 100 = 210 m
|
||||
|
||||
# (함수 이름, 인자) — 높이 자리는 "hill" · "plane" 글자로 넘김
|
||||
@@ -53,6 +57,9 @@ CASES = [
|
||||
("fixedSlopePoint", [[100, 30], [130, 70], 12, "hill"]),
|
||||
("fixedSlopePoint", [[0, 0], [50, 0], 9, "hill", 100]),
|
||||
("fixedSlopePoint", [[600, 0], [700, 0], 1, "hill"]),
|
||||
("fixedSlopePoint", [[0, 0], [30, 0], 9, "bumps"]),
|
||||
("fixedSlopePoint", [[0, 0], [60, 0], 9, "bumps"]),
|
||||
("fixedSlopePoint", [[0, 0], [200, 0], 9, "bumps"]),
|
||||
("compassCandidates", [[0, 0], 50, 5, "plane"]),
|
||||
("compassCandidates", [[200, 10], 60, 15, "hill"]),
|
||||
("compassCandidates", [[0, 0], 50, 50, "plane"]),
|
||||
@@ -77,6 +84,7 @@ import * as draw from "./D03_PlanAnalysis/logic/D03_PlanAnalysis_Draw.js";
|
||||
const heights = {
|
||||
hill: (x, y) => (x > 800 ? NaN : 0.0005 * x * x + 3 * Math.sin(y / 40)),
|
||||
plane: (x, y) => 0.1 * x,
|
||||
bumps: (x, y) => 5 * Math.sin(x / 10),
|
||||
};
|
||||
const cases = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
||||
const out = cases.map(([name, args]) =>
|
||||
@@ -85,7 +93,7 @@ const out = cases.map(([name, args]) =>
|
||||
writeFileSync(process.argv[3], JSON.stringify(out));
|
||||
"""
|
||||
|
||||
_HEIGHTS = {"hill": hill, "plane": plane}
|
||||
_HEIGHTS = {"hill": hill, "plane": plane, "bumps": bumps}
|
||||
_PY = {
|
||||
"segmentLength": draw.segment_length,
|
||||
"groundSlopePct": draw.ground_slope_pct,
|
||||
@@ -187,6 +195,29 @@ def test_hand_values() -> None:
|
||||
assert draw.compass_point((0, 0), (10, 40), 50, 50, plane) is None
|
||||
|
||||
|
||||
def test_fixed_slope_nearest_to_cursor() -> None:
|
||||
# 5·sin(x/10) 에서 9 % 자리가 여럿 — 마우스 가까운 자리(짧은 첫 자리 아님)
|
||||
def roots() -> list[float]:
|
||||
out, prev = [], None
|
||||
for i in range(1, 100001):
|
||||
t = i * 0.01
|
||||
f = abs(bumps(t, 0)) - 0.09 * t
|
||||
if prev is not None and (prev < 0) != (f < 0):
|
||||
out.append(t)
|
||||
prev = f
|
||||
return out
|
||||
|
||||
rs = roots()
|
||||
assert len(rs) >= 3
|
||||
for cx in (30, 60, 200):
|
||||
want = min(rs, key=lambda r: abs(r - cx))
|
||||
got = draw.fixed_slope_point((0, 0), (cx, 0), 9, bumps)
|
||||
assert got is not None and got[0] == pytest.approx(want, abs=0.02)
|
||||
first = draw.fixed_slope_point((0, 0), (30, 0), 9, bumps)
|
||||
far = draw.fixed_slope_point((0, 0), (200, 0), 9, bumps)
|
||||
assert first is not None and far is not None and far[0] > first[0] + 20
|
||||
|
||||
|
||||
def test_line_values() -> None:
|
||||
assert draw.line_length(LINE) == 210
|
||||
assert draw.point_at_distance(LINE, -5) == (0, 0)
|
||||
|
||||
Reference in New Issue
Block a user