FUNCTION enclose_pregion_in_cregion
(prgn : polar_complex_number_region) : cartesian_complex_number_region;
PROCEDURE nearest_good_direction(acart : REAL; aitv : finite_real_interval; VAR a : REAL; VAR a_in : BOOLEAN); a := acart; a_in := TRUE; IF a < aitv.min THEN -- a+2.0*PI > aitv.min automatically! IF a+2.0*PI < aitv.max THEN RETURN; END_IF; IF a+2.0*PI = aitv.max THEN a_in := max_included(aitv); RETURN; END_IF; ELSE IF a = aitv.min THEN a_in := min_included(aitv); RETURN; ELSE IF a < aitv.max THEN RETURN; ELSE IF a = aitv.max THEN a_in := max_included(aitv); RETURN; END_IF; END_IF; END_IF; END_IF; IF COS(acart - aitv.max) >= COS(acart - aitv.min) THEN a := aitv.max; a_in := max_included(aitv); ELSE a := aitv.min; a_in := min_included(aitv); END_IF; END_PROCEDURE; LOCAL xc, yc, xmin, xmax, ymin, ymax : REAL := 0.0; ritv, xitv, yitv : real_interval; aitv : finite_real_interval; xmin_exists, xmax_exists, ymin_exists, ymax_exists : BOOLEAN; xmin_in, xmax_in, ymin_in, ymax_in : BOOLEAN := FALSE; a, r : REAL := 0.0; a_in : BOOLEAN := FALSE; min_clo, max_clo : open_closed := open; END_LOCAL; IF NOT EXISTS (prgn) THEN RETURN (?); END_IF; -- Extract elementary input data xc := prgn.centre.real_part; yc := prgn.centre.imag_part; ritv := prgn.distance_constraint; aitv := prgn.direction_constraint; -- Determine xmin data nearest_good_direction(PI,aitv,a,a_in); IF COS(a) >= 0.0 THEN xmin_exists := TRUE; xmin := xc + real_min(ritv)*COS(a); xmin_in := a_in AND (min_included(ritv) OR (COS(a) = 0.0)); ELSE IF max_exists(ritv) THEN xmin_exists := TRUE; xmin := xc + real_max(ritv)*COS(a); xmin_in := a_in AND max_included(ritv); ELSE xmin_exists := FALSE; END_IF; END_IF; -- Determine xmax data nearest_good_direction(0.0,aitv,a,a_in); IF COS(a) <= 0.0 THEN xmax_exists := TRUE; xmax := xc + real_min(ritv)*COS(a); xmax_in := a_in AND (min_included(ritv) OR (COS(a) = 0.0)); ELSE IF max_exists(ritv) THEN xmax_exists := TRUE; xmax := xc + real_max(ritv)*COS(a); xmax_in := a_in AND max_included(ritv); ELSE xmax_exists := FALSE; END_IF; END_IF; -- Determine ymin data nearest_good_direction(-0.5*PI,aitv,a,a_in); IF SIN(a) >= 0.0 THEN ymin_exists := TRUE; ymin := yc + real_min(ritv)*SIN(a); ymin_in := a_in AND (min_included(ritv) OR (SIN(a) = 0.0)); ELSE IF max_exists(ritv) THEN ymin_exists := TRUE; ymin := yc + real_max(ritv)*SIN(a); ymin_in := a_in AND max_included(ritv); ELSE ymin_exists := FALSE; END_IF; END_IF; -- Determine ymax data nearest_good_direction(0.5*PI,aitv,a,a_in); IF SIN(a) <= 0.0 THEN ymax_exists := TRUE; ymax := yc + real_min(ritv)*SIN(a); ymax_in := a_in AND (min_included(ritv) OR (SIN(a) = 0.0)); ELSE IF max_exists(ritv) THEN ymax_exists := TRUE; ymax := yc + real_max(ritv)*SIN(a); ymax_in := a_in AND max_included(ritv); ELSE ymax_exists := FALSE; END_IF; END_IF; -- Construct result IF NOT (xmin_exists OR xmax_exists OR ymin_exists OR ymax_exists) THEN RETURN (?); -- No finite boundaries exist END_IF; -- Construct real_constraint IF xmin_exists THEN IF xmin_in THEN min_clo := closed; ELSE min_clo := open; END_IF; IF xmax_exists THEN IF xmax_in THEN max_clo := closed; ELSE max_clo := open; END_IF; xitv := make_finite_real_interval(xmin,min_clo,xmax,max_clo); ELSE xitv := make_real_interval_from_min(xmin,min_clo); END_IF; ELSE IF xmax_exists THEN IF xmax_in THEN max_clo := closed; ELSE max_clo := open; END_IF; xitv := make_real_interval_to_max(xmax,max_clo); ELSE xitv := the_reals; END_IF; END_IF; -- Construct imag_constraint IF ymin_exists THEN IF ymin_in THEN min_clo := closed; ELSE min_clo := open; END_IF; IF ymax_exists THEN IF ymax_in THEN max_clo := closed; ELSE max_clo := open; END_IF; yitv := make_finite_real_interval(ymin,min_clo,ymax,max_clo); ELSE yitv := make_real_interval_from_min(ymin,min_clo); END_IF; ELSE IF ymax_exists THEN IF ymax_in THEN max_clo := closed; ELSE max_clo := open; END_IF; yitv := make_real_interval_to_max(ymax,max_clo); ELSE yitv := the_reals; END_IF; END_IF; -- Construct cartesian region RETURN (make_cartesian_complex_number_region(xitv,yitv)); END_FUNCTION; -- enclose_pregion_in_cregion
|