vkgs-sim / tests /test_obstacles.py
kimjunhan's picture
Add files using upload-large-folder tool
ceea884 verified
Raw History Blame Contribute Delete
2.85 kB
import numpy as np
from nusim.sim.obstacles import RES, obstacle_grid
def _cell(grid, x0, y0, x, y):
return grid[int((y - y0) / RES), int((x - x0) / RES)]
def test_wall_blocks_but_curb_and_canopy_do_not():
rng = np.random.default_rng(0)
ground = np.c_[rng.uniform(-20, 20, (40000, 2)), rng.normal(0.0, 0.01, 40000)]
# ๋ฒฝ: x = 5 m, ๋†’์ด 0~3 m
wall = np.c_[np.full(3000, 5.05), rng.uniform(-3, 3, 3000), rng.uniform(0, 3, 3000)]
# ์—ฐ์„: x = -5 m, ๋†’์ด 0.15 m โ€” ์ฐจ์ฒด์— ๊ฑธ๋ฆฌ์ง€ ์•Š๋Š”๋‹ค (์ฃผํ–‰๊ฐ€๋Šฅ์˜์—ญ ๊ฒฝ๊ณ„๊ฐ€ ๋”ฐ๋กœ ๋งก๋Š”๋‹ค)
curb = np.c_[np.full(3000, -5.05), rng.uniform(-3, 3, 3000), np.full(3000, 0.15)]
# ๊ฐ€๋กœ์ˆ˜ ์ˆ˜๊ด€: ๋†’์ด 4 m โ€” ์ฐจ๊ฐ€ ๋ฐ‘์œผ๋กœ ์ง€๋‚˜๊ฐ„๋‹ค
canopy = np.c_[rng.uniform(-1, 1, (3000, 2)) + [0, 10], np.full(3000, 4.0)]
# ์™ธํ†จ์ด ์žก์Œ ์  ๋ฌด๋”๊ธฐ ํ•œ ์นธ
noise = np.tile([[12.05, 12.05, 1.0]], (10, 1))
grid, x0, y0 = obstacle_grid(np.vstack([ground, wall, curb, canopy, noise]), np.zeros(2), 20.0)
assert _cell(grid, x0, y0, 5.05, 0.0) == 255
assert _cell(grid, x0, y0, -5.05, 0.0) == 0
assert _cell(grid, x0, y0, 0.0, 10.0) == 0
assert _cell(grid, x0, y0, 12.05, 12.05) == 0 # ์ด์›ƒ ์—†๋Š” ์นธ์€ ์ง€์šด๋‹ค
assert _cell(grid, x0, y0, 0.0, 0.0) == 0
def test_ground_follows_slope():
"""๋น„ํƒˆ(๊ฒฝ์‚ฌ 10%)์—์„œ๋„ ๋…ธ๋ฉด์ด ์žฅ์• ๋ฌผ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค โ€” ์ง€๋ฉด ๋†’์ด๋ฅผ ์นธ๋งˆ๋‹ค ์žฐ๋‹ค."""
rng = np.random.default_rng(1)
xy = rng.uniform(-20, 20, (60000, 2))
pts = np.c_[xy, 0.1 * xy[:, 0]]
grid, _, _ = obstacle_grid(pts, np.zeros(2), 20.0)
assert grid.sum() == 0
def test_smeared_road_and_canopy_not_obstacle():
"""๊ธด ์”ฌ: ๋จผ sweep ์˜ ๋…ธ๋ฉด ์ ์ด ์•„๋ž˜๋กœ ๋ฒˆ์ง€๊ณ (์ง€๋ฉด์ด ๋‚ฎ๊ฒŒ ์žกํžˆ๋˜ ๋ฌธ์ œ), ๋…ธ๋ฉด ์œ„๋กœ ๊ฐ€๋กœ์ˆ˜ ์ˆ˜๊ด€์ด ๋“œ๋ฆฌ์šด๋‹ค
(๊ฐ€์žฅ ๋†’์€ ์  ๊ธฐ์ค€์ด๋ฉด '์†Ÿ์€ ๊ตฌ์กฐ๋ฌผ' ๋กœ ๋‚จ๋˜ ๋ฌธ์ œ) โ€” scene-0402, 2026-10-09."""
from nusim.sim.obstacles import TALL_BAND
rng = np.random.default_rng(0)
n = 200_000
xy = rng.uniform(-10, 10, (n, 2))
z = np.where(rng.random(n) < 0.7, rng.normal(-0.2, 0.01, n), rng.uniform(-0.65, -0.2, n)) # ๋…ธ๋ฉด + ์•„๋ž˜ ๋ฒˆ์ง 30%
road = np.c_[xy, z]
canopy = np.c_[rng.uniform(-5, 5, (20_000, 2)), rng.uniform(6, 15, 20_000)]
pole = np.c_[rng.normal(7, 0.03, (3000, 2)), rng.uniform(-0.2, 6, 3000)]
grid, x0, y0, tall = obstacle_grid(np.vstack([road, canopy, pole]), np.zeros(2), 12.0, with_top=True)
ix = lambda v: int((v - x0) / 0.2)
assert grid[ix(-8):ix(5), ix(-8):ix(5)].sum() == 0 # ๋…ธ๋ฉด์€ ๋น„์–ด ์žˆ๋‹ค
assert not tall[ix(-4):ix(4), ix(-4):ix(4)].any() # ์ˆ˜๊ด€ ์•„๋ž˜๋Š” '์†Ÿ์€ ๊ตฌ์กฐ๋ฌผ' ์ด ์•„๋‹ˆ๋‹ค
assert grid[ix(7), ix(7)] and tall[ix(7), ix(7)] # ๊ธฐ๋‘ฅ์€ ์žฅ์• ๋ฌผ์ด๊ณ  ๋…ธ๋ฉด์—์„œ๋„ ๋‚จ๋Š”๋‹ค
assert TALL_BAND[1] <= 3.0