// Path: java-mt/src/main/java/mayton/CardRaytracerMt.java
// static final int HEIGHT = 512;
// 
// Path: java-mt/src/main/java/mayton/CardRaytracerMt.java
// static final int WIDTH  = 512;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import javax.annotation.Nonnull;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.nio.file.Path;
import java.util.Random;
import java.util.concurrent.RecursiveAction;
import static java.lang.Math.ceil;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
import static mayton.CardRaytracerMt.HEIGHT;
import static mayton.CardRaytracerMt.WIDTH;
                Vector p = COLOR_DARK_GRAY_VECTOR;
                for (int r = 0; r < SUB_SAMPLES; r++) {
                    Vector t = a.prod(random.nextDouble() - 0.5).prod(99.0).sum(b.prod(random.nextDouble() - 0.5).prod(99.0));
                    p = sampler(CAMERA_ASPECT_VECTOR.sum(t),
                            t.prod(-1.0).sum(a.prod(random.nextDouble() + x).sum(b.prod(random.nextDouble() + y)).sum(c).prod(16.0)).norm()
                    ).prod(3.5).sum(p);
                }
                int red   = (int) p.x;
                int green = (int) p.y;
                int blue  = (int) p.z;
                image[xx + yy * width] = red << 16 | green << 8 | blue ;
                xx--;
            }
            yy--;
        }

        if (drawMargins) {
            for (int x = 0; x < width; x += 2) {
                image[x] = Color.GREEN.getRGB();
            }
            for (int y = 0; y < height; y += 2) {
                image[y * width] = Color.GREEN.getRGB();
            }
        }

        synchronized (mutexImage) {
            // TODO: This is fat and ugly code to copy rectangle into BufferedImage. Should be improoved with copy collections
            int xd = rect.x1;
            int yd = rect.y1;
            int x1 = WIDTH - xd - 1;
// Path: java-mt/src/main/java/mayton/CardRaytracerMt.java
// static final int HEIGHT = 512;
// 
// Path: java-mt/src/main/java/mayton/CardRaytracerMt.java
// static final int WIDTH  = 512;


// Path: java-mt/src/main/java/mayton/CardRaytraceRecursiveAction.java
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import javax.annotation.Nonnull;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.nio.file.Path;
import java.util.Random;
import java.util.concurrent.RecursiveAction;
import static java.lang.Math.ceil;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
import static mayton.CardRaytracerMt.HEIGHT;
import static mayton.CardRaytracerMt.WIDTH;

                Vector p = COLOR_DARK_GRAY_VECTOR;
                for (int r = 0; r < SUB_SAMPLES; r++) {
                    Vector t = a.prod(random.nextDouble() - 0.5).prod(99.0).sum(b.prod(random.nextDouble() - 0.5).prod(99.0));
                    p = sampler(CAMERA_ASPECT_VECTOR.sum(t),
                            t.prod(-1.0).sum(a.prod(random.nextDouble() + x).sum(b.prod(random.nextDouble() + y)).sum(c).prod(16.0)).norm()
                    ).prod(3.5).sum(p);
                }
                int red   = (int) p.x;
                int green = (int) p.y;
                int blue  = (int) p.z;
                image[xx + yy * width] = red << 16 | green << 8 | blue ;
                xx--;
            }
            yy--;
        }

        if (drawMargins) {
            for (int x = 0; x < width; x += 2) {
                image[x] = Color.GREEN.getRGB();
            }
            for (int y = 0; y < height; y += 2) {
                image[y * width] = Color.GREEN.getRGB();
            }
        }

        synchronized (mutexImage) {
            // TODO: This is fat and ugly code to copy rectangle into BufferedImage. Should be improoved with copy collections
            int xd = rect.x1;
            int yd = rect.y1;
            int x1 = WIDTH - xd - 1;
            int x2 = WIDTH - xd - 1 - width;