1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| interface { distence_segment: (a, b) => distence }
function make_rectange(a, b, c, d) { const a_b = pair(a, b) const c_d = pair(c, d) return pair(a_b, c_d) } function a_rectange(r) { return head(head(r)) }
function get_w_and_h(r) { const a_to_b = distence_segment(a_rectange(r), b_rectange(r)) const a_to_c = distence_segment(a_rectange(r), c_rectange(r)) return pair(a_to_b,a_to_c) } function perimeter(r) { const w_h = get_w_and_h(r) return (head(w_h) + head(w_h)) * 2 } function area(r) { const w_h = get_w_and_h(r) return head(w_h) * head(w_h) } function get_w_and_h(r) { const a_to_b = distence_segment(a_rectange(r), b_rectange(r)) const a_to_c = distence_segment(a_rectange(r), c_rectange(r)) return pair(a_to_b,a_to_c) }
|