public static Cubic <SpanF> MultiplySpanByMatrix(Cubic <SpanF> span, Matrix4x4 mat) { SpanAPI.WeakTODO(); // slow but accurate way bool doAllCorners = false; if (doAllCorners) { var ans = span .Select(k => k.EachOfFromAndTo()) // seperate from and to .EachPermutation() // generate all corner permutations .Select(k => ToVector3(k)) .Select(k => mat.MultiplyPoint(k)) // transform by matrix .Select(k => k.ToCubic().Select(j => SpanAPI.spanExactly(j))) // back into spans .Aggregate((a, b) => a.Select2(b, (c, d) => SpanAPI.spanUnion(c, d))); // take union of all return(ans); } // only doing the corners, ideally do all: var cornerAM = ToVector3(span.Select(k => k.From)); var cornerBM = ToVector3(span.Select(k => k.To)); var cornerAW = mat.MultiplyPoint(cornerAM); var cornerBW = mat.MultiplyPoint(cornerBM); return(new Cubic <SpanF>( SpanAPI.spanUnsorted(cornerAW.x, cornerBW.x), SpanAPI.spanUnsorted(cornerAW.y, cornerBW.y), SpanAPI.spanUnsorted(cornerAW.z, cornerBW.z) )); }