POV-Ray / povray

The Persistence of Vision Raytracer: http://www.povray.org/
GNU Affero General Public License v3.0
1.35k stars 282 forks source link

Broken quadric bounding in CSG intersection and difference. #315

Open c-lipka opened 7 years ago

c-lipka commented 7 years ago

Bounding box computation for CSG intersection uses a special mechanism to optimize bounding of some special cases of the quadric primitive, such as infinite axis-aligned cylinders. However, this mechanism is currently broken for the inverted variants of those quadrics, which affect the bounding box as if the regular variant was used.

Example (note that difference is effectively an intersection with all but the first object inverted):

#include "shapes.inc"

#declare Obj = difference { sphere { <0,0,0>, 2 } object { Cylinder_Y } }

#debug vstr(3,min_extent(Obj),",",0,-1)
#debug "\n"
#debug vstr(3,max_extent(Obj),",",0,-1)
#debug "\n"

The resulting object is a sphere with a hole punched into it, and should have the same bounding box as the sphere itself (-2 to 2 in all dimensions), but the bounding box is erroneously computed as <-1,-2,-1> to <1,2,1>.

The effect occurs not only with quadrics in CSG diffeerences, but also in CSG intersections when the quadric is inverted explicitly, either via the inverse keyword or by flipping the sign of all the quadric's parameter values.

c-lipka commented 7 years ago

It should be noted that while POV-Ray v3.7.0 does not exhibit the described problem if the quadric is inverted implicitly as part of a CSG difference or explicitly via the inverse keyword, that old version does exhibit the same problem if the quadric is inverted by flipping the sign of all its parameter values. Reverting to the old v3.7.0 code should therefore not be considered a viable solution.