-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMiscSpace.j
108 lines (84 loc) · 2.5 KB
/
MiscSpace.j
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
This file is part of FrACT10, a vision test battery.
Copyright © 2023 Michael Bach, bach@uni-freiburg.de, <https://michaelbach.de>
Misc.j
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import "Settings.j"
/**
A collection of "miscellaneous" functions for spatial aspects (degrees, acuity, …).
All a class variables for easy global access,
*/
@implementation MiscSpace: CPObject {
}
/**
Convert degrees to pixels
*/
+ (float) pixelFromDegree: (float) degs { //console.info("pixelFromDegree");
const mm = Math.tan(degs * Math.PI / 180) * 10 * [Settings distanceInCM];
return [self pixelFromMillimeter: mm];
}
/**
Convert pixels to degrees
*/
+ (float) degreeFromPixel: (float) pixel { //console.info("Misc>pixelFromDegree");
return 180 / Math.PI * Math.atan2([self millimeterFromPixel: pixel], [Settings distanceInCM] * 10);
}
/**
Convert to period from spatial frequency
*/
+ (float) periodInPixelFromSpatialFrequency: (float) f {
let p = [MiscSpace pixelFromDegree: 1 / f];
return p;
}
+ (float) spatialFrequencyFromPeriodInPixel: (float) p {
let f = 1 / [MiscSpace degreeFromPixel: p];
return f;
}
+ (float) millimeterFromPixel: (float) pixel {
return pixel * [Settings calBarLengthInMM] / gCalBarLengthInPixel;
}
+ (float) pixelFromMillimeter: (float) inMM { //console.info("pixelFromMillimeter");
return inMM * gCalBarLengthInPixel / [Settings calBarLengthInMM];
}
/**
Given stroke size in pixels, calculates decimal VA
*/
+ (float) decVAFromStrokePixels: (float) pixels { // "decVA": visual acuity in decimal format
return 1 / 60 / [self degreeFromPixel: pixels];
}
/**
And the inverse
*/
+ (float) strokePixelsFromDecVA: (float) decVA {
return [self pixelFromDegree: (1 / 60 / decVA)];
}
/**
Given decimal VA, returns equivalent LogMAR
*/
+ (float) logMARfromDecVA: (float) decVA {
return -Math.log10(decVA);
}
/**
And the inverse
*/
+ (float) decVAfromLogMAR: (float) logMAR {
return Math.pow(10, -logMAR);
}
/* ///////////////////////////////////// OLD, not in use (yet) */
/*
static public function spatFreq2periodInPix(spatFreqInCPD:Number):Number {
return 2 * PixelFromDegree(1.0 / spatFreqInCPD / 2)
}
static public function periodInPix2spatFreq(periodInPix:Number):Number {
return 0.5 / (DegreeFromPixel(periodInPix / 2.0))
}
static public function cpd2logMAR(cpd:Number):Number {
return log10(30.0 / cpd);
}
static public function logMAR2cpd(logMAR:Number):Number {
return 30.0 / (Math.pow(10, logMAR));
}
*/
@end