Some more helper functions

This commit is contained in:
Ruben van de Ven 2020-09-22 09:11:45 +02:00
parent 377c60ac92
commit 058a656d13

View file

@ -219,20 +219,20 @@ function drawPart(feature, closed) {
}
/**
* Wrapper around p5.js color class
* @param {*} c color, either as array, or string (css name or HEX string)
*/
function getColor(c) {
if(!Array.isArray(c)) c = [c];
return new p5.Color(p5.instance, c);
}
// /**
// * Wrapper around p5.js color class
// * @param {*} c color, either as array, or string (css name or HEX string)
// */
// function getColor(c) {
// if(!Array.isArray(c)) c = [c];
// return new p5.Color(p5.instance, c);
// }
var colors = {
red: getColor('red'),
blue: getColor('blue'),
green: getColor('green'),
};
// var colors = {
// red: getColor('red'),
// blue: getColor('blue'),
// green: getColor('green'),
// };
function faceDistance(face1, face2){
// distance between faces, in pixels, not meters.. for now
@ -259,16 +259,39 @@ function faceDistance(face1, face2){
return Math.sqrt( Math.pow(dx, 2) + Math.pow(dy, 2) ) - r1 - r2;
}
function mergePoints() {
// a points should be {x: , y: }
// collect all points in the arguments:
let points = [];
for(let arg of arguments) {
if(Array.isArray(arg)) {
points.push(...arg);
} else {
points.push(arg);
}
}
return points;
}
function getBoundingBox(){
// arguments contains points, or sets of points. Find bbox
console.log(arguments)
// return {
// top:
// left:
// width:
// height:
// }
const points = mergePoints(...arguments);
const xs = points.map((point) => point.x);
const ys = points.map((point) => point.y);
const minx = Math.min(...xs);
const miny = Math.min(...ys);
return {
x: minx,
y: miny,
width: Math.max(...xs) - minx,
height: Math.max(...ys) - miny,
}
}
function parseDetectionResults(results) {
@ -277,6 +300,7 @@ function parseDetectionResults(results) {
const landmarks = result.landmarks._positions.map((pos) => parseCoordinate(pos));
let detection = {
'landmarks': landmarks,
// TODO: rotation
'parts': {},
'box': {
x: result.alignedRect._box._x * factor_x,
@ -292,9 +316,6 @@ function parseDetectionResults(results) {
}
return detections;
// result.parts
// result.alignedRect._box
// factor_x, factor_y
}
/**