-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.pde
More file actions
51 lines (39 loc) · 1.32 KB
/
Utils.pde
File metadata and controls
51 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Collision detection
// copied and adapted from http://www.jeffreythompson.org/collision-detection/point-rect.php
// POINT/RECTANGLE
boolean isPointInRectangle(float px, float py, float rx, float ry, float rw, float rh) {
return px >= rx && px <= rx + rw && py >= ry && py <= ry + rh;
}
// trace functions:
// traceWithTime( String traceMessage )
// traceIfChanged( String id , String logLine )
import java.util.Map;
import java.util.HashMap;
private static float start = System.nanoTime();
/**
* Traces a string preceded with the current time.
* @param traceMessage Message to be traced.
*/
public static void traceWithTime( String traceMessage )
{
float now = timeSinceStartInSeconds();
println( now + " > " + traceMessage );
}
/**
* Returns the number of seconds since the start of the execution.
*/
public static int timeSinceStartInSeconds()
{
return (int) ( ( System.nanoTime() - start ) / 1e9 );
}
private static Map<String,String> logid2line = new HashMap<String,String>();
/**
* Only logs data associated with an id, if and only if the *data* has changed.
*/
public static void traceIfChanged( String id , String logLine )
{
if ( !logid2line.containsKey(id) || !logid2line.get(id).equals( logLine ) ) {
println( id + " = " + logLine );
logid2line.put( id, logLine );
}
}