AKTIVE

Artifact [257a08ec63]
Login

Artifact [257a08ec63]

Artifact 257a08ec6312d6e4a59e1f0d56ceb8c5cbf5ff161356eb793ea7f601f1513b1f:


# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0 tcl.tk//DSL tcltest//EN//2.0
## (c) 2024 Andreas Kupries
# # ## ### ##### ######## ############# #####################
## AKTIVE. signed Distance Fields.

kt check Tcl     8.6 9
kt check tcltest 2

# # ## ### ##### ######## ############# #####################

kt local testing aktive

kt source support/util.tcl

# # ## ### ##### ######## ############# #####################
## Syntax

syntax {
    box           args
    box-rounded   args
    circle        args
    circles       args
    line          args
    parallelogram args
    polyline      args
    rhombus       args
    triangle      args
} {aktive image sdf}

syntax {
    and       args
    not       src
    or        args
    sub      {a b}
    xor       args
    xor-core {a b}

    outline  src
    ring    {src args}
    round   {src args}
} {aktive op sdf}

syntax {
    fit       src
    smooth    src
    pixelated src
} {aktive op sdf 2image}

# # ## ### ##### ######## ############# #####################

set base {width 11 height 11 x 0 y 0}

test aktive-image-sdf-box-2.0 "aktive image sdf box" -body {
    astclx 11 aktive image sdf box {*}$base ewidth 5 eheight 3 center {5 5}
} -match image -result [makei image::sdf::box 0 0 11 11 1 "$base ewidth 5.0 eheight 3.0 center {5.0 5.0}" {
    	2  2  2  2  2  2  2  2  2  2 2
	1  1  1  1  1  1  1  1  1  1 1
	0  0  0  0  0  0  0  0  0  0 0
	0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0
	0 -1 -2 -2 -2 -2 -2 -2 -2 -1 0
	0 -1 -2 -3 -3 -3 -3 -3 -2 -1 0
	0 -1 -2 -2 -2 -2 -2 -2 -2 -1 0
	0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0
	0  0  0  0  0  0  0  0  0  0 0
	1  1  1  1  1  1  1  1  1  1 1
    	2  2  2  2  2  2  2  2  2  2 2
}]

test aktive-image-sdf-box-rounded-2.0 "aktive image sdf box-rounded" -body {
    astclx 11 aktive image sdf box-rounded {*}$base \
	upleftradius 1 uprightradius 1 downleftradius 1 downrightradius 1 \
	ewidth 5 eheight 3 center {5 5}
} -match image -result [makei image::sdf::box-rounded 0 0 11 11 1 "$base upleftradius 1.0 uprightradius 1.0 downleftradius 1.0 downrightradius 1.0 ewidth 5.0 eheight 3.0 center {5.0 5.0}" {

    2.1623  2      2       2       2       2       2       2       2       2      2.1623
    1.2361  1      1       1       1       1       1       1       1       1      1.2361
    0.4142  0      0       0       0       0       0       0       0       0      0.4142
    0      -1     -1      -1      -1      -1      -1      -1      -1      -1      0
    0      -1     -2      -2      -2      -2      -2      -2      -2      -1      0
    0      -1     -2      -3      -3      -3      -3      -3      -2      -1      0
    0      -1     -2      -2      -2      -2      -2      -2      -2      -1      0
    0      -1     -1      -1      -1      -1      -1      -1      -1      -1      0
    0.4142  0      0       0       0       0       0       0       0       0      0.4142
    1.2361  1      1       1       1       1       1       1       1       1      1.2361
    2.1623  2      2       2       2       2       2       2       2       2      2.1623

}]

