Skip to content

Commit

Permalink
Updates to gator class syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Checkmate50 committed Jul 8, 2019
1 parent d9e359f commit 0cd8edb
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 79 deletions.
4 changes: 2 additions & 2 deletions semantics/gator_draft.tex
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ \subsection{Context Declarations}
return s * x;
}

hom<vector> -(hom<position> x, hom<position> y) {
hom.vector -(hom.position x, hom.position y) {
// We use n rather than n-1 since hom has dimension n+1
return x * y[n] - y * x[n]
}

hom<position> +(hom<position> x, hom<vector> y) {
hom.position +(hom.position x, hom.vector y) {
return x + y * x[n]
}
\end{lstlisting}
Expand Down
2 changes: 0 additions & 2 deletions test/types/assign.expect

This file was deleted.

18 changes: 0 additions & 18 deletions test/types/assign.lgl

This file was deleted.

1 change: 1 addition & 0 deletions test/types/basics.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[3., 3., 3.]
12 changes: 12 additions & 0 deletions test/types/basics.lgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type a is float[2];
type b is float[3];
type c is b;
type d is b;

void main() {
a x = [1., 2.];
b y = [2., 1., 1.];
c z = [3., 3., 3.];

print z;
}
7 changes: 0 additions & 7 deletions test/types/decl.lgl

This file was deleted.

File renamed without changes.
19 changes: 19 additions & 0 deletions test/types/geobasics.lgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
object point;
object vector;

coord cart<n> [n] {}
coord polar<2> [2] {}
coord hom<n> [n+1] {}

frame world is float[3];
frame plane is float[2];

void main() {
cart<world>.point pos = [1., 2., 3.];
cart<plane>.vector offset = [2., 2.];
polar<plane>.point ppos = [1., 0.];
hom<world>.point extended = [1., 2., 3., 1.];
hom<plane>.vector poffset = [1., 3., 5.];

print 1;
}
3 changes: 3 additions & 0 deletions test/types/geops.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[1., 2., 3.]
[2., 2., 2.]
[1., 2., 3., 1.]
125 changes: 125 additions & 0 deletions test/types/geops.lgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
declare float cos(float f);
declare float sqrt(float f);
declare float acos(float f);

prototype {
object point<r>;
object vector<r>;

vector<r> +(vector<r> x, vector<r> y);
vector -(vector x, vector y);
vector *(vector v, scalar s);
vector *(scalar s, vector v);
vector -(vector v);
position +(position p, vector v);
vector -(position x, position y);
}
coord cart2 {
dimension 2; // i.e. all frame parameters implicitly require dimension 2
point<r> = float[2];
vector<r> = float[2];

vector<r> +(vector<r> x, vector<r> y) {
return x + y;
}
vector -(vector x, vector y) {
return x - y;
}
vector *(vector v, scalar s) {
return v * s;
}
vector *(scalar s, vector v) {
return s * v;
}
vector -(vector v) {
return -v;
}
position +(position p, vector v) {
return p + v;
}
vector -(position x, position y) {
return x - y;
}
}
coord cart3 {
point = float[3];
vector = float[3];
vector +(vector x, vector y) {
return x + y;
}
vector -(vector x, vector y) {
return x - y;
}
vector *(vector v, scalar s) {
return v * s;
}
vector *(scalar s, vector v) {
return s * v;
}
vector -(vector v) {
return -v;
}
position +(position p, vector v) {
return p + v;
}
vector -(position x, position y) {
return x - y;
}
}
coord polar {
point = float[2];
vector = float[2];
float[2]% translate(float[2]% x, float[2]% y) {
// https://pritschet.me/wiki/physics/linear-translation-polar-coordinates/
float r1 = x[0];
float r2 = y[0];
float theta1 = x[1];
float theta2 = x[2];
float r = sqrt(r1 * r1 + r2 * r2 + 2 * r1 * r2 * cos(theta1 - theta2));
float theta = acos((r1 * cos(theta1) + r2 * cos(theta2)) / r);
return [r, theta];
}
vector +(vector x, vector y) {
return translate(x, y);
}
vector -(vector x, vector y) {
return translate(x, [-y[0], y[1]]);
}
vector *(vector v, scalar s) {
return [v[0] * s, v[1]];
}
vector *(scalar s, vector v) {
return [s * v[0], v[1]];
}
vector -(vector v) {
return [-v[0], v[1]];
}
position +(position p, vector v) {
return translate(p, v);
}
vector -(position x, position y) {
return translate(x, [-y[0], y[1]]);
}
}
coord hom {
object point = float[4];
object vector = float[4];

hom *(scalar s, hom x) {
float[n+1] y = x * s;
y[n] = 1.;
return y;
}
}

frame model is float[3];
frame world is float[3];

void main() {
cart<model>.point pos = [1., 2., 3.];
cart<model>.vector offset = [2., 2., 2.];

print pos + offset;
print

}
11 changes: 0 additions & 11 deletions test/types/scale.expect

This file was deleted.

39 changes: 0 additions & 39 deletions test/types/scale.lgl

This file was deleted.

0 comments on commit 0cd8edb

Please sign in to comment.