[vtkusers] Useless comupations in vtkMath

Dženan Zukić dzenanz at gmail.com
Mon Aug 15 03:14:45 EDT 2011


I just took a look at vtk 5.6.1, and the Norm function looks like this:
  // Description:
  // Compute the norm of 3-vector.
  static float Norm(const float x[3]) {
    return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2]
) );};

That means it returns the magnitude of the vector, and the Normalize method
works as it should:
1. calculate magnitude
2. if it is not zero
  3. divide all vector components by the magnitude
4. return magnitude

Nothing can be erased here, only made more clear, like this:

inline double vtkMath::Normalize(double x[3])
{
 double den = vtkMath::Norm( x );
 if ( den  != 0.0 )
   {
   for (int i=0; i < 3; i++)
     {
     x[i] /= den;
     }
   }
 return den;
}


On Mon, Aug 15, 2011 at 08:58, al.gry <al.gry at web.de> wrote:

> Hi everyone,
>
> I posted this thread last week but it wasn't accepted so Im trying again.
>
> I just looked into vtkMath source code provided via VTK.git and I found
> things like this:
>
> inline double vtkMath::Normalize(double x[3])
> {
>  double den;
>  if ( ( den = vtkMath::Norm( x ) ) != 0.0 )
>    {
>    for (int i=0; i < 3; i++)
>      {
>      x[i] /= den;
>      }
>    }
>  return den;
> }
>
> I guess the for-loop can be erased since it's useless... btw,
> if-instruction
> doesn't do anything so it's also useless.
>
> Regards, Al
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/Useless-comupations-in-vtkMath-tp4700083p4700083.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110815/42247e44/attachment.htm>


More information about the vtkusers mailing list