test aktive-image-sdf-circle-2.0 "aktive image sdf circle" -body {
    astclx 11 aktive image sdf circle {*}$base radius 3 center {5 5}
} -match image -result [makei image::sdf::circle 0 0 11 11 1 "$base radius 3.0 center {5.0 5.0}" {
    4.0711 3.4031 2.8310  2.3852  2.0990  2       2.0990  2.3852 2.8310 3.4031 4.0711
    3.4031 2.6569 2       1.4721  1.1231  1       1.1231  1.4721 2      2.6569 3.4031
    2.8310 2      1.2426  0.6056  0.1623  0       0.1623  0.6056 1.2426 2      2.8310
    2.3852 1.4721 0.6056 -0.1716 -0.7639 -1      -0.7639 -0.1716 0.6056 1.4721 2.3852
    2.0990 1.1231 0.1623 -0.7639 -1.5858 -2      -1.5858 -0.7639 0.1623 1.1231 2.0990
    2      1      0      -1      -2      -3      -2      -1      0      1      2
    2.0990 1.1231 0.1623 -0.7639 -1.5858 -2      -1.5858 -0.7639 0.1623 1.1231 2.0990
    2.3852 1.4721 0.6056 -0.1716 -0.7639 -1      -0.7639 -0.1716 0.6056 1.4721 2.3852
    2.8310 2      1.2426  0.6056  0.1623  0       0.1623  0.6056 1.2426 2      2.8310
    3.4031 2.6569 2       1.4721  1.1231  1       1.1231  1.4721 2      2.6569 3.4031
    4.0711 3.4031 2.8310  2.3852  2.0990  2       2.0990  2.3852 2.8310 3.4031 4.0711
}]

test aktive-image-sdf-parallelogram-2.0 "aktive image sdf parallelogram" -body {
    astclx 11 aktive image sdf parallelogram {*}$base ewidth 5 eheight 3 eskew 1 center {5 5}
} -match image -result [makei image::sdf::parallelogram 0 0 11 11 1 "$base ewidth 5.0 eheight 3.0 eskew 1.0 center {5.0 5.0}" {
    =  2       2       2       2       2       2       2       2       2       2       2.2361
    =  1       1       1       1       1       1       1       1       1       1       1.4142
    =  0       0       0       0       0       0       0       0       0       0       0.9487
    = -0.6325 -1      -1      -1      -1      -1      -1      -1      -1      -0.3162  0.6325
    = -0.3162 -1.2649 -2      -2      -2      -2      -2      -2      -1.5811 -0.6325  0.3162
    =  0      -0.9487 -1.8974 -2.8460 -3      -3      -3      -2.8460 -1.8974 -0.9487  0
    =  0.3162 -0.6325 -1.5811 -2      -2      -2      -2      -2      -2      -1.2649 -0.3162
    =  0.6325 -0.3162 -1      -1      -1      -1      -1      -1      -1      -1      -0.6325
    =  0.9487  0       0       0       0       0       0       0       0       0       0
    =  1.4142  1       1       1       1       1       1       1       1       1       1
    =  2.2361  2       2       2       2       2       2       2       2       2       2
}]

test aktive-image-sdf-rhombus-2.0 "aktive image sdf rhombus" -body {
    astclx 11 aktive image sdf rhombus {*}$base ewidth 5 eheight 3 center {5 5}
} -match image -result [makei image::sdf::rhombus 0 0 11 11 1 "$base ewidth 5.0 eheight 3.0 center {5.0 5.0}" {
    4.2875  3.7730  3.2585  2.7440  2.2361  2       2.2361  2.7440  3.2585  3.7730 4.2875
    3.4300  2.9155  2.4010  1.8865  1.3720  1       1.3720  1.8865  2.4010  2.9155 3.4300
    2.5725  2.0580  1.5435  1.0290  0.5145  0       0.5145  1.0290  1.5435  2.0580 2.5725
    1.7150  1.2005  0.6860  0.1715 -0.3430 -0.8575 -0.3430  0.1715  0.6860  1.2005 1.7150
    0.8575  0.3430 -0.1715 -0.6860 -1.2005 -1.7150 -1.2005 -0.6860 -0.1715  0.3430 0.8575
    0      -0.5145 -1.0290 -1.5435 -2.0580 -2.5725 -2.0580 -1.5435 -1.0290 -0.5145 0
    0.8575  0.3430 -0.1715 -0.6860 -1.2005 -1.7150 -1.2005 -0.6860 -0.1715  0.3430 0.8575
    1.7150  1.2005  0.6860  0.1715 -0.3430 -0.8575 -0.3430  0.1715  0.6860  1.2005 1.7150
    2.5725  2.0580  1.5435  1.0290  0.5145  0       0.5145  1.0290  1.5435  2.0580 2.5725
    3.4300  2.9155  2.4010  1.8865  1.3720  1       1.3720  1.8865  2.4010  2.9155 3.4300
    4.2875  3.7730  3.2585  2.7440  2.2361  2       2.2361  2.7440  3.2585  3.7730 4.2875
}]

