- Introduced tests for color image handling, ensuring source preservation and premultiplied alpha usage. - Implemented tests for brush stroke operations, validating segment boundaries and brush anti-aliasing. - Added tests for frame anti-aliasing, confirming correct rendering behavior with various alpha values and depth settings. - Created tests for frame projection, ensuring accurate overlap calculations and half-plane clipping. - Developed tests for image premultiplied retention, verifying behavior during loading and packing processes. - Added undo functionality tests for mask operations, ensuring single transaction behavior during edits.
41 lines
1.5 KiB
Python
41 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.image_edit_tool import 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)
|