Permalink
Browse files

Be more careful about float precision in tessellation classes

  • Loading branch information...
1 parent 403bdc1 commit 8e7c946eed596415aa4f87b4adbd00225a2a641a @snogglethorpe committed Feb 2, 2012
Showing with 14 additions and 14 deletions.
  1. +4 −4 tessel-param.h
  2. +2 −2 tessel-sinc.cc
  3. +3 −3 tessel-sphere.cc
  4. +5 −5 tessel-torus.cc
View
@@ -1,6 +1,6 @@
// tessel-param.h -- Parametric tessellation functions
//
-// Copyright (C) 2005, 2006, 2007, 2008, 2011 Miles Bader <miles@gnu.org>
+// Copyright (C) 2005-2008, 2011-2012 Miles Bader <miles@gnu.org>
//
// This source code is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
@@ -47,9 +47,9 @@ class ParamTesselFun : public Tessel::Function
//
param_t wrapped_midpoint (param_t p1, param_t p2) const
{
- param_t mid = (p1 + p2) * 0.5f;
- if (abs (p1 - p2) > 0.5f)
- mid += 0.5f;
+ param_t mid = (p1 + p2) * param_t (0.5);
+ if (abs (p1 - p2) > param_t (0.5))
+ mid += param_t (0.5);
if (mid >= 1)
mid -= 1;
return mid;
View
@@ -83,7 +83,7 @@ SincTesselFun::midpoint (Tessel &tessel,
Pos
SincTesselFun::surface_pos (param_t u, param_t v) const
{
- param_t theta = u * 2 * PIf;
+ param_t theta = u * param_t (2 * PI);
param_t t = v * SINC_X_COMP;
dist_t sinc = t < Eps ? 1 : sin (t) / t;
return Pos (-cos (theta) * v, sin (theta) * v, sinc);
@@ -97,7 +97,7 @@ SincTesselFun::surface_pos (param_t u, param_t v) const
Vec
SincTesselFun::vertex_normal (const Vertex &vertex) const
{
- param_t theta = vertex.u * 2 * PIf;
+ param_t theta = vertex.u * param_t (2 * PI);
param_t t = vertex.v * SINC_X_COMP;
dist_t deriv = t < Eps ? 0 : (cos (t) / t - sin (t) / (t * t));
dist_t norm_x = -deriv;
View
@@ -1,6 +1,6 @@
// tessel-sphere.cc -- Sphere tessellation
//
-// Copyright (C) 2005, 2006, 2007, 2008 Miles Bader <miles@gnu.org>
+// Copyright (C) 2005-2008, 2012 Miles Bader <miles@gnu.org>
//
// This source code is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
@@ -89,8 +89,8 @@ SphereTesselFun::midpoint (Tessel &tessel,
Pos
SphereTesselFun::surface_pos (param_t u, param_t v) const
{
- coord_t theta = u * 2 * PIf;
- coord_t phi = (v - 0.5f) * PIf;
+ coord_t theta = u * coord_t (2 * PI);
+ coord_t phi = (v - coord_t (0.5)) * coord_t (PI);
coord_t cos_phi = cos (phi);
return Pos (-cos (theta) * cos_phi, sin (theta) * cos_phi, sin (phi));
}
View
@@ -93,8 +93,8 @@ TorusTesselFun::midpoint (Tessel &tessel,
Pos
TorusTesselFun::surface_pos (param_t u, param_t v) const
{
- dist_t theta = u * 2 * PIf;
- dist_t phi = v * 2 * PIf;
+ dist_t theta = u * dist_t (2 * PI);
+ dist_t phi = v * dist_t (2 * PI);
dist_t x_offs = r2 * cos (phi) + r1;
dist_t y_offs = r2 * sin (phi);
@@ -110,8 +110,8 @@ TorusTesselFun::surface_pos (param_t u, param_t v) const
Vec
TorusTesselFun::vertex_normal (const Vertex &vertex) const
{
- dist_t theta = vertex.u * 2 * PIf;
- dist_t phi = vertex.v * 2 * PIf;
+ dist_t theta = vertex.u * dist_t (2 * PI);
+ dist_t phi = vertex.v * dist_t (2 * PI);
dist_t x_norm = cos (phi);
dist_t y_norm = sin (phi);
return Vec (-cos (theta) * x_norm, sin (theta) * x_norm, y_norm);
@@ -122,7 +122,7 @@ TorusTesselFun::vertex_normal (const Vertex &vertex) const
Mesh *
snogray::tessel_torus (const Ref<const Material> &mat,
- const Xform &xform, float r2_frac, dist_t max_err)
+ const Xform &xform, dist_t r2_frac, dist_t max_err)
{
Mesh *mesh = new Mesh (mat);
TorusTesselFun fun (r2_frac, xform);

0 comments on commit 8e7c946

Please sign in to comment.