Skip to content

Commit

Permalink
Merge pull request #1 from dip000/CurrentReWork
Browse files Browse the repository at this point in the history
Added implementations and small rework
  • Loading branch information
dip000 authored Feb 20, 2022
2 parents 6fcb8aa + 0dc2819 commit d0967cc
Show file tree
Hide file tree
Showing 13 changed files with 1,279 additions and 654 deletions.
159 changes: 94 additions & 65 deletions MapBuilderForWeb/BuilderCalculations.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,31 @@


function DictionaryToVector2(dictionary){
let arrayX = [];
let arrayY = [];

for(let i=0; i<Object.keys(dictionary).length; i++){
arrayX[i] = dictionary[ Object.keys(dictionary)[i] ].x;
arrayY[i] = dictionary[ Object.keys(dictionary)[i] ].y;
}

console.log("VECTOR TO DOUBLE ARRAY: ");
console.log(arrayX)
console.log(arrayY)

function OccupancyMapToCoordinates(occupancyMap){
if(occupancyMap == null) return;

return new Vector2Array(arrayX, arrayY);
}

function OccupancyMapToCoordenates(occupancyMap){
let coordenates = new Vector2Array();
let coordinates = new Vector2Array();
let k = 0;
let mapLengthX = occupancyMap.length;
let mapLengthY = occupancyMap[0].length;

for(var i=0; i<mapLengthX; i++){
for(var j=0; j<mapLengthY; j++){
if(occupancyMap[i][j] == true){
coordenates.x[k] = i;
coordenates.y[k] = j;
coordinates.x[k] = i;
coordinates.y[k] = j;
k++;
}
}
}

return coordenates;
return coordinates;
}

function LocalizeCoordenates(vector2){
function LocalizeCoordinates(vector2){
var minX = 999;
var minY = 999;

for(var i=0; i<vector2.x.length; i++){
if(vector2.x[i] < minX){
minX = vector2.x[i];
Expand All @@ -47,32 +34,32 @@
minY = vector2.y[i];
}
}

for(var i=0; i<vector2.x.length; i++){
vector2.x[i] -= minX;
vector2.y[i] -= minY;
}

console.log("LOCALIZED TO MIN VALUE: ");
/*console.log("LOCALIZED TO MIN VALUE: ");
console.log("minX " + minX + "; minY " + minY);
console.log(vector2);

console.log(vector2);*/
return vector2;
}

function GlobalizeCoordenates(shape, x, y){
let coordenates = new Vector2Array(shape);
function GlobalizeCoordinates(shape, x, y){
let coordinatesa = new Vector2Array(shape);

for(let i=0; i<coordenates.x.length; i++){
coordenates.x[i] += x;
coordenates.y[i] += y;
for(let i=0; i<shape.x.length; i++){
coordinatesa.x[i] += x;
coordinatesa.y[i] += y;
}
//console.log("GLOBALIZED TO TARGET VALUE: ");
//console.log(coordenates);
return coordenates;
//console.log(coordinates);
return coordinatesa;
}

function RotateCoordenatesByAngle(coordenates, angle){
function RotateCoordinatesByAngle(coordinates, angle){
//console.log("RESULT angle: " + angle);

if(angle<0){
Expand All @@ -84,34 +71,46 @@

angle = Math.round(angle);

if(angle == 4) return coordenates;
if(angle == 4) return coordinates;

let rotatedCoordenates = new Vector2Array(coordenates);
let rotatedCoordinates = new Vector2Array(coordinates);

//console.log("RESULT times: " + angle);
for(let i=0; i<angle; i++){
rotatedCoordenates = RotateCoordenates90Clockwise(rotatedCoordenates);
rotatedCoordinates = RotateCoordinates90Clockwise(rotatedCoordinates);
}

return rotatedCoordenates;
return rotatedCoordinates;
}


function RotateCoordenates90Clockwise(vector2){
function RotatePerfect(vector2, maxX){
var tempX = vector2.x;
vector2.x = vector2.y;

for(var i=0; i<vector2.x.length; i++){
tempX[i] = maxX - tempX[i];
}
vector2.y = tempX;

return vector2;
}

function RotateCoordinates90Clockwise(vector2){

//Flip axis. This actually mirors coordenates by 45 degrees
//Flip axis. This actually mirors coordinates by 45 degrees
var maxY = 0;
for(var i=0; i<vector2.x.length; i++){
var switchReg = vector2.x[i];
vector2.x[i] = vector2.y[i];
vector2.y[i] = switchReg;

if(vector2.y[i] > maxY){
maxY = vector2.y[i];
}
}

//Miror y axis. Both instructions actually rotate the coordenates 90° counteclockwise
//Miror y axis. Both instructions actually rotate the coordinates 90° counteclockwise
// and that can be seen as switching from row-cols system to x-y cartesian system
for(var i=0; i<vector2.x.length; i++){
vector2.y[i] = maxY - vector2.y[i];
Expand All @@ -124,35 +123,65 @@
}


function GetMaxValueOfCoordenates(coordenates){
function GetMaxValueOfCoordinates(coordinates){
let maxValue = 0;

for( let i=0; i<coordenates.x.length; i++ ){
if(coordenates.x[i] > maxValue){
maxValue = coordenates.x[i];
for( let i=0; i<coordinates.x.length; i++ ){
if(coordinates.x[i] > maxValue){
maxValue = coordinates.x[i];
}
if(coordenates.y[i] > maxValue){
maxValue = coordenates.y[i];
if(coordinates.y[i] > maxValue){
maxValue = coordinates.y[i];
}
}

return maxValue;
}

function GetMinValuesOfCoordenates(coordenates){
let minValue = {x:0, y:99};
function GetMinValuesOfCoordinates(coordinates){
let minValue = {x:0, y:999};

for( let i=0; i<coordenates.x.length; i++ ){
if(coordenates.x[i] > minValue.x){
minValue.x = coordenates.x[i];
for( let i=0; i<coordinates.x.length; i++ ){
if(coordinates.x[i] > minValue.x){
minValue.x = coordinates.x[i];
}
if(coordenates.y[i] < minValue.y){
minValue.y = coordenates.y[i];
if(coordinates.y[i] < minValue.y){
minValue.y = coordinates.y[i];
}
}

return minValue;
}

function GetMinValues(coordinates){
let minValue = {x:999, y:999};

for( let i=0; i<coordinates.x.length; i++ ){
if(coordinates.x[i] < minValue.x){
minValue.x = coordinates.x[i];
}
if(coordinates.y[i] < minValue.y){
minValue.y = coordinates.y[i];
}
}

return minValue;
}

function GetMaxValuesOfCoordinates(coordinates){
let maxValue = {x:0, y:0};

for( let i=0; i<coordinates.x.length; i++ ){
if(coordinates.x[i] > maxValue.x){
maxValue.x = coordinates.x[i];
}
if(coordinates.y[i] > maxValue.y){
maxValue.y = coordinates.y[i];
}
}

return maxValue;
}

function getStatisticsTopValue(val)
{
Expand All @@ -164,21 +193,21 @@
}

function randomColor(){
return 'rgb('+random(200)+','+(random(155)+100)+','+random(200)+')';
return 'rgb('+(random(200)+55)+','+(random(100)+50)+','+(random(100)+50)+')';
}
function random(number){
return Math.floor(Math.random()*number);;
}

function AverageVolume(coordenates){
function AverageVolume(coordinates){
let average = {x:0, y:0};
for(let i=0; i<coordenates.x.length; i++){
average.x += coordenates.x[i];
average.y += coordenates.y[i];
for(let i=0; i<coordinates.x.length; i++){
average.x += coordinates.x[i];
average.y += coordinates.y[i];
}

average.x /= coordenates.x.length;
average.y /= coordenates.y.length;
average.x /= coordinates.x.length;
average.y /= coordinates.y.length;

return average;
}
Loading

0 comments on commit d0967cc

Please sign in to comment.