Bladeren bron

test file + filter by size of opposed segment

Alexis 2 jaren geleden
bovenliggende
commit
c43ff77fa3
3 gewijzigde bestanden met toevoegingen van 122 en 7 verwijderingen
  1. 24 1
      backend/server.js
  2. 12 6
      frontend/assets/config.json
  3. 86 0
      frontend/test.html

+ 24 - 1
backend/server.js

@@ -18,6 +18,12 @@ app.get('/', function (req, res) {
 	});
 });
 
+app.get('/test', function (req, res) {
+	res.sendFile('./frontend/test.html', {
+		root: path.resolve(__dirname + '/..')
+	});
+});
+
 const httpServer = require('http').Server(app);
 
 /* --------
@@ -162,6 +168,19 @@ function getOrientation(dotTrio, topIndex) {
 	 //return length ;
 }
 
+function getSizeOfOpposedSegment(dots, apex){
+	let res = 0;
+	if(apex == 0){
+		res = getHypotenuse(dots[1], dots[2]);
+	} else if(apex == 1) {
+		res = getHypotenuse(dots[0], dots[2]);
+	} else if(apex == 2) {
+		res = getHypotenuse(dots[0], dots[1]);
+	}
+	console.log(res);
+	return res;
+}
+
 function objectGarbageCollector(){
 	//si un point dans last dots est detecté dans un des triangle alors on ne réduit pas sa duration
 	for(const triangle of objectsAlive){
@@ -312,6 +331,7 @@ function filterTriangles(dots, triangles){
 
 		objTriangle.angleApex = getAngleApex(objTriangle.dots, objTriangle.apex);
 		objTriangle.orientation = getOrientation(objTriangle.dots, objTriangle.apex);
+		objTriangle.sizeOfOpposedSegment = getSizeOfOpposedSegment(objTriangle.dots, objTriangle.apex);
 
 		if (config.app.debug && config.app.debugLog.backend.emitter.apex) {
 			console.log('-- apex --', objTriangle.apex);
@@ -322,7 +342,10 @@ function filterTriangles(dots, triangles){
 
 		//verify if triangle has a corresponding triangle in config
 		const matchingObject = config.objects.find(item => {
-			return objTriangle.angleApex > item.apexAngle - config.app.matchingTolerance && objTriangle.angleApex < item.apexAngle + config.app.matchingTolerance;
+			return objTriangle.angleApex > item.apexAngle - config.app.matchingTolerance && 
+			objTriangle.angleApex < item.apexAngle + config.app.matchingTolerance &&
+			objTriangle.sizeOfOpposedSegment > item.sizeOfOpposedSegment - 10 &&
+			objTriangle.sizeOfOpposedSegment < item.sizeOfOpposedSegment + 10;
 		});
 		if (matchingObject) {
 			objTriangle.matchingObject = matchingObject;

+ 12 - 6
frontend/assets/config.json

@@ -45,27 +45,33 @@
 	"objects": [
 		{
 			"name": "object1",
-			"apexAngle": 30
+			"apexAngle": 30,
+			"sizeOfOpposedSegment": 100
 		},
 		{
 			"name": "object2",
-			"apexAngle": 40
+			"apexAngle": 40,
+			"sizeOfOpposedSegment": 109
 		},
 		{
 			"name": "object2",
-			"apexAngle": 50
+			"apexAngle": 50,
+			"sizeOfOpposedSegment": 160
 		},
 		{
 			"name": "object4",
-			"apexAngle": 70
+			"apexAngle": 70,
+			"sizeOfOpposedSegment": 175
 		},
 		{
 			"name": "object5",
-			"apexAngle": 80
+			"apexAngle": 80,
+			"sizeOfOpposedSegment": 205
 		},
 		{
 			"name": "object6",
-			"apexAngle": 90
+			"apexAngle": 90,
+			"sizeOfOpposedSegment": 223
 		}
 	]
 }

+ 86 - 0
frontend/test.html

@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html style="height: 100%;">
+	<head>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width">
+		<title>ASR tangibles</title>
+        <style>
+            body {
+				width: 100%;
+				height: 100%;
+				margin: 0;
+				background-color: #EEEEEE;
+			}
+            canvas {
+                border: gray;
+            }
+        </style>
+    </head>
+
+	<body>
+
+		<!--<div id="box"></div>-->
+		<canvas id="myCanvas" width="1000" height="800"></canvas>
+
+		<script>
+            var canvasElement = document.querySelector("#myCanvas");
+            canvasElement.addEventListener('touchstart', (evt) => {
+                return eventHandler(evt, 'touchstart');
+            });
+
+            canvasElement.addEventListener('touchmove', (evt) => {
+                return eventHandler(evt, 'touchmove');
+            });
+
+            canvasElement.addEventListener('touchend', (evt) => {
+                return eventHandler(evt, 'touchend');
+            });
+            
+            var context = canvasElement.getContext("2d");
+            context.font = '48px serif';
+
+            function distance(touches, id1, id2){
+                return Math.sqrt( (touches[id1].pageX-touches[id2].pageX)**2 + (touches[id1].pageY-touches[id2].pageY)**2 );
+            }
+            function angle(touches, id){
+                var AB = distance(touches, id, (id+1)%3);    
+                var BC = distance(touches, (id+1)%3, (id+2)%3); 
+                var AC = distance(touches, (id+2)%3, id);
+                return Math.acos((BC*BC+AB*AB-AC*AC)/(2*BC*AB))*180/Math.PI;
+            }
+
+            const eventHandler = (evt, type) => {
+                console.log("test");
+                if(evt.touches.length === 3){
+                    console.log(evt.touches);
+                    context.clearRect(0, 0, canvasElement.width, canvasElement.height);
+                    // the triangle
+                    context.beginPath();
+                    context.moveTo(evt.touches[0].pageX, evt.touches[0].pageY);
+                    context.fillText(distance(evt.touches, 0, 1), 10, 50);
+                    context.fillText(angle(evt.touches, 0), 10, 100);
+                    context.lineTo(evt.touches[1].pageX, evt.touches[1].pageY);
+                    context.fillText(distance(evt.touches, 1, 2), 10, 150);
+                    context.fillText(angle(evt.touches, 1), 10, 200);
+                    context.lineTo(evt.touches[2].pageX, evt.touches[2].pageY);
+                    context.fillText(distance(evt.touches, 2, 0), 10, 250);
+                    context.fillText(angle(evt.touches, 2), 10, 300);
+                    context.closePath();
+
+                    // the outline
+                    context.lineWidth = 1;
+                    context.strokeStyle = '#666666';
+                    context.stroke();
+
+                    // the fill color
+                    context.fillStyle = "#FFCC00";
+                    context.fill();
+                }
+
+                
+                evt.preventDefault();
+            };
+
+		</script>
+	</body>
+</html>