test aktive-image-sdf-line-2.0 "aktive image sdf line" -body {
    astclx 11 aktive image sdf line {*}$base from {1 2} to {8 9}
} -match image -result [makei image::sdf::line 0 0 11 11 1 "$base from {1.0 2.0} to {8.0 9.0}" {

    2.2361 2      2.2361 2.8284 3.5355 4.2426 4.9497 5.6569 6.3640 7.0711 7.7782
    1.4142 1      1.4142 2.1213 2.8284 3.5355 4.2426 4.9497 5.6569 6.3640 7.0711
    1      0      0.7071 1.4142 2.1213 2.8284 3.5355 4.2426 4.9497 5.6569 6.3640
    1.4142 0.7071 0      0.7071 1.4142 2.1213 2.8284 3.5355 4.2426 4.9497 5.6569
    2.1213 1.4142 0.7071 0      0.7071 1.4142 2.1213 2.8284 3.5355 4.2426 4.9497
    2.8284 2.1213 1.4142 0.7071 0      0.7071 1.4142 2.1213 2.8284 3.5355 4.2426
    3.5355 2.8284 2.1213 1.4142 0.7071 0      0.7071 1.4142 2.1213 2.8284 3.5355
    4.2426 3.5355 2.8284 2.1213 1.4142 0.7071 0      0.7071 1.4142 2.1213 2.8284
    4.9497 4.2426 3.5355 2.8284 2.1213 1.4142 0.7071 0      0.7071 1.4142 2.2361
    5.6569 4.9497 4.2426 3.5355 2.8284 2.1213 1.4142 0.7071 0      1      2
    6.3640 5.6569 4.9497 4.2426 3.5355 2.8284 2.1213 1.4142 1      1.4142 2.2361
}]

test aktive-image-sdf-triangle-2.0 "aktive image sdf triangle" -body {
    astclx 11 aktive image sdf triangle {*}$base a {1 1} b {3 8} c {8 3}
} -match image -result [makei image::sdf::triangle 0 0 11 11 1 "$base a {1.0 1.0} b {3.0 8.0} c {8.0 3.0}" {
    1.4142  1       1.2362  1.5110  1.7857  2.0604  2.3351  2.6099  2.8846 3.1623 3.6056
    1      -0       0.2747  0.5494  0.8242  1.0989  1.3736  1.6483  1.9230 2.2361 2.8284
    1.2362  0.2747 -0.6868 -0.4121 -0.1374  0.1374  0.4121  0.6868  0.9615 1.4142 2.2361
    1.5110  0.5494 -0.4121 -1.3736 -1.0989 -0.8242 -0.5494 -0.2747 -0      1      2
    1.7857  0.8242 -0.1374 -1.0989 -2.0604 -1.4142 -0.7071 -0       0.7071 1.4142 2.2361
    2.0604  1.0989  0.1374 -0.8242 -1.4142 -0.7071 -0       0.7071  1.4142 2.1213 2.8284
    2.3351  1.3736  0.4121 -0.5494 -0.7071 -0       0.7071  1.4142  2.1213 2.8284 3.5355
    2.6099  1.6483  0.6868 -0.2747 -0       0.7071  1.4142  2.1213  2.8284 3.5355 4.2426
    2.8846  1.9230  0.9615 -0       0.7071  1.4142  2.1213  2.8284  3.5355 4.2426 4.9497
    3.1623  2.2361  1.4142  1       1.4142  2.1213  2.8284  3.5355  4.2426 4.9497 5.6569
    3.6056  2.8284  2.2361  2       2.2361  2.8284  3.5355  4.2426  4.9497 5.6569 6.3640
}]

