# -*- coding: utf-8 -*- """등고선·세류선 절취(clip_line_to_box)가 경계에서 정확히 끊기는지 확인한다.""" import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[2])) from B07_DesignDetail.B07_DesignDetail_Router_Support import clip_line_to_box BOX = (0.0, 0.0, 10.0, 10.0) def test_경계를_넘는_선은_경계_위에서_끊긴다(): runs = clip_line_to_box([(-5.0, 5.0), (15.0, 5.0)], BOX) assert runs == [[(0.0, 5.0), (10.0, 5.0)]] def test_상자를_두_번_드나들면_조각이_둘이다(): line = [(-1.0, 5.0), (5.0, 5.0), (5.0, 20.0), (8.0, 20.0), (8.0, 5.0), (20.0, 5.0)] runs = clip_line_to_box(line, BOX) assert len(runs) == 2 assert runs[0][0] == (0.0, 5.0) assert runs[0][-1] == (5.0, 10.0) assert runs[1][0] == (8.0, 10.0) assert runs[1][-1] == (10.0, 5.0) def test_안에_전부_들면_그대로_남는다(): line = [(1.0, 1.0), (2.0, 3.0), (4.0, 2.0)] assert clip_line_to_box(line, BOX) == [line] def test_바깥에만_있으면_아무것도_안_남는다(): assert clip_line_to_box([(-5.0, -5.0), (-1.0, -3.0)], BOX) == [] def test_끝점이_경계를_넘지_않는다(): line = [(-3.0, 2.0), (12.0, 12.0), (5.0, -4.0)] for run in clip_line_to_box(line, BOX): for x, y in run: assert -1e-9 <= x <= 10.0 + 1e-9 assert -1e-9 <= y <= 10.0 + 1e-9