Posted to tcl by florentis at Wed Oct 21 05:42:40 GMT 2026view pretty

# illustration of TIP 764, using prototype V15

type def point {
    {double}x;
    {double}y;
}

set {point}A 100 250
set {point}B -100 -200

type def segment list(2).point

set {segment}AB $A $B

type def rect list(4).point

proc segment2rect {S} {(
    [type get $S] ne "segment" ? [return]:;
    
    A is point = $S(0)  ;  x_a = $A(x)  ;  y_a = $A(y);
    C is point = $S(1)  ;  x_c = $C(x)  ;  y_c = $C(y) ;

    # Milieu
    M is point = (
	x_m = ($x_a + $x_c)/2.0,
	y_m = ($y_a + $y_c)/2.0
    );
    
    MC is segment = ($M, $C);
    B is point = (
	x_b = $x_m - ($y_c - $y_m),
	y_b = $y_m + ($x_c - $x_m)
    );
    D is point = (
	x_d = 2*$x_m - $x_b,
	y_d = 2*$y_m - $y_b
    );
    
    return [($A,$B,$C,$D)]
)}

segment2rect $AB ; # {100 250} {225.0 -75.0} {-100 -200} {-225.0 125.0}