flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 178: Check if point is inside rectangle
Idiom # 178: Check if point is inside rectangle
See
programming-idioms.org
:
Functional Approach
Code
b := x1 < x < x2 && y1 < y < y2
What are effects?
Running Example
ex179 is for i := 0.3, i+0.3 while i < 1.3 do x := i y := i*2 x1 := 0.0 x2 := 1.0 y1 := 0.0 y2 := 2.0 b := x1 < x < x2 && y1 < y < y2 say "Point $x,$y is {if b then "" else "not "}inside of rectangle $x1,$y1,$x2,$y2" unit
What are effects?
Object-oriented Approach
Code
point (x, y f64) is rectangle(a, b point) is isInside (p point) => (a.x < p.x < b.x && a.y < p.y < b.y) x := 0.3 y := 1.1 p := point x y x1 := 0.0 x2 := 1.0 y1 := 0.0 y2 := 2.0 r := rectangle (point x1 y1) (point x2 y2) b := r.isInside p
What are effects?
Running Example
ex179b is point (x, y f64) is rectangle(a, b point) is isInside (p point) => (a.x < p.x < b.x && a.y < p.y < b.y) for i := 0.3, i+0.3 while i < 1.3 do x := i y := i*2 p := point x y x1 := 0.0 x2 := 1.0 y1 := 0.0 y2 := 2.0 r := rectangle (point x1 y1) (point x2 y2) b := r.isInside p say "Point $x,$y is {if b then "" else "not "}inside of rectangle $x1,$y1,$x2,$y2" unit
What are effects?
next: Idiom # 179: Get center of a rectangle