fillTriangle(v0, v1, v2, color0, color1, color2) {
            const { width, height, imageBuffer, depthBuffer } = this;
        
            let vertices = [
                { pos: v0, color: color0 },
                { pos: v1, color: color1 },
                { pos: v2, color: color2 },
            ];

            if (vertices[1].pos[1] < vertices[0].pos[1]) {
                [vertices[1], vertices[0]] = [vertices[0], vertices[1]];
            }
            if (vertices[2].pos[1] < vertices[0].pos[1]) {
                [vertices[2], vertices[0]] = [vertices[0], vertices[2]];
            }
            if (vertices[2].pos[1] < vertices[1].pos[1]) {
                [vertices[2], vertices[1]] = [vertices[1], vertices[2]];
            }
        
            const [sv0, sv1, sv2] = [vertices[0].pos, vertices[1].pos, vertices[2].pos];
            const [sc0, sc1, sc2] = [vertices[0].color, vertices[1].color, vertices[2].color];
        
            const w0_a = (sv1[1] - sv2[1]);
            const w0_b = (sv2[0] - sv1[0]);
            const denom = w0_a * (sv0[0] - sv2[0]) + w0_b * (sv0[1] - sv2[1]);
            if (denom === 0) return;
        
            const invDenom = 1 / denom;
        
            const yStart = Math.max(0, Math.ceil(sv0[1]));
            const yEnd = Math.min(height, Math.ceil(sv2[1]));
        
            const edges = [
                { v1: sv0, v2: sv1 },
                { v1: sv1, v2: sv2 },
                { v1: sv2, v2: sv0 }
            ];
        
            for (let y = yStart; y < yEnd; y++) {
                let xMin = width, xMax = 0;


                for (let i = 0; i < 3; i++) {
                    const edge = edges[i];
                    const { v1, v2 } = edge;
                    if (y < Math.min(v1[1], v2[1]) || y > Math.max(v1[1], v2[1])) continue;
                    const dy = v2[1] - v1[1];
                    if (dy === 0) continue;

                    const t = (y - v1[1]) / dy;
                    const x = v1[0] + t * (v2[0] - v1[0]);
        
                    if (x < xMin) xMin = x;
                    if (x > xMax) xMax = x;
                }
        
                const xStart = Math.max(0, Math.ceil(xMin));
                const xEnd = Math.min(width, Math.ceil(xMax));
        
                const baseIndex = y * width;


                const w1_a = (sv2[1] - sv0[1]);
                const w1_b = (sv0[0] - sv2[0]);
        
                for (let x = xStart; x < xEnd; x++) {
                    const dx = (x - sv2[0]);
                    const dy = (y - sv2[1])
                    const w0 = (w0_a * dx + w0_b * dy) * invDenom;
                    const w1 = (w1_a * dx + w1_b * dy) * invDenom;
                    const w2 = 1 - w0 - w1;
        
                    if (w0 < 0 || w1 < 0 || w2 < 0) continue;
        
                    const zInterpolated = 1 / (w0 / sv0[2] + w1 / sv1[2] + w2 / sv2[2]);
        
                    const index = baseIndex + x;
        
                    if (zInterpolated < depthBuffer[index]) {
                        depthBuffer[index] = zInterpolated;
                        
                        const interpolatedColor = w0 * sc0 + w1 * sc1 + w2 * sc2;
        
                        const bufferIndex = index << 2;
                        imageBuffer.data[bufferIndex] = interpolatedColor;
                        imageBuffer.data[bufferIndex + 1] = interpolatedColor;
                        imageBuffer.data[bufferIndex + 2] = interpolatedColor;
                        imageBuffer.data[bufferIndex + 3] = 255;
                    }
                }
            }
        }




Optimize this code to make it run faster. Remove redundancies if they are present.