#module
#deffunc circle_area double x, double y, double r, \
local r_area, local l_area, local u_area, local d_area, local ur_area, local area, \
local theta, local dx, local dy, local buf
ddim area, 4
w_area=M_PI*r*r
if x>=r {
r_area=w_area
l_area=0.0
} else : if x<=-r {
r_area=0.0
l_area=w_area
} else {
dy=sqrt(r*r-x*x)
theta=atan(dy, -x)
r_area=r*r*theta+x*dy
l_area=w_area-r_area
}
if y>=r {
u_area=w_area
d_area=0.0
} else : if y<=-r {
u_area=0.0
d_area=w_area
} else {
dx=sqrt(r*r-y*y)
theta=atan(dx, -y)
u_area=r*r*theta+y*dx
d_area=w_area-u_area
}
if dx>0.0 and dy>0.0 {
if x*x+y*y>=r*r {
if x>0.0 {
if y>0.0 {
area=w_area-l_area-d_area, l_area, 0.0, d_area
} else {
area=u_area, 0.0, l_area, w_area-u_area-l_area
}
} else {
if y>0.0 {
area=r_area, w_area-r_area-d_area, d_area, 0.0
} else {
area=0.0, u_area, w_area-u_area-r_area, r_area
}
}
} else {
theta=atan(dy, -x)-atan(-y, dx)
ur_area=r*r*(theta-sin(theta))/2.0+(x+dx)*(y+dy)/2.0
area=ur_area, u_area-ur_area, w_area+ur_area-r_area-u_area, r_area-ur_area
}
} else : if dx>0.0 {
if x>0.0 {
area=u_area, 0.0, 0.0, d_area
} else {
area=0.0, u_area, d_area, 0.0
}
} else : if dy>0.0 {
if y>0.0 {
area=r_area, l_area, 0.0, 0.0
} else {
area=0.0, 0.0, l_area, r_area
}
} else {
if x>0.0 {
if y>0.0 {
area=w_area, 0.0, 0.0, 0.0
} else {
area=0.0, 0.0, 0.0, w_area
}
} else {
if y>0.0 {
area=0.0, w_area, 0.0, 0.0
} else {
area=0.0, 0.0, w_area, 0.0
}
}
}
buf=strf("x=%f y=%f r=%f ", x, y, r)
repeat 4 : buf+=strf(" %f", area.cnt) : loop
mes buf
return
#global
circle_area 11, 11, 10
circle_area -11, 11, 10
circle_area -11, -11, 10
circle_area 11, -11, 10
circle_area 11, -4, 10
circle_area -11, -4, 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