Files
AnyImage/tests/test_frame_projection.py
nan f5aff50b13 Refactor and clean up codebase by removing unused functions and reorganizing imports
- Removed unused model keys and functions from properties.py.
- Deleted projection.py as its functions were no longer needed.
- Cleaned up model_catalog.py by removing unused model directory function.
- Updated imports in various test files to reflect new module structure.
- Removed deprecated test cases related to image editing tools.
- Added new tests for ONNX runtime provider selection logic.
2026-09-09 10:31:56 +08:00

40 lines
1.5 KiB
Python

import sys
from pathlib import Path
import numpy as np
import pytest
sys.path.insert(0, str(Path(__file__).parents[1] / "src"))
from anyimage.common.selection import clip_polygon_halfplanes
from anyimage.operators import frame_tool as frame
@pytest.mark.parametrize("focal", [1, 1.7, 2, 4])
@pytest.mark.parametrize("angle,depth", [(30, 0.2), (0, 1e-14)])
def test_frame_overlap_matches_finite_front_samples(focal, angle, depth):
projection = np.eye(4)
projection[0, 0] = projection[1, 1] = focal
projection[3] = (0, 0, -1, 0)
c, s = np.cos(np.radians(angle)), np.sin(np.radians(angle))
world = np.eye(4)
world[:3, :3] = ((c, 0, s), (0, 1, 0), (-s, 0, c))
world[2, 3] = -depth
source = frame.frame_source_projection(
projection, np.eye(4), world, (-1, 1, -1, 1), (100, 100), perspective=True
)
source["image_size"] = (100, 100)
assert frame.frame_source_coordinates(source, np.array(((50, 50),)))[2][0]
overlap = frame.frame_source_overlap(source, ((0, 100), (100, 100), (100, 0), (0, 0)))
assert len(overlap) >= 3
assert np.isfinite(overlap).all()
@pytest.mark.parametrize("scale", [1e-14, 1, 1e14])
def test_halfplane_clipping_is_scale_invariant(scale):
square = ((0, 0), (2, 0), (2, 2), (0, 2))
result = clip_polygon_halfplanes(square, ((-scale, 0, scale),))
assert set(result) == {(0, 0), (1, 0), (1, 2), (0, 2)}
assert clip_polygon_halfplanes(square, ((1, 0, -3),)) == ()
edge = clip_polygon_halfplanes(square, ((1, 0, -2),))
assert all(x == 2 for x, y in edge)