class POINT inherit ANY redefine out end creation make feature x,y : DOUBLE -- the coordinates of the point left_of ( p, q: like Current ) : BOOLEAN is -- Is Current to left of directed line pq? local a, b, c, d : DOUBLE do a := p.y - q.y b := q.x - p.x c := x - p.x d := y - p.y Result := (a*c + b*d > 0) end side_of_circle ( p, q, r: like Current ) : INTEGER is -- -1 of Current is inside, 0 if on, 1 if outside local a,b,c,d,e,f,c_x,c_y,det,sqrad,difference : DOUBLE do a := q.x - p.x; b := q.y - p.y d := r.x - p.x; e := r.y - p.y det := a*e - b*d c := a*(p.x+q.x)/2 + b*(p.y+q.y)/2 f := d*(p.x+r.x)/2 + e*(p.y+r.y)/2 c_x := (c*e-f*b)/det c_y := (a*f-d*c)/det sqrad := (p.x-c_x)^2 + (p.y-c_y)^2 difference := (x-c_x)^2+(y-c_y)^2 - sqrad if difference < 0.0 then Result := -1 elseif difference = 0.0 then Result := 0 else Result := 1 end ensure -1 <= Result and Result <= 1 end prefix "-" : like Current is do !! Result.make ( -x, -y ) end out : STRING is do Result := "(" + x.out + ", " + y.out + ")" end feature {NONE} make (a,b: DOUBLE) is do x := a y := b end end -- class POINT