X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fextrudedshape.h;h=78dfa4911463e57951eaa0ca4524c223ab9ce9b5;hb=65b26478a62b8d715ec415164fff25fafcb35fc1;hp=c00111a549a67fa0bbdd4682f859030acbad4a74;hpb=a6ba5f18950f8471c5f3c168a9d65e901a8a6f2a;p=libs%2Fmath.git diff --git a/source/geometry/extrudedshape.h b/source/geometry/extrudedshape.h index c00111a..78dfa49 100644 --- a/source/geometry/extrudedshape.h +++ b/source/geometry/extrudedshape.h @@ -41,7 +41,7 @@ template inline ExtrudedShape::ExtrudedShape(const Shape &b, T l): length(l) { - if(l<=0) + if(l<=T(0)) throw std::invalid_argument("ExtrudedShape::ExtrudedShape"); base = b.clone(); @@ -78,8 +78,8 @@ inline BoundingBox ExtrudedShape::get_axis_aligned_bounding_box() co { BoundingBox base_bbox = base->get_axis_aligned_bounding_box(); T half_length = length/T(2); - return BoundingBox(LinAl::Vector(base_bbox.get_minimum_point(), -half_length), - LinAl::Vector(base_bbox.get_maximum_point(), half_length)); + return BoundingBox(compose(base_bbox.get_minimum_point(), -half_length), + compose(base_bbox.get_maximum_point(), half_length)); } template @@ -90,7 +90,7 @@ inline bool ExtrudedShape::contains(const LinAl::Vector &point) cons if(abs(point[D-1])>length/T(2)) return false; - return base->contains(LinAl::Vector(point)); + return base->contains(point.template slice(0)); } template @@ -108,7 +108,7 @@ inline unsigned ExtrudedShape::get_intersections(const Ray &ray, Sur T half_length = length/T(2); const LinAl::Vector &ray_start = ray.get_start(); const LinAl::Vector &ray_direction = ray.get_direction(); - LinAl::Vector base_dir(ray_direction); + LinAl::Vector base_dir = ray_direction.template slice(0); /* If the ray does not degenerate to a point in the base space, it could intersect the base shape. */ @@ -116,7 +116,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]; @@ -129,13 +129,13 @@ inline unsigned ExtrudedShape::get_intersections(const Ray &ray, Sur if(limit>=offset) { T distortion = base_dir.norm(); - Ray base_ray(LinAl::Vector(ray_start+ray_direction*offset), + Ray base_ray((ray_start+ray_direction*offset).template slice(0), base_dir, (limit-offset)*distortion); SurfacePoint *base_points = 0; if(points) - /* Shamelessly reuse the provided storage. Align to the end of the array - so processing can start from the first (nearest) point. */ + /* Shamelessly reuse the provided storage. Align to the end of the + array so processing can start from the first (nearest) point. */ base_points = reinterpret_cast *>(points+size)-size; unsigned count = base->get_intersections(base_ray, base_points, size); @@ -145,8 +145,9 @@ inline unsigned ExtrudedShape::get_intersections(const Ray &ray, Sur { T x = offset+base_points[i].distance/distortion; points[n].position = ray_start+ray_direction*x; - points[n].normal = LinAl::Vector(base_points[i].normal, T(0)); + points[n].normal = compose(base_points[i].normal, T(0)); points[n].distance = x; + points[n].entry = base_points[i].entry; } ++n; @@ -156,7 +157,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 continue; LinAl::Vector p = ray_start+ray_direction*x; - if(base->contains(LinAl::Vector(p))) + if(base->contains(p.template slice(0))) { if(points) { @@ -173,6 +174,7 @@ inline unsigned ExtrudedShape::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]