Skip to content

Commit

Permalink
Fix eclipse artifacts
Browse files Browse the repository at this point in the history
This reflects the fix in CalcMySky commit
afe131c57b14f984e3cdcd090fa905695b02ffce.

Fixes #3729
  • Loading branch information
10110111 committed Jun 9, 2024
1 parent 9e0e8ae commit 8072837
Show file tree
Hide file tree
Showing 43 changed files with 258 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ float circlesIntersectionArea(float R1, float R2, float d)
if(d>=R1+R2) return 0.;

// Return area of the lens with radii R1 and R2 and offset d
return sqr(R1)*acos(clamp( (sqr(d)+sqr(R1)-sqr(R2))/(2*d*R1) ,-1.,1.)) +
sqr(R2)*acos(clamp( (sqr(d)+sqr(R2)-sqr(R1))/(2*d*R2) ,-1.,1.)) -
// Note: R1^2-R2^2 must be computed before adding d^2 to the result,
// otherwise catastrophic cancellation will occur when R1≈R2 and d≈0,
// which will result in visual artifacts.
CONST float dRR = sqr(R1)-sqr(R2);
return sqr(R1)*acos(clampCosine( (sqr(d)+dRR)/(2*d*R1) )) +
sqr(R2)*acos(clampCosine( (sqr(d)-dRR)/(2*d*R2) )) -
0.5*sqrt(max( (-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2) ,0.));
}

Expand Down
Loading

0 comments on commit 8072837

Please sign in to comment.