# # ## ### ##### ######## ############# #####################

test aktive-image-sdf-circles-2.0 "aktive image sdf circles" -body {
    astclx 11 aktive image sdf circles {*}$base radius 1 centers {2 2} {7 3} {5 7}
} -match image -result [makei image::sdf::circles 0 0 11 11 1 {width 11 height 11 x 0 y 0 radius 1.0 centers {{2.0 2.0} {7.0 3.0} {5.0 7.0}}} {
    1.8284 1.2361  1      1.2361 1.8284  2.6056 2.1623  2      2.1623 2.6056 3.2426
    1.2361 0.4142  0      0.4142 1.2361  1.8284 1.2361  1      1.2361 1.8284 2.6056
    1      0      -1      0      1       1.2361 0.4142  0      0.4142 1.2361 2.1623
    1.2361 0.4142  0      0.4142 1.2361  1      0      -1      0      1      2
    1.8284 1.2361  1      1.2361 1.8284  1.2361 0.4142  0      0.4142 1.2361 2.1623
    2.6056 2.1623  2      1.8284 1.2361  1      1.2361  1      1.2361 1.8284 2.6056
    3.4721 3.1231  2.1623 1.2361 0.4142  0      0.4142  1.2361 2.1623 2.6056 3.2426
    4      3       2      1      0      -1      0       1      2      3      4
    4.0990 3.1231  2.1623 1.2361 0.4142  0      0.4142  1.2361 2.1623 3.1231 4.0990
    4.3852 3.4721  2.6056 1.8284 1.2361  1      1.2361  1.8284 2.6056 3.4721 4.3852
    4.8310 4       3.2426 2.6056 2.1623  2      2.1623  2.6056 3.2426 4      4.8310
}]

test aktive-image-sdf-polyline-2.0 "aktive image sdf polyline" -body {
    astclx 11 aktive image sdf polyline {*}$base points {2 2} {7 3} {5 7}
} -match image -result [makei image::sdf::polyline 0 0 11 11 1 {width 11 height 11 x 0 y 0 points {{2.0 2.0} {7.0 3.0} {5.0 7.0}}} {
    2.8284 2.2361 2      2.1573 2.3534 2.5495 2.7456 2.9417 3.1623 3.6056 4.2426
    2.2361 1.4142 1      1.1767 1.3728 1.5689 1.7650 1.9612 2.2361 2.8284 3.6056
    2      1      0      0.1961 0.3922 0.5883 0.7845 0.9806 1.4142 2.2361 3.1623
    2.2361 1.4142 0.9806 0.7845 0.5883 0.3922 0.1961 0      1      2      3
    2.8284 2.2361 1.9612 1.7650 1.5689 1.3416 0.4472 0.4472 1.3416 2.2361 3.1623
    3.6056 3.1623 2.9417 2.6833 1.7889 0.8944 0      0.8944 1.7889 2.6833 3.5777
    4.4721 4.1231 3.1623 2.2361 1.3416 0.4472 0.4472 1.3416 2.2361 3.1305 4.0249
    5      4      3      2      1      0      0.8944 1.7889 2.6833 3.5777 4.4721
    5.0990 4.1231 3.1623 2.2361 1.4142 1      1.4142 2.2361 3.1305 4.0249 4.9193
    5.3852 4.4721 3.6056 2.8284 2.2361 2      2.2361 2.8284 3.6056 4.4721 5.3666
    5.8310 5      4.2426 3.6056 3.1623 3      3.1623 3.6056 4.2426 5      5.8310
}]

# # ## ### ##### ######## ############# #####################
unset base
cleanupTests
return