Previous | Next --- Slide 6 of 49
Back to Lecture Thumbnails
fengyupeng

how would std::min() behave on two 3d vectors? For example, isn't it hard to tell which one is bigger: v1 = Vector3D(1,3,5) or v2 = Vector3D(2,3,4). What will min(v1, v2) return? Will it return (1,3,4)? The smallest of each field? or just crash?

keenan

@fengyupeng Yes, great question. In this case, the min and max methods are defined componentwise, i.e., they would look something like this:

Vec3D min( Vec3D a, Vec3D b )
{
   Vec3D c;

   c.x = min( a.x, b.x );
   c.y = min( a.y, b.y );
   c.z = min( a.z, b.z );

   return c;
}

(and similarly for max).