X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fextrudedshape.h;h=fd4597b9b1a5c935f50a3eb3a6e02296cd3f3a9f;hb=44bd1d1ab256d397be4e2169c4ca5efdd0569d31;hp=a62aa9a311e88bf09dd9fa5d480b425baaf38758;hpb=7919982691f0b8c69d8bef1bf6471b1e7a312163;p=libs%2Fmath.git diff --git a/source/geometry/extrudedshape.h b/source/geometry/extrudedshape.h index a62aa9a..fd4597b 100644 --- a/source/geometry/extrudedshape.h +++ b/source/geometry/extrudedshape.h @@ -31,10 +31,11 @@ public: const Shape &get_base() const { return *base; } T get_length() const { return length; } - virtual BoundingBox get_axis_aligned_bounding_box() const; + virtual BoundingBox get_axis_aligned_bounding_box(unsigned = 0) const; 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 @@ -74,9 +75,9 @@ inline ExtrudedShape *ExtrudedShape::clone() const } template -inline BoundingBox ExtrudedShape::get_axis_aligned_bounding_box() const +inline BoundingBox ExtrudedShape::get_axis_aligned_bounding_box(unsigned detail) const { - BoundingBox base_bbox = base->get_axis_aligned_bounding_box(); + BoundingBox base_bbox = base->get_axis_aligned_bounding_box(detail); T half_length = length/T(2); return BoundingBox(compose(base_bbox.get_minimum_point(), -half_length), compose(base_bbox.get_maximum_point(), half_length)); @@ -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]; @@ -157,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 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