angle node kind of working

This commit is contained in:
2026-03-27 22:37:09 -07:00
parent e10a30c08f
commit 3752e1c733
12 changed files with 993 additions and 4 deletions

View File

@@ -695,6 +695,91 @@ def test_scar_removal():
print(" PASS\n")
def test_angle_measure():
print("=== Test: AngleMeasure ===")
from backend.node_registry import get_node_info
from backend.nodes.angle_measure import AngleMeasure
from backend.data_types import ImageData
node = AngleMeasure()
assert get_node_info("AngleMeasure")["category"] == "Overlay"
required_inputs = AngleMeasure.INPUT_TYPES()["required"]
assert required_inputs["color"][1]["default"] == "#ff0000"
field = make_field(
data=np.zeros((32, 64), dtype=np.float64),
xreal=4.0,
yreal=2.0,
)
output, table = node.process(
field,
color="#c62828",
line_thickness=1.8,
x1=0.2,
y1=0.5,
xm=0.5,
ym=0.5,
x2=0.5,
y2=0.2,
label_dx=0.0,
label_dy=0.0,
)
rows = {row["quantity"]: row for row in table}
assert isinstance(output, DataField)
assert output is not field
assert len(output.overlays) == len(field.overlays) + 1
assert output.overlays[-1]["kind"] == "angle_measure"
assert output.overlays[-1]["color"] == "#c62828"
assert np.isclose(output.overlays[-1]["line_thickness"], 1.8)
assert np.isclose(rows["Arm A length"]["value"], 1.2)
assert np.isclose(rows["Arm B length"]["value"], 0.6)
assert np.isclose(rows["Angle"]["value"], 90.0)
assert rows["Angle"]["unit"] == "deg"
assert rows["Vertex x"]["unit"] == field.si_unit_xy
overridden_output, _ = node.process(
field,
color="not-a-color",
line_thickness=0.7,
x1=0.2,
y1=0.5,
xm=0.5,
ym=0.5,
x2=0.5,
y2=0.2,
label_dx=0.0,
label_dy=0.0,
line_thickness_input=2.4,
)
assert overridden_output.overlays[-1]["color"] == "#ff0000"
assert np.isclose(overridden_output.overlays[-1]["line_thickness"], 2.4)
image = np.zeros((50, 100, 3), dtype=np.uint8)
image_output, image_table = node.process(
image,
color="#ff0000",
line_thickness=1.25,
x1=0.25,
y1=0.5,
xm=0.5,
ym=0.5,
x2=0.5,
y2=0.25,
label_dx=0.0,
label_dy=0.0,
)
image_rows = {row["quantity"]: row for row in image_table}
assert isinstance(image_output, ImageData)
assert image_output.shape == image.shape
assert np.count_nonzero(np.asarray(image_output)) > 0
assert np.isclose(image_rows["Arm A length"]["value"], 24.75)
assert np.isclose(image_rows["Arm B length"]["value"], 12.25)
assert np.isclose(image_rows["Angle"]["value"], 90.0)
assert image_rows["Arm A length"]["unit"] == "px"
print(" PASS\n")
# =========================================================================
# Analysis (non-FFT)
# =========================================================================
@@ -2648,6 +2733,7 @@ if __name__ == "__main__":
test_fix_zero()
test_line_correction()
test_scar_removal()
test_angle_measure()
# Analysis
test_statistics()