Texture coordinate problem

So i have these two functions that i want to plug into a textures UV, problem is only one of them can connect and adding the functions together with math nodes would distort the textures on the object because they both stem from the texture coord node. I figured this problem is easily fixed with coding?

basically the top function is an affine distortion of the triangles and the bottom function is just to pixelize the data.