<commit_before>/*globals require, describe, it, console, assert*/
var chai    = require("chai");
var utilities = require("../../collision");
var graphics = require('../../graphics');


describe("Image partitioning process", function() {
    'use strict';
    describe("partitionParallelogramIntoFour", function() {
        var checkPartitioning = function(test, expected) {
            var currentTest = test.vertices;
            var currentResults = expected.vertices;
            for (var key in currentResults) {
                if(currentResults[key] !== undefined && currentTest[key] !== undefined){
                    chai.expect(currentTest[key]).to.be(currentResults[key]);
                }
            }
        };

        it("Return four quadrants for a 100X200 image", function() {
            var results100by200 = {
                TopLeft: new graphics.Parallelogram().fromVertices(0, 50, 0, 100),
                TopRight: new graphics.Parallelogram().fromVertices(50, 100, 0, 100),
                LowerLeft: new graphics.Parallelogram().fromVertices(0, 50, 100, 200),
                LowerRight: new graphics.Parallelogram().fromVertices(50, 100, 100, 200)
            };
            var portraitParallelograms = utilities.partitionSquareIntoFour({width: 100, height: 200});
            checkPartitioning(portraitParallelograms, results100by200);
        });

        it("Return four quadrants for a 200X200 image", function() {
            var results200by200 = {
                TopLeft: new graphics.Parallelogram().fromVertices(0, 100, 0, 100),
                TopRight: new graphics.Parallelogram().fromVertices(100, 200, 0, 100),
                LowerLeft: new graphics.Parallelogram().fromVertices(0, 100, 100, 200),
                LowerRight: new graphics.Parallelogram().fromVertices(100, 200, 100, 200)
            };
            var squareParallelograms = utilities.partitionSquareIntoFour({width: 200, height: 200});
            checkPartitioning(squareParallelograms, results200by200);
        });

        it("Return four quadrants for a 200X100 image", function() {
            var results200by100 = {
                TopLeft: new graphics.Parallelogram().fromVertices(0, 100, 0, 50),
                TopRight: new graphics.Parallelogram().fromVertices(100, 200, 0, 50),
                LowerLeft: new graphics.Parallelogram().fromVertices(0, 100, 50, 100),
                LowerRight: new graphics.Parallelogram().fromVertices(100, 200, 50, 100)
            };
            var landscapeParallelograms = utilities.partitionSquareIntoFour({width: 200, height: 100});
            checkPartitioning(landscapeParallelograms, results200by100);
        });
    });

    /** FaceContainer
     * width, height, offsetX, offsetY, imageWidth, imageHeight, containerWidth, containerHeight*/
    describe("squareOverlap", function() {
        describe("Concentric square test for 166x250 image", function() {
            var imageWidth = 166;
            var imageHeight = 250;
            var divWidth = 100;
            var divHeight = 100;
            var faceBoxWidth = imageWidth * 0.45;
            var faceBoxHeight = imageHeight * 0.35;

            var concentricSquareTest = function(offsetX, offsetY, vertexPerSquareTest, areaPerSquareTest) {
                var faceBox = new graphics.FaceContainer(faceBoxWidth, faceBoxHeight, offsetX, offsetY, imageWidth, imageHeight, divWidth, divHeight);
                var faceBoxCollisionMap = utilities.squareOverlap(faceBox);
                vertexPerSquareTest(faceBoxCollisionMap);
                utilities.calculateAreasForPoints(faceBox, faceBoxCollisionMap);
                areaPerSquareTest(faceBoxCollisionMap);
            };

            it("Centered face, one vertex per quadrant", function () {
                concentricSquareTest((imageWidth - faceBoxWidth) / 2, (imageHeight - faceBoxHeight) / 2,
                    function(collisionMap) {
                        for (var key in collisionMap) {
                            if (collisionMap[key] !== undefined) {
                                chai.expect(collisionMap[key].collisions.length).to.equal(1);
                            }<commit_msg>refactored area calculation to another file<commit_after>/*globals require, describe, it, console, assert*/
var chai    = require("chai");
var collision = require("../../collision");
var areas = require("../../areaProbability");
var graphics = require('../../graphics');


describe("Image partitioning process", function() {
    'use strict';
    describe("partitionParallelogramIntoFour", function() {
        var checkPartitioning = function(test, expected) {
            var currentTest = test.vertices;
            var currentResults = expected.vertices;
            for (var key in currentResults) {
                if(currentResults[key] !== undefined && currentTest[key] !== undefined){
                    chai.expect(currentTest[key]).to.be(currentResults[key]);
                }
            }
        };

        it("Return four quadrants for a 100X200 image", function() {
            var results100by200 = {
                TopLeft: new graphics.Parallelogram().fromVertices(0, 50, 0, 100),
                TopRight: new graphics.Parallelogram().fromVertices(50, 100, 0, 100),
                LowerLeft: new graphics.Parallelogram().fromVertices(0, 50, 100, 200),
                LowerRight: new graphics.Parallelogram().fromVertices(50, 100, 100, 200)
            };
            var portraitParallelograms = collision.partitionSquareIntoFour({width: 100, height: 200});
            checkPartitioning(portraitParallelograms, results100by200);
        });

        it("Return four quadrants for a 200X200 image", function() {
            var results200by200 = {
                TopLeft: new graphics.Parallelogram().fromVertices(0, 100, 0, 100),
                TopRight: new graphics.Parallelogram().fromVertices(100, 200, 0, 100),
                LowerLeft: new graphics.Parallelogram().fromVertices(0, 100, 100, 200),
                LowerRight: new graphics.Parallelogram().fromVertices(100, 200, 100, 200)
            };
            var squareParallelograms = collision.partitionSquareIntoFour({width: 200, height: 200});
            checkPartitioning(squareParallelograms, results200by200);
        });

        it("Return four quadrants for a 200X100 image", function() {
            var results200by100 = {
                TopLeft: new graphics.Parallelogram().fromVertices(0, 100, 0, 50),
                TopRight: new graphics.Parallelogram().fromVertices(100, 200, 0, 50),
                LowerLeft: new graphics.Parallelogram().fromVertices(0, 100, 50, 100),
                LowerRight: new graphics.Parallelogram().fromVertices(100, 200, 50, 100)
            };
            var landscapeParallelograms = collision.partitionSquareIntoFour({width: 200, height: 100});
            checkPartitioning(landscapeParallelograms, results200by100);
        });
    });

    /** FaceContainer
     * width, height, offsetX, offsetY, imageWidth, imageHeight, containerWidth, containerHeight*/
    describe("squareOverlap", function() {
        describe("Concentric square test for 166x250 image", function() {
            var imageWidth = 166;
            var imageHeight = 250;
            var divWidth = 100;
            var divHeight = 100;
            var faceBoxWidth = imageWidth * 0.45;
            var faceBoxHeight = imageHeight * 0.35;

            var concentricSquareTest = function(offsetX, offsetY, vertexPerSquareTest, areaPerSquareTest) {
                var faceBox = new graphics.FaceContainer(faceBoxWidth, faceBoxHeight, offsetX, offsetY, imageWidth, imageHeight, divWidth, divHeight);
                var faceBoxCollisionMap = collision.squareOverlap(faceBox);
                vertexPerSquareTest(faceBoxCollisionMap);
                console.log(areas.calculateAreasForPoints(faceBox, faceBoxCollisionMap));
                areaPerSquareTest(faceBoxCollisionMap);
            };

            it("Centered face, one vertex per quadrant", function () {
                concentricSquareTest((imageWidth - faceBoxWidth) / 2, (imageHeight - faceBoxHeight) / 2,
                    function(collisionMap) {
                        for (var key in collisionMap) {
                            if (collisionMap[key] !== undefined) {
                                chai.expect(collisionMap[key].collisions.length).to.equal(1);
                            }
{'fraction_non_alphanumeric': 0.10673428470338484, 'fraction_numerical': 0.049770020049534146, 'mean_word_length': 2.347808922226609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3859983', 'n_tokens_mistral': 2629, 'n_tokens_neox': 2171, 'n_words': 516}