const Shape<T, D-1> &get_base() const { return *base; }
T get_length() const { return length; }
- virtual HyperBox<T, D> get_axis_aligned_bounding_box() const;
+ virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const;
virtual bool contains(const LinAl::Vector<T, D> &) const;
- virtual bool check_intersection(const Ray<T, D> &) const;
virtual unsigned get_max_ray_intersections() const;
virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
};
}
template<typename T, unsigned D>
-inline HyperBox<T, D> ExtrudedShape<T, D>::get_axis_aligned_bounding_box() const
+inline BoundingBox<T, D> ExtrudedShape<T, D>::get_axis_aligned_bounding_box() const
{
- HyperBox<T, D-1> base_bbox = base->get_axis_aligned_bounding_box();
- return HyperBox<T, D>(LinAl::Vector<T, D>(base_bbox.get_dimensions(), length));
+ BoundingBox<T, D-1> base_bbox = base->get_axis_aligned_bounding_box();
+ T half_length = length/T(2);
+ return BoundingBox<T, D>(LinAl::Vector<T, D>(base_bbox.get_minimum_point(), -half_length),
+ LinAl::Vector<T, D>(base_bbox.get_maximum_point(), half_length));
}
template<typename T, unsigned D>
return base->contains(LinAl::Vector<T, D-1>(point));
}
-template<typename T, unsigned D>
-inline bool ExtrudedShape<T, D>::check_intersection(const Ray<T, D> &ray) const
-{
- return get_intersections(ray, 0, 1);
-}
-
template<typename T, unsigned D>
inline unsigned ExtrudedShape<T, D>::get_max_ray_intersections() const
{
if(offset<T(0))
offset = T(0);
}
- T distortion = base_dir.norm();
- Ray<T, D-1> base_ray(LinAl::Vector<T, D-1>(ray_start+ray_direction*offset),
- base_dir, (limit-offset)*distortion);
-
- SurfacePoint<T, D-1> *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. */
- base_points = reinterpret_cast<SurfacePoint<T, D-1> *>(points+size)-size;
-
- unsigned count = base->get_intersections(base_ray, base_points, size);
- for(unsigned i=0; (n<size && i<count); ++i)
+
+ if(limit>=offset)
{
+ T distortion = base_dir.norm();
+ Ray<T, D-1> base_ray(LinAl::Vector<T, D-1>(ray_start+ray_direction*offset),
+ base_dir, (limit-offset)*distortion);
+
+ SurfacePoint<T, D-1> *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. */
+ base_points = reinterpret_cast<SurfacePoint<T, D-1> *>(points+size)-size;
+
+ unsigned count = base->get_intersections(base_ray, base_points, size);
+ for(unsigned i=0; (n<size && i<count); ++i)
{
- T x = offset+base_points[i].distance/distortion;
- points[n].position = ray_start+ray_direction*x;
- points[n].normal = LinAl::Vector<T, D>(base_points[i].normal, T(0));
- points[n].distance = x;
- }
+ if(points)
+ {
+ T x = offset+base_points[i].distance/distortion;
+ points[n].position = ray_start+ray_direction*x;
+ points[n].normal = LinAl::Vector<T, D>(base_points[i].normal, T(0));
+ points[n].distance = x;
+ }
- ++n;
+ ++n;
+ }
}
}