FUNCTION compatible_complex_number_regions
(sp1 : maths_space, sp2 : maths_space) : BOOLEAN;
LOCAL typenames : SET OF STRING := stripped_typeof (sp1); crgn1, crgn2 : cartesian_complex_number_region; prgn1, prgn2, prgn1c2, prgn2c1 : polar_complex_number_region; sp1_is_crgn, sp2_is_crgn : BOOLEAN; END_LOCAL; IF 'CARTESIAN_COMPLEX_NUMBER_REGION' IN typenames THEN sp1_is_crgn := TRUE; crgn1 := sp1; ELSE IF 'POLAR_COMPLEX_NUMBER_REGION' IN typenames THEN sp1_is_crgn := FALSE; prgn1 := sp1; ELSE -- Improper usage: Default response is TO assume compatibility. RETURN (TRUE); END_IF; END_IF; typenames := stripped_typeof (sp2); IF 'CARTESIAN_COMPLEX_NUMBER_REGION' IN typenames THEN sp2_is_crgn := TRUE; crgn2 := sp2; ELSE IF 'POLAR_COMPLEX_NUMBER_REGION' IN typenames THEN sp2_is_crgn := FALSE; prgn2 := sp2; ELSE -- Improper usage: Default response is TO assume compatibility. RETURN (TRUE); END_IF; END_IF; IF sp1_is_crgn AND sp2_is_crgn THEN -- two cartesian regions RETURN (compatible_intervals(crgn1.real_constraint, crgn2.real_constraint) AND compatible_intervals(crgn1.imag_constraint, crgn2.imag_constraint)); END_IF; IF NOT sp1_is_crgn AND NOT sp2_is_crgn AND (prgn1.centre.real_part = prgn2.centre.real_part) AND (prgn1.centre.imag_part = prgn2.centre.imag_part) THEN -- two polar regions WITH common centre IF NOT compatible_intervals(prgn1.distance_constraint, prgn2.distance_constraint) THEN RETURN (FALSE); END_IF; IF compatible_intervals(prgn1.direction_constraint, prgn2.direction_constraint) THEN RETURN (TRUE); END_IF; -- Deal WITH direction ambiguity BY 2 pi. IF (prgn1.direction_constraint.max > PI) AND (prgn2.direction_constraint.max < PI) THEN RETURN (compatible_intervals(prgn2.direction_constraint, make_finite_real_interval(-PI,open,prgn1.direction_constraint.max-2.0*PI, prgn1.direction_constraint.max_closure))); END_IF; IF (prgn2.direction_constraint.max > PI) AND (prgn1.direction_constraint.max < PI) THEN RETURN (compatible_intervals(prgn1.direction_constraint, make_finite_real_interval(-PI,open,prgn2.direction_constraint.max-2.0*PI, prgn2.direction_constraint.max_closure))); END_IF; RETURN (FALSE); END_IF; -- Make do WITH imperfect tests FOR remaining cases. IF sp1_is_crgn AND NOT sp2_is_crgn THEN crgn2 := enclose_pregion_in_cregion(prgn2); prgn1 := enclose_cregion_in_pregion(crgn1,prgn2.centre); RETURN (compatible_complex_number_regions(crgn1,crgn2) AND compatible_complex_number_regions(prgn1,prgn2)); END_IF; IF NOT sp1_is_crgn AND sp2_is_crgn THEN crgn1 := enclose_pregion_in_cregion(prgn1); prgn2 := enclose_cregion_in_pregion(crgn2,prgn1.centre); RETURN (compatible_complex_number_regions(crgn1,crgn2) AND compatible_complex_number_regions(prgn1,prgn2)); END_IF; -- Two polar regions WITH different centres prgn1c2 := enclose_pregion_in_pregion(prgn1,prgn2.centre); prgn2c1 := enclose_pregion_in_pregion(prgn2,prgn1.centre); RETURN (compatible_complex_number_regions(prgn1,prgn2c1) AND compatible_complex_number_regions(prgn1c2,prgn2)); END_FUNCTION; -- compatible_complex_number_regions
|