X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fextrudedshape.h;h=e702f90a7a0f844d93f417b53d38a8c6aea2359a;hb=a29d2c17ca70a3ed5df1e863c92ccd851d5dba6b;hp=84addc46e7dde3fee65dea0283f56f2c0b29fc91;hpb=2087c3bb9e6087ccce86360c1c57823aa8a9ff40;p=libs%2Fmath.git diff --git a/source/geometry/extrudedshape.h b/source/geometry/extrudedshape.h index 84addc4..e702f90 100644 --- a/source/geometry/extrudedshape.h +++ b/source/geometry/extrudedshape.h @@ -35,6 +35,7 @@ public: virtual bool contains(const LinAl::Vector &) const; virtual unsigned get_max_ray_intersections() const; virtual unsigned get_intersections(const Ray &, SurfacePoint *, unsigned) const; + virtual Coverage get_coverage(const BoundingBox &) const; }; template @@ -116,7 +117,7 @@ inline unsigned ExtrudedShape::get_intersections(const Ray &ray, Sur { T offset = T(); T limit = T(); - if(ray.get_direction()[D-1]!=T(0)) + if(ray_direction[D-1]!=T(0)) { offset = (half_length-ray_start[D-1])/ray_direction[D-1]; limit = (-half_length-ray_start[D-1])/ray_direction[D-1]; @@ -147,6 +148,7 @@ inline unsigned ExtrudedShape::get_intersections(const Ray &ray, Sur points[n].position = ray_start+ray_direction*x; points[n].normal = compose(base_points[i].normal, T(0)); points[n].distance = x; + points[n].entry = base_points[i].entry; } ++n; @@ -156,7 +158,7 @@ inline unsigned ExtrudedShape::get_intersections(const Ray &ray, Sur /* If the ray is not parallel to the base space, it may pass through the caps. */ - if(n::get_intersections(const Ray &ray, Sur points[n].normal = LinAl::Vector(); points[n].normal[D-1] = i; points[n].distance = x; + points[n].entry = (T(i)*ray_direction[D-1]::get_intersections(const Ray &ray, Sur return n; } +template +inline Coverage ExtrudedShape::get_coverage(const BoundingBox &bbox) const +{ + T half_length = length/T(2); + if(bbox.get_maximum_coordinate(D-1)<-half_length || bbox.get_minimum_coordinate(D-1)>half_length) + return NO_COVERAGE; + + BoundingBox base_bbox(bbox.get_minimum_point().template slice(0), bbox.get_maximum_point().template slice(0)); + Coverage coverage = base->get_coverage(base_bbox); + if(coverage==NO_COVERAGE) + return NO_COVERAGE; + + if(bbox.get_minimum_coordinate(D-1)<-half_length || bbox.get_maximum_coordinate(D-1)>half_length) + return PARTIAL_COVERAGE; + else + return coverage; +} + } // namespace Geometry } // namespace Msp