@@ -93,7 +93,7 @@ context.moduleContexts.robot_minigame.state = state;
9393
9494/**
9595 * Shorthand function that initializes a new simulation with a map of size width * height
96- * Also sets the initial position an rotation of the robot
96+ * Also sets the initial position and rotation of the robot
9797 *
9898 * @param width of the map
9999 * @param height of the map
@@ -127,7 +127,7 @@ export function init(
127127}
128128
129129/**
130- * Creates a new area with the given vertices and flags
130+ * Create a new area with the given vertices and flags
131131 *
132132 * @param vertices of the area in alternating x-y pairs
133133 * @param isObstacle a boolean indicating if the area is an obstacle or not
@@ -180,10 +180,10 @@ export function create_area(
180180}
181181
182182/**
183- * Creates a new rectangular, axis-aligned area
183+ * Create a new rectangular, axis-aligned area
184184 *
185- * @param x top left corner of the rectangle
186- * @param y top right corner of the rectangle
185+ * @param x coordinate of the top left corner of the rectangle
186+ * @param y coordinate of the top left corner of the rectangle
187187 * @param width of the rectangle
188188 * @param height of the rectangle
189189 * @param isObstacle a boolean indicating if the area is an obstacle or not
@@ -209,7 +209,7 @@ export function create_rect_area(
209209}
210210
211211/**
212- * Creates a new obstacle
212+ * Create a new obstacle
213213 *
214214 * @param vertices of the obstacle
215215 */
@@ -223,10 +223,10 @@ export function create_obstacle(
223223}
224224
225225/**
226- * Creates a new rectangular, axis-aligned obstacle
226+ * Create a new rectangular, axis-aligned obstacle
227227 *
228- * @param x top left corner of the rectangle
229- * @param y top right corner of the rectangle
228+ * @param x coordinate of the top left corner of the rectangle
229+ * @param y coordinate of the top left corner of the rectangle
230230 * @param width of the rectangle
231231 * @param height of the rectangle
232232 */
@@ -254,7 +254,7 @@ export function complete_init() {
254254// ======= //
255255
256256/**
257- * Get the distance to the closest collidable area
257+ * Get the distance to the closest obstacle
258258 *
259259 * @returns the distance to the closest obstacle, or infinity (if robot is out of bounds)
260260 */
@@ -276,24 +276,7 @@ export function get_distance() : number {
276276}
277277
278278/**
279- * Gets the flags of the area containing the point (x, y)
280- *
281- * @param x coordinate
282- * @param y coordinate
283- * @returns the flags of the area containing (x, y)
284- */
285- export function get_flags (
286- x : number ,
287- y : number
288- ) : AreaFlags {
289- // Find the area containing the point
290- const area : Area | null = area_of_point ( { x, y} ) ;
291-
292- return area === null ? { } : area . flags ;
293- }
294-
295- /**
296- * Gets the color of the area under the robot
279+ * Get the color of the area under the robot
297280 *
298281 * @returns the color of the area under the robot
299282 */
@@ -358,9 +341,9 @@ export function move_forward_to_wall() {
358341}
359342
360343/**
361- * Rotates the robot clockwise by the given angle
344+ * Rotate the robot clockwise by the given angle
362345 *
363- * @param angle the angle (in radians) to rotate clockwise
346+ * @param angle (in radians) to rotate clockwise
364347 */
365348export function rotate (
366349 angle : number
@@ -379,7 +362,7 @@ export function rotate(
379362}
380363
381364/**
382- * Turns the robot 90 degrees to the left
365+ * Turn the robot 90 degrees to the left
383366 */
384367export function turn_left ( ) {
385368 let currentAngle = Math . atan2 ( - robot . dy , robot . dx ) ;
@@ -397,7 +380,7 @@ export function turn_left() {
397380}
398381
399382/**
400- * Turns the robot 90 degrees to the right
383+ * Turn the robot 90 degrees to the right
401384 */
402385export function turn_right ( ) {
403386 let currentAngle = Math . atan2 ( - robot . dy , robot . dx ) ;
@@ -427,9 +410,9 @@ export function start_testing() {
427410}
428411
429412/**
430- * Checks if the robot's entered areas satisfy the condition
413+ * Checks if the robot's entered areas satisfy the callback
431414 *
432- * @returns if the entered areas satisfy the condition
415+ * @returns if the entered areas satisfy the callback
433416 */
434417export function entered_areas (
435418 callback : ( areas : Area [ ] ) => boolean
@@ -443,7 +426,7 @@ export function entered_areas(
443426/**
444427 * Check if the robot has entered different areas with the given colors in order
445428 *
446- * @param colors in order
429+ * @param colors in the order visited
447430 * @returns if the robot entered the given colors in order
448431 */
449432export function entered_colors (
@@ -458,6 +441,12 @@ export function entered_colors(
458441 . every ( ( { flags : { color } } , i ) => color === colors [ i ] ) ; // Check if each area has the expected color
459442}
460443
444+ // ==================
445+ // ==================
446+ // PRIVATE FUNCTIONS:
447+ // ==================
448+ // ==================
449+
461450// ================== //
462451// DATA WRITE HELPERS //
463452// ================== //
@@ -756,6 +745,10 @@ function logArea(
756745 state . areaLog . push ( area ) ;
757746}
758747
748+ // ============ //
749+ // AREA HELPERS //
750+ // ============ //
751+
759752/**
760753 * Compare two areas for equality
761754 *
@@ -785,3 +778,20 @@ function areaEquals(a: Area, b: Area) {
785778const filterAdjacentDuplicateAreas = ( area : Area , i : number , areas : Area [ ] ) : boolean =>
786779 i === 0 // First one is always correct
787780 || ! areaEquals ( area , areas [ i - 1 ] ) ; // Otherwise check for equality against previous area
781+
782+ /**
783+ * Gets the flags of the area containing the point (x, y)
784+ *
785+ * @param x coordinate
786+ * @param y coordinate
787+ * @returns the flags of the area containing (x, y)
788+ */
789+ function get_flags (
790+ x : number ,
791+ y : number
792+ ) : AreaFlags {
793+ // Find the area containing the point
794+ const area : Area | null = area_of_point ( { x, y} ) ;
795+
796+ return area === null ? { } : area . flags ;
797+ }
0 commit comments