jspsych/plugins/jspsych-rdk.js
//Calculates a random position on the opposite edge to reinsert the dot

Calculates a random position on the opposite edge to reinsert the dot
Calculates a random position on the opposite edge to reinsert the dot
function reinsertOnOppositeEdge(dot) {
			if (apertureType == 1 || apertureType == 2) {
				dot.x -= dot.latestXMove;
				dot.y -= dot.latestYMove;
				dot.x -= apertureCenterX;
				dot.y -= apertureCenterY;
				dot.x = -dot.x;
				dot.y = -dot.y;
				dot.x += apertureCenterX;
				dot.y += apertureCenterY;
			} 
			if (apertureType == 3 || apertureType == 4) {
				var absX = Math.abs(dot.latestXMove);
				var absY = Math.abs(dot.latestYMove);
				var weightInXDirection = absX / (absX + absY);
				var weightInYDirection = absY / (absX + absY);
				var weightOnVerticalEdge = (verticalAxis / (verticalAxis + horizontalAxis)) * weightInXDirection;
				var weightOnHorizontalEdge = (horizontalAxis / (verticalAxis + horizontalAxis)) * weightInYDirection;
				if (weightOnVerticalEdge > (weightOnHorizontalEdge + weightOnVerticalEdge) * Math.random()) { 
					if (dot.latestXMove < 0) { 
						dot.x = apertureCenterX + horizontalAxis;
						dot.y = randomNumberBetween((apertureCenterY) - verticalAxis, (apertureCenterY) + verticalAxis);
					} else { 
						dot.x = apertureCenterX - horizontalAxis;
						dot.y = randomNumberBetween((apertureCenterY) - verticalAxis, (apertureCenterY) + verticalAxis);
					}
				} else { 
					if (dot.latestYMove < 0) { 
						dot.y = apertureCenterY + verticalAxis;
						dot.x = randomNumberBetween((apertureCenterX) - horizontalAxis, (apertureCenterX) + horizontalAxis)
					} else { 
						dot.y = apertureCenterY - verticalAxis;
						dot.x = randomNumberBetween((apertureCenterX) - horizontalAxis, (apertureCenterX) + horizontalAxis)
					}
				}
			} 
			return dot;
		} 
function reinsertOnOppositeEdge ( dot ) { if ( apertureType == 1 || apertureType == 2 ) { dot . x -= dot . latestXMove ; dot . y -= dot . latestYMove ; dot . x -= apertureCenterX ; dot . y -= apertureCenterY ; dot . x = - dot . x ; dot . y = - dot . y ; dot . x += apertureCenterX ; dot . y += apertureCenterY ; } if ( apertureType == 3 || apertureType == 4 ) { var absX = Math . abs ( dot . latestXMove ) ; var absY = Math . abs ( dot . latestYMove ) ; var weightInXDirection = absX / ( absX + absY ) ; var weightInYDirection = absY / ( absX + absY ) ; var weightOnVerticalEdge = ( verticalAxis / ( verticalAxis + horizontalAxis ) ) * weightInXDirection ; var weightOnHorizontalEdge = ( horizontalAxis / ( verticalAxis + horizontalAxis ) ) * weightInYDirection ; if ( weightOnVerticalEdge > ( weightOnHorizontalEdge + weightOnVerticalEdge ) * Math . random ( ) ) { if ( dot . latestXMove < 0 ) { dot . x = apertureCenterX + horizontalAxis ; dot . y = randomNumberBetween ( ( apertureCenterY ) - verticalAxis , ( apertureCenterY ) + verticalAxis ) ; } else { dot . x = apertureCenterX - horizontalAxis ; dot . y = randomNumberBetween ( ( apertureCenterY ) - verticalAxis , ( apertureCenterY ) + verticalAxis ) ; } } else { if ( dot . latestYMove < 0 ) { dot . y = apertureCenterY + verticalAxis ; dot . x = randomNumberBetween ( ( apertureCenterX ) - horizontalAxis , ( apertureCenterX ) + horizontalAxis ) } else { dot . y = apertureCenterY - verticalAxis ; dot . x = randomNumberBetween ( ( apertureCenterX ) - horizontalAxis , ( apertureCenterX ) + horizontalAxis ) } } } return dot ; }
Calculates a random position on the opposite edge to reinsert the dot
Calculates a random position on the opposite edge to reinsert the dot
//If it is a circle or ellipse
 //Bring the dot back into the aperture by moving back one step
 //Move the dot to the position relative to the origin to be reflected about the origin
 //Reflect the dot about the origin
 //Move the dot back to the center of the screen
 //End of if apertureType == 1 | == 2
 //If it is a square or rectangle, re-insert on one of the opposite edges
 /* The formula for calculating whether a dot appears from the vertical edge (left or right edges) is dependent on the direction of the dot and the ratio of the vertical and horizontal edge lengths.
				E.g.  
				Aperture is 100 px high and 200px wide
				Dot is moving 3 px in x direction and 4px in y direction
				Weight on vertical edge (sides)           = (100/(100+200)) * (|3| / (|3| + |4|)) = 1/7
				Weight on horizontal edge (top or bottom) = (200/(100+200)) * (|4| / (|3| + |4|)) = 8/21
			
				The weights above are the ratios to one another.
				E.g. (cont.)
				Ratio (vertical edge : horizontal edge) == (1/7 : 8/21)
				Total probability space = 1/7 + 8/21 = 11/21
				Probability that dot appears on vertical edge   = (1/7)/(11/21) = 3/11
				Probability that dot appears on horizontal edge = (8/21)/(11/21) = 8/11
				*/ //Get the absolute values of the latest X and Y moves and store them in variables for easy handling.
 //Calculate the direction weights based on direction the dot was moving
 //Calculate the weight of the edge the dot should appear from, based on direction of dot and ratio of the aperture edges
 //Generate a bounded random number to determine if the dot should appear on the vertical edge or the horizontal edge
 //If yes, appear on the left or right edge (vertical edge)
 //If dots move left, appear on right edge
 //Else dots move right, so they should appear on the left edge
 //Else appear on the top or bottom edge (horizontal edge)
 //If dots move upwards, then appear on bottom edge
 //If dots move downwards, then appear on top edge
 //End of apertureType == 3
 //End of reinsertOnOppositeEdge
