#version 3.8; global_settings {assumed_gamma 1.0 } #macro VectorDimTest (v0) #local vZ3D = <0, 0, 0>; #local vZ4D = <0, 0, 0, 0>; #local vZ5D = <0, 0, 0, 0, 0>; #local v1 = v0 + 1; #local v2 = v0 + 2; #local D2 = ((vZ3D + v1).z = (vZ3D + v2).z); // because when vector promotion happens, they are 0 #local D3 = ((vZ4D + v1).t = (vZ4D + v2).t); // but when the vector is the same size, all the components are the same number, and 1 != 2 #local D4 = ((vZ5D + v1).transmit = (vZ5D + v2).transmit); #local v15D = <1, 1, 1, 1, 1>; #local v0v5 = v0*v15D; #if (D2) //#debug "2D " #local Size = 2; #else #if (D3) //#debug "3D " #local Size = 3; #else #if (D4) //#debug "4D " #local Size = 4; #else #local sqv0 = v0 * v0; #local v0p1 = v0 + 1; //#local Result = rgb (sqv0+1) + (sqv0+1); #local rgbv1 = rgb (v0+1); #local rgbv02 = rgb (v0*2); //#local Result = rgb (sqv0+1) + (sqv0+1) + rgbv1; #local Result = rgb (sqv0+1) + (sqv0+1) + rgbv1 + rgbv02; //#if (Result.transmit = Result.filter & Result.filter != Result.z) #if ( Result.x = Result.y & Result.y = Result.z & Result.z != Result.transmit & Result.transmit = Result.filter & v0v5.x = v0v5.y & v0v5.y = v0v5.z & v0v5.z = v0v5.filter & v0v5.filter = v0v5.transmit ) //#debug "Scalar" #local Size = 1; #else //#debug "5D " #local Size = 5; #end #end // if #end // if #end // if Size #end // end macro #macro Compare_AB (A, B, Partial) #local Asize = VectorDimTest (A); #local Bsize = VectorDimTest (B); #debug concat ("Asize = ", str (Asize, 0, 0), "\n") #debug concat ("Bsize = ", str (Bsize, 0, 0), "\n") #if (Asize = Bsize | Partial) #local LargestComponent = min (Asize, Bsize); #debug concat ("Min = ", str (LargestComponent, 0, 0), "\n") #local Result = 1; #for (CurrentComponent, 1, LargestComponent) #if (CurrentComponent = 1) //#debug "1\n" #local Result = Result * (A.x = B.x); #end #if (CurrentComponent = 2) //#debug "2\n" #local Result = Result * (A.y = B.y); #end #if (CurrentComponent = 3) //#debug "3\n" #local Result = Result * (A.z = B.z); #end #if (CurrentComponent = 4) #local Result = Result * (A.filter = B.filter); #end #if (CurrentComponent = 5) #local Result = Result * (A.transmit = B.transmit); #end #end #local Result = Result * LargestComponent; #else #warning concat ("Value mismatch! A = ", #if (Asize = 1) str (A, 3, -1), #else "<", vstr (Asize, A, ", ", 3, -1), ">" #end " B = ", #if (Bsize = 1) str (B, 3, -1), #else "<", vstr (Bsize, B, ", ", 3, -1), ">" #end #local Result = 0; "\n") #end Result #end #macro Test (A, B, P) #local Val = Compare_AB (A, B, P); #local AS = VectorDimTest (A); #local BS = VectorDimTest (B); #if (Val = 0) #debug concat ("Unequal: ", #if (AS = 1) str (A, 0, 0), #else "<", vstr (AS, A, ", ", 0, 3), ">", #end " != " #if (BS = 1) str (B, 0, 0), #else "<", vstr (BS, B, ", ", 0, 3), ">", #end "\n\n") #end #if (Val = 1) #debug concat ("Scalar: ", str (A, 0, 0), " = ", str (B, 0, 0), "\n\n") #end #if (Val > 1) #debug concat ("Vector: <", vstr (Val, A, ", ", 0, 3), "> = <", vstr (Val, B, ", ", 0, 3), "> \n\n") #end #end Test (1, 1, no) Test (1, 3, no) Test (<1, 1>, <1, 1>, no) Test (<1, 1>, <1, 2>, no) Test (<1, 1, 1>, <1, 1, 1>, no) Test (<1, 1, 1>, <1, 1, 2>, no) Test (<1, 1, 1, 1>, <1, 1, 1, 1>, no) Test (<1, 1, 1, 1>, <1, 1, 1, 2>, no) Test (<1, 1, 1, 1, 1>, <1, 1, 1, 1, 1>, no) Test (<1, 1, 1, 1, 1>, <1, 1, 1, 1, 2>, no) // Let's suppose you want to be able to test a smaller vector against a larger vector, // Only testing the smallest number of components. // That's what the Boolean macro argument is for. Test (<1, 2, 3>, <1, 2, 3, 4, 5>, yes) #error "No objects in scene"