[SCM] Lisaac library math branch, master, updated. 95432df7db6429dcc6ae3a62b0d87295cde3e12e
Damien Bouvarel
dams.bouvarel at wanadoo.fr
Wed Aug 26 23:44:37 UTC 2009
The following commit has been merged in the master branch:
commit d913aa022c08ec9831f55ffdcb2c16e702010deb
Author: Damien Bouvarel <dams.bouvarel at wanadoo.fr>
Date: Mon Aug 24 08:44:20 2009 +0200
start clean lib
diff --git a/low_level/abstract_matrix.li b/low_level/abstract_matrix.li
index dd27a6d..8eed570 100644
--- a/low_level/abstract_matrix.li
+++ b/low_level/abstract_matrix.li
@@ -1,163 +1,163 @@
-///////////////////////////////////////////////////////////////////////////////
-// Math-Library //
-// //
-// LSIIT - ULP - CNRS - INRIA - FRANCE //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation, either version 3 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details. //
-// //
-// You should have received a copy of the GNU General Public License //
-// along with this program. If not, see <http://www.gnu.org/licenses/>. //
-// //
-// http://isaacproject.u-strasbg.fr/ //
-///////////////////////////////////////////////////////////////////////////////
-
-Section Header
-
- + name := ABSTRACT_MATRIX[E];
-
- - comment := "(n,m) matrix";
-
-Section Inherit
-
- - parent_object:OBJECT := OBJECT;
-
-Section Private
-
- + storage:FAST_ARRAY2[E];
-
-Section Public
-
- - lines:INTEGER <- storage.count1;
- - columns:INTEGER <- storage.coun2;
-
-
- - make (n,m:INTEGER) <-
- (
- storage := FAST_ARRAY2[E].create (n,m);
- );
-
- - create_from v:FAST_ARRAY2[E] :SELF <-
- ( + result:SELF;
- result := SELF.clone;
- result.make_from v;
- result
- );
-
- - make_from v:FAST_ARRAY2[E] <-
- (
- storage := v;
- );
-
-
- //
- // Access.
- //
-
- - copy other:SELF <-
- (
- storage.copy (other.getv);
- );
-
- - zero:SELF <- create (lines,columns) value (E.zero);
-
-
- - put v:E to (l,c:INTEGER) <-
- (
- storage.put v to (l,c);
- );
-
- - set_all_with val:E <-
- (
- storage.set_all_with val;
- );
-
- - item (l,c:INTEGER) :E <-
- (
- storage.item (l,c)
- );
-
- - getv:FAST_ARRAY2[E] <-
- (
- storage
- );
-
- - to_external:POINTER <-
- (
- storage.to_external
- );
-
- //
- // Operations.
- //
-
- - put_foreach block:BLOCK <-
- (
- storage.lower1.to (storage.upper1) do { line:INTEGER;
- storage.lower2.to (storage.upper2) do { column:INTEGER;
- storage.put (block.value (line,column)) to (line, column);
- };
- };
- );
-
- - load_identity <-
- (
- put_foreach { (l,c:INTEGER);
- + result:E;
-
- (l = c).if {
- result := E.one;
- } else {
- result := E.zero;
- };
- result
- };
- );
-
- - '+' Left 80 other:SELF :SELF <-
- ( + m:FAST_ARRAY[E];
-
- m := FAST_ARRAY[E].create (lines,columns);
- m.put_foreach { (l,c:INTEGER);
- item (l,c) + other.item (l,c)
- };
- create_from m
- );
-
- - '-' Left 80 other:SELF :SELF <-
- ( + m:FAST_ARRAY[E];
-
- m := FAST_ARRAY[E].create (lines,columns);
- m.put_foreach { (l,c:INTEGER);
- item (l,c) - other.item (l,c)
- };
- create_from m
- );
-
- - '*' Left 100 scalar:E :SELF <-
- ( + m:FAST_ARRAY[E];
-
- m := FAST_ARRAY[E].create (lines,columns);
- m.put_foreach { (l,c:INTEGER);
- item (l,c) * scalar
- };
- create_from m
- );
-
- - print <-
- (
- storage.lower1.to (storage.upper1) do { line:INTEGER;
- "( ".print;
- storage.lower2.to (storage.upper2) do { column:INTEGER;
- storage.item (line,column).print; " ".print;
- };
- ")\n".print;
- };
+///////////////////////////////////////////////////////////////////////////////
+// Math-Library //
+// //
+// LSIIT - ULP - CNRS - INRIA - FRANCE //
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see <http://www.gnu.org/licenses/>. //
+// //
+// http://isaacproject.u-strasbg.fr/ //
+///////////////////////////////////////////////////////////////////////////////
+
+Section Header
+
+ + name := ABSTRACT_MATRIX[E];
+
+ - comment := "(n,m) matrix";
+
+Section Inherit
+
+ - parent_object:OBJECT := OBJECT;
+
+Section Private
+
+ + storage:FAST_ARRAY2[E];
+
+Section Public
+
+ - lines:INTEGER <- storage.count1;
+ - columns:INTEGER <- storage.coun2;
+
+
+ - make (n,m:INTEGER) <-
+ (
+ storage := FAST_ARRAY2[E].create (n,m);
+ );
+
+ - create_from v:FAST_ARRAY2[E] :SELF <-
+ ( + result:SELF;
+ result := SELF.clone;
+ result.make_from v;
+ result
+ );
+
+ - make_from v:FAST_ARRAY2[E] <-
+ (
+ storage := v;
+ );
+
+
+ //
+ // Access.
+ //
+
+ - copy other:SELF <-
+ (
+ storage.copy (other.getv);
+ );
+
+ - zero:SELF <- create (lines,columns) value (E.zero);
+
+
+ - put v:E to (l,c:INTEGER) <-
+ (
+ storage.put v to (l,c);
+ );
+
+ - set_all_with val:E <-
+ (
+ storage.set_all_with val;
+ );
+
+ - item (l,c:INTEGER) :E <-
+ (
+ storage.item (l,c)
+ );
+
+ - getv:FAST_ARRAY2[E] <-
+ (
+ storage
+ );
+
+ - to_external:POINTER <-
+ (
+ storage.to_external
+ );
+
+ //
+ // Operations.
+ //
+
+ - put_foreach block:BLOCK <-
+ (
+ storage.lower1.to (storage.upper1) do { line:INTEGER;
+ storage.lower2.to (storage.upper2) do { column:INTEGER;
+ storage.put (block.value (line,column)) to (line, column);
+ };
+ };
+ );
+
+ - load_identity <-
+ (
+ put_foreach { (l,c:INTEGER);
+ + result:E;
+
+ (l = c).if {
+ result := E.one;
+ } else {
+ result := E.zero;
+ };
+ result
+ };
+ );
+
+ - '+' Left 80 other:SELF :SELF <-
+ ( + m:FAST_ARRAY[E];
+
+ m := FAST_ARRAY[E].create (lines,columns);
+ m.put_foreach { (l,c:INTEGER);
+ item (l,c) + other.item (l,c)
+ };
+ create_from m
+ );
+
+ - '-' Left 80 other:SELF :SELF <-
+ ( + m:FAST_ARRAY[E];
+
+ m := FAST_ARRAY[E].create (lines,columns);
+ m.put_foreach { (l,c:INTEGER);
+ item (l,c) - other.item (l,c)
+ };
+ create_from m
+ );
+
+ - '*' Left 100 scalar:E :SELF <-
+ ( + m:FAST_ARRAY[E];
+
+ m := FAST_ARRAY[E].create (lines,columns);
+ m.put_foreach { (l,c:INTEGER);
+ item (l,c) * scalar
+ };
+ create_from m
+ );
+
+ - print <-
+ (
+ storage.lower1.to (storage.upper1) do { line:INTEGER;
+ "( ".print;
+ storage.lower2.to (storage.upper2) do { column:INTEGER;
+ storage.item (line,column).print; " ".print;
+ };
+ ")\n".print;
+ };
);
\ No newline at end of file
diff --git a/matrix.li b/matrix.li
index b1773b6..dc6c280 100644
--- a/matrix.li
+++ b/matrix.li
@@ -1,51 +1,51 @@
-///////////////////////////////////////////////////////////////////////////////
-// Math-Library //
-// //
-// LSIIT - ULP - CNRS - INRIA - FRANCE //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation, either version 3 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details. //
-// //
-// You should have received a copy of the GNU General Public License //
-// along with this program. If not, see <http://www.gnu.org/licenses/>. //
-// //
-// http://isaacproject.u-strasbg.fr/ //
-///////////////////////////////////////////////////////////////////////////////
-
-Section Header
-
- + name := MATRIX[E];
-
- - comment := "(n,m) matrix";
-
-Section Inherit
-
- - parent_abstract_matrix:Expanded ABSTRACT_MATRIX[E];
-
-Section Public
-
- //
- // Creation.
- //
-
- - create (n,m:INTEGER) :SELF <-
- ( + result:SELF;
- result := SELF.clone;
- result.make (n,m);
- result
- );
-
- - create (n,m:INTEGER) value val:E :SELF <-
- ( + result:SELF;
- result := SELF.clone;
- result.make (n,m);
- result.set_all_with val;
- result
+///////////////////////////////////////////////////////////////////////////////
+// Math-Library //
+// //
+// LSIIT - ULP - CNRS - INRIA - FRANCE //
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see <http://www.gnu.org/licenses/>. //
+// //
+// http://isaacproject.u-strasbg.fr/ //
+///////////////////////////////////////////////////////////////////////////////
+
+Section Header
+
+ + name := MATRIX[E];
+
+ - comment := "(n,m) matrix";
+
+Section Inherit
+
+ - parent_abstract_matrix:Expanded ABSTRACT_MATRIX[E];
+
+Section Public
+
+ //
+ // Creation.
+ //
+
+ - create (n,m:INTEGER) :SELF <-
+ ( + result:SELF;
+ result := SELF.clone;
+ result.make (n,m);
+ result
+ );
+
+ - create (n,m:INTEGER) value val:E :SELF <-
+ ( + result:SELF;
+ result := SELF.clone;
+ result.make (n,m);
+ result.set_all_with val;
+ result
);
\ No newline at end of file
diff --git a/matrix4.li b/matrix4.li
index 89ed2f1..68d2c45 100644
--- a/matrix4.li
+++ b/matrix4.li
@@ -1,61 +1,61 @@
-///////////////////////////////////////////////////////////////////////////////
-// Math-Library //
-// //
-// LSIIT - ULP - CNRS - INRIA - FRANCE //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation, either version 3 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details. //
-// //
-// You should have received a copy of the GNU General Public License //
-// along with this program. If not, see <http://www.gnu.org/licenses/>. //
-// //
-// http://isaacproject.u-strasbg.fr/ //
-///////////////////////////////////////////////////////////////////////////////
-
-Section Header
-
- + name := MATRIX4[E];
-
- - comment := "4x4 matrix";
-
-Section Inherit
-
- + parent_matrix:Expanded ABSTRACT_MATRIX[E];
-
-Section Public
-
- - lines:INTEGER <- 4;
- - columns:INTEGER <- 4;
-
- //
- // Creation.
- //
-
- - create:SELF <-
- ( + result:SELF;
- result := clone;
- result.make (4,4);
- result
- );
-
- - create_value val:INTEGER :SELF <-
- ( + result:SELF;
- result := clone;
- result.make (4,4);
- result.set_all_with val;
- result
- );
-
- //
- //
- //
-
-
+///////////////////////////////////////////////////////////////////////////////
+// Math-Library //
+// //
+// LSIIT - ULP - CNRS - INRIA - FRANCE //
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see <http://www.gnu.org/licenses/>. //
+// //
+// http://isaacproject.u-strasbg.fr/ //
+///////////////////////////////////////////////////////////////////////////////
+
+Section Header
+
+ + name := MATRIX4[E];
+
+ - comment := "4x4 matrix";
+
+Section Inherit
+
+ + parent_matrix:Expanded ABSTRACT_MATRIX[E];
+
+Section Public
+
+ - lines:INTEGER <- 4;
+ - columns:INTEGER <- 4;
+
+ //
+ // Creation.
+ //
+
+ - create:SELF <-
+ ( + result:SELF;
+ result := clone;
+ result.make (4,4);
+ result
+ );
+
+ - create_value val:INTEGER :SELF <-
+ ( + result:SELF;
+ result := clone;
+ result.make (4,4);
+ result.set_all_with val;
+ result
+ );
+
+ //
+ //
+ //
+
+
\ No newline at end of file
diff --git a/vector2.li b/vector2.li
index 3b29e88..0e6cf12 100644
--- a/vector2.li
+++ b/vector2.li
@@ -1,135 +1,135 @@
-///////////////////////////////////////////////////////////////////////////////
-// Math-Library //
-// //
-// LSIIT - ULP - CNRS - INRIA - FRANCE //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation, either version 3 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details. //
-// //
-// You should have received a copy of the GNU General Public License //
-// along with this program. If not, see <http://www.gnu.org/licenses/>. //
-// //
-// http://isaacproject.u-strasbg.fr/ //
-///////////////////////////////////////////////////////////////////////////////
-
-Section Header
-
- + name := VECTOR2[E];
-
- - comment := "(x,y) vector";
-
-Section Inherit
-
- - parent_object:OBJECT := OBJECT;
-
-Section Public
-
- + x:E;
- + y:E;
-
- - create (a,b:E) :SELF <-
- ( + result:SELF;
- result := SELF.clone;
- result.make (a,b);
- result
- );
-
- - make (a,b:E) <-
- (
- x := a;
- y := b;
- );
-
- - copy :SELF <-
- (
- create (x,y)
- );
-
- - zero:SELF <- create (E.zero,E.zero);
-
- - set_x v:E <-
- (
- x := v;
- );
- - set_y v:E <-
- (
- y := v;
- );
-
- - get :(E,E) <-
- (
- x, y
- );
-
- - getv:FAST_ARRAY[E] <-
- (
- + result:FAST_ARRAY[E];
-
- result := FAST_ARRAY[E].create 2;
- result.put x to 0;
- result.put y to 1;
- result
- );
-
- - '-' :SELF <-
- (
- create (-x, -y)
- );
-
- - '+' Left 80 other:SELF :SELF <-
- (
- create (x + other.x, y + other.y)
- );
-
- - '-' Left 80 other:SELF :SELF <-
- (
- create (x - other.x, y - other.y)
- );
-
- - '*' Left 100 scalar:E :SELF <-
- (
- create (scalar * x, scalar * y)
- );
-
- - '/' Left 100 scalar:E :SELF <-
- (
- ? {scalar != 0};
- create (x / scalar, y / scalar)
- );
-
- - magnitude:E <-
- // magnitude = sqrt(x^2 + y^2)
- (
- (x*x + y*y).sqrt
- );
-
- - normalize <-
- // normalize self vector (of length 1)
- ( + m:E;
-
- m := magnitude;
- make (x/m, y/m);
- );
-
- - normalized :SELF <-
- // return a normalized vector (of length 1) from self
- (
- Self / magnitude
- );
-
- - dot other:SELF :E <-
- (
- x*other.x + y*other.y
- );
-
- - print <-
- (
- "(".print; x.print;", ".print; y.print; ")".print;
+///////////////////////////////////////////////////////////////////////////////
+// Math-Library //
+// //
+// LSIIT - ULP - CNRS - INRIA - FRANCE //
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see <http://www.gnu.org/licenses/>. //
+// //
+// http://isaacproject.u-strasbg.fr/ //
+///////////////////////////////////////////////////////////////////////////////
+
+Section Header
+
+ + name := VECTOR2[E];
+
+ - comment := "(x,y) vector";
+
+Section Inherit
+
+ - parent_object:OBJECT := OBJECT;
+
+Section Public
+
+ + x:E;
+ + y:E;
+
+ - create (a,b:E) :SELF <-
+ ( + result:SELF;
+ result := SELF.clone;
+ result.make (a,b);
+ result
+ );
+
+ - make (a,b:E) <-
+ (
+ x := a;
+ y := b;
+ );
+
+ - copy :SELF <-
+ (
+ create (x,y)
+ );
+
+ - zero:SELF <- create (E.zero,E.zero);
+
+ - set_x v:E <-
+ (
+ x := v;
+ );
+ - set_y v:E <-
+ (
+ y := v;
+ );
+
+ - get :(E,E) <-
+ (
+ x, y
+ );
+
+ - getv:FAST_ARRAY[E] <-
+ (
+ + result:FAST_ARRAY[E];
+
+ result := FAST_ARRAY[E].create 2;
+ result.put x to 0;
+ result.put y to 1;
+ result
+ );
+
+ - '-' :SELF <-
+ (
+ create (-x, -y)
+ );
+
+ - '+' Left 80 other:SELF :SELF <-
+ (
+ create (x + other.x, y + other.y)
+ );
+
+ - '-' Left 80 other:SELF :SELF <-
+ (
+ create (x - other.x, y - other.y)
+ );
+
+ - '*' Left 100 scalar:E :SELF <-
+ (
+ create (scalar * x, scalar * y)
+ );
+
+ - '/' Left 100 scalar:E :SELF <-
+ (
+ ? {scalar != 0};
+ create (x / scalar, y / scalar)
+ );
+
+ - magnitude:E <-
+ // magnitude = sqrt(x^2 + y^2)
+ (
+ (x*x + y*y).sqrt
+ );
+
+ - normalize <-
+ // normalize self vector (of length 1)
+ ( + m:E;
+
+ m := magnitude;
+ make (x/m, y/m);
+ );
+
+ - normalized :SELF <-
+ // return a normalized vector (of length 1) from self
+ (
+ Self / magnitude
+ );
+
+ - dot other:SELF :E <-
+ (
+ x*other.x + y*other.y
+ );
+
+ - print <-
+ (
+ "(".print; x.print;", ".print; y.print; ")".print;
);
\ No newline at end of file
diff --git a/vector3.li b/vector3.li
index 7b01c05..744b370 100644
--- a/vector3.li
+++ b/vector3.li
@@ -1,156 +1,156 @@
-///////////////////////////////////////////////////////////////////////////////
-// Math-Library //
-// //
-// LSIIT - ULP - CNRS - INRIA - FRANCE //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation, either version 3 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details. //
-// //
-// You should have received a copy of the GNU General Public License //
-// along with this program. If not, see <http://www.gnu.org/licenses/>. //
-// //
-// http://isaacproject.u-strasbg.fr/ //
-///////////////////////////////////////////////////////////////////////////////
-
-Section Header
-
- + name := VECTOR3[E];
-
- - comment := "(x,y,z) vector";
-
-Section Inherit
-
- - parent_object:OBJECT := OBJECT;
-
-Section Public
-
- + x:E;
- + y:E;
- + z:E;
-
- - create (a,b,c:E) :SELF <-
- ( + result:SELF;
- result := SELF.clone;
- result.make (a,b,c);
- result
- );
-
- - make (a,b,c:E) <-
- (
- x := a;
- y := b;
- z := c;
- );
-
- - copy :SELF <-
- (
- create (x,y,z)
- );
-
- - zero:SELF <- create (E.zero,E.zero,E.zero);
-
- - set_x v:E <-
- (
- x := v;
- );
- - set_y v:E <-
- (
- y := v;
- );
- - set_z v:E <-
- (
- z := v;
- );
-
- - get :(E,E,E) <-
- (
- x, y, z
- );
-
- - getv:FAST_ARRAY[E] <-
- (
- + result:FAST_ARRAY[E];
-
- result := FAST_ARRAY[E].create 3;
- result.put x to 0;
- result.put y to 1;
- result.put z to 2;
- result
- );
-
- - '-' :SELF <-
- (
- create (-x, -y, -z)
- );
-
- - '+' Left 80 other:SELF :SELF <-
- (
- create (x + other.x, y + other.y, z + other.z)
- );
-
- - '-' Left 80 other:SELF :SELF <-
- (
- create (x - other.x, y - other.y, z - other.z)
- );
-
- - '*' Left 100 scalar:E :SELF <-
- (
- create (scalar * x, scalar * y, scalar * z)
- );
-
- - '/' Left 100 scalar:E :SELF <-
- (
- ? {scalar != 0};
- create (x / scalar, y / scalar, z / scalar)
- );
-
- - magnitude:E <-
- // magnitude = sqrt(V.x^2 + V.y^2 + V.z^2)
- (
- (x*x + y*y + z*z).sqrt
- );
-
- - normalize <-
- // normalize self vector (of length 1)
- ( + m:E;
-
- m := magnitude;
- make (x/m, y/m, z/m);
- );
-
- - normalized :SELF <-
- // return a normalized vector (of length 1) from self
- (
- Self / magnitude
- );
-
- - dot other:SELF :E <-
- (
- x*other.x + y*other.y + z*other.z
- );
-
- - cross other:SELF :SELF <-
- // calculate the cross product
- (
- + nx,ny,nz:E;
-
- nx := (y * other.z) - (z * other.y);
- ny := (z * other.x) - (x * other.z);
- nz := (x * other.y) - (y * other.x);
-
- create (nx,ny,nz)
- );
-
-
- - print <-
- (
- "(".print; x.print;", ".print; y.print; ", ".print;
- z.print; ")".print;
+///////////////////////////////////////////////////////////////////////////////
+// Math-Library //
+// //
+// LSIIT - ULP - CNRS - INRIA - FRANCE //
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see <http://www.gnu.org/licenses/>. //
+// //
+// http://isaacproject.u-strasbg.fr/ //
+///////////////////////////////////////////////////////////////////////////////
+
+Section Header
+
+ + name := VECTOR3[E];
+
+ - comment := "(x,y,z) vector";
+
+Section Inherit
+
+ - parent_object:OBJECT := OBJECT;
+
+Section Public
+
+ + x:E;
+ + y:E;
+ + z:E;
+
+ - create (a,b,c:E) :SELF <-
+ ( + result:SELF;
+ result := SELF.clone;
+ result.make (a,b,c);
+ result
+ );
+
+ - make (a,b,c:E) <-
+ (
+ x := a;
+ y := b;
+ z := c;
+ );
+
+ - copy :SELF <-
+ (
+ create (x,y,z)
+ );
+
+ - zero:SELF <- create (E.zero,E.zero,E.zero);
+
+ - set_x v:E <-
+ (
+ x := v;
+ );
+ - set_y v:E <-
+ (
+ y := v;
+ );
+ - set_z v:E <-
+ (
+ z := v;
+ );
+
+ - get :(E,E,E) <-
+ (
+ x, y, z
+ );
+
+ - getv:FAST_ARRAY[E] <-
+ (
+ + result:FAST_ARRAY[E];
+
+ result := FAST_ARRAY[E].create 3;
+ result.put x to 0;
+ result.put y to 1;
+ result.put z to 2;
+ result
+ );
+
+ - '-' :SELF <-
+ (
+ create (-x, -y, -z)
+ );
+
+ - '+' Left 80 other:SELF :SELF <-
+ (
+ create (x + other.x, y + other.y, z + other.z)
+ );
+
+ - '-' Left 80 other:SELF :SELF <-
+ (
+ create (x - other.x, y - other.y, z - other.z)
+ );
+
+ - '*' Left 100 scalar:E :SELF <-
+ (
+ create (scalar * x, scalar * y, scalar * z)
+ );
+
+ - '/' Left 100 scalar:E :SELF <-
+ (
+ ? {scalar != 0};
+ create (x / scalar, y / scalar, z / scalar)
+ );
+
+ - magnitude:E <-
+ // magnitude = sqrt(V.x^2 + V.y^2 + V.z^2)
+ (
+ (x*x + y*y + z*z).sqrt
+ );
+
+ - normalize <-
+ // normalize self vector (of length 1)
+ ( + m:E;
+
+ m := magnitude;
+ make (x/m, y/m, z/m);
+ );
+
+ - normalized :SELF <-
+ // return a normalized vector (of length 1) from self
+ (
+ Self / magnitude
+ );
+
+ - dot other:SELF :E <-
+ (
+ x*other.x + y*other.y + z*other.z
+ );
+
+ - cross other:SELF :SELF <-
+ // calculate the cross product
+ (
+ + nx,ny,nz:E;
+
+ nx := (y * other.z) - (z * other.y);
+ ny := (z * other.x) - (x * other.z);
+ nz := (x * other.y) - (y * other.x);
+
+ create (nx,ny,nz)
+ );
+
+
+ - print <-
+ (
+ "(".print; x.print;", ".print; y.print; ", ".print;
+ z.print; ")".print;
);
\ No newline at end of file
diff --git a/vector4.li b/vector4.li
index 6de5c90..97bb439 100644
--- a/vector4.li
+++ b/vector4.li
@@ -1,145 +1,145 @@
-///////////////////////////////////////////////////////////////////////////////
-// Math-Library //
-// //
-// LSIIT - ULP - CNRS - INRIA - FRANCE //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation, either version 3 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details. //
-// //
-// You should have received a copy of the GNU General Public License //
-// along with this program. If not, see <http://www.gnu.org/licenses/>. //
-// //
-// http://isaacproject.u-strasbg.fr/ //
-///////////////////////////////////////////////////////////////////////////////
-
-Section Header
-
- + name := VECTOR4[E];
-
- - comment := "(x,y,z,w) vector";
-
-Section Inherit
-
- - parent_object:OBJECT := OBJECT;
-
-Section Public
-
- + x:E;
- + y:E;
- + z:E;
- + w:E;
-
- - create (a,b,c,d:E) :SELF <-
- ( + result:SELF;
- result := SELF.clone;
- result.make (a,b,c,d);
- result
- );
-
- - make (a,b,c,d:E) <-
- (
- x := a;
- y := b;
- z := c;
- w := d;
- );
-
- - copy :SELF <-
- (
- create (x,y,z,w)
- );
-
- - zero:SELF <- create (E.zero,E.zero,E.zero,E.zero);
-
- - set_x v:E <-
- (
- x := v;
- );
- - set_y v:E <-
- (
- y := v;
- );
- - set_z v:E <-
- (
- z := v;
- );
- - set_w v:E <-
- (
- w := v;
- );
- - get :(E,E,E,E) <-
- (
- x, y, z, w
- );
-
- - getv:FAST_ARRAY[E] <-
- (
- + result:FAST_ARRAY[E];
-
- result := FAST_ARRAY[E].create 4;
- result.put x to 0;
- result.put y to 1;
- result.put z to 2;
- result.put w to 3;
- result
- );
-
- - '-' :SELF <-
- (
- create (-x, -y, -z, -w)
- );
-
- - '+' Left 80 other:SELF :SELF <-
- (
- create (x + other.x, y + other.y, z + other.z, w + other.w)
- );
-
- - '-' Left 80 other:SELF :SELF <-
- (
- create (x - other.x, y - other.y, z - other.z, w - other.w)
- );
-
- - '*' Left 100 scalar:E :SELF <-
- (
- create (scalar * x, scalar * y, scalar * z, scalar * w)
- );
-
- - '/' Left 100 scalar:E :SELF <-
- (
- ? {scalar != 0};
- create (x / scalar, y / scalar, z / scalar, w / scalar)
- );
-
- - magnitude:E <-
- // magnitude = sqrt(x^2 + y^2 + z^2 + w^2)
- (
- (x*x + y*y + z*z + w*w).sqrt
- );
-
- - normalize <-
- // normalize self vector (of length 1)
- ( + m:E;
-
- m := magnitude;
- make (x/m, y/m, z/m, w/m);
- );
-
- - normalized :SELF <-
- // return a normalized vector (of length 1) from self
- (
- Self / magnitude
- );
-
-
- - print <-
- (
- "(".print; x.print;", ".print; y.print; ", ".print;
- z.print; ", ".print; w.print; ")".print;
+///////////////////////////////////////////////////////////////////////////////
+// Math-Library //
+// //
+// LSIIT - ULP - CNRS - INRIA - FRANCE //
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see <http://www.gnu.org/licenses/>. //
+// //
+// http://isaacproject.u-strasbg.fr/ //
+///////////////////////////////////////////////////////////////////////////////
+
+Section Header
+
+ + name := VECTOR4[E];
+
+ - comment := "(x,y,z,w) vector";
+
+Section Inherit
+
+ - parent_object:OBJECT := OBJECT;
+
+Section Public
+
+ + x:E;
+ + y:E;
+ + z:E;
+ + w:E;
+
+ - create (a,b,c,d:E) :SELF <-
+ ( + result:SELF;
+ result := SELF.clone;
+ result.make (a,b,c,d);
+ result
+ );
+
+ - make (a,b,c,d:E) <-
+ (
+ x := a;
+ y := b;
+ z := c;
+ w := d;
+ );
+
+ - copy :SELF <-
+ (
+ create (x,y,z,w)
+ );
+
+ - zero:SELF <- create (E.zero,E.zero,E.zero,E.zero);
+
+ - set_x v:E <-
+ (
+ x := v;
+ );
+ - set_y v:E <-
+ (
+ y := v;
+ );
+ - set_z v:E <-
+ (
+ z := v;
+ );
+ - set_w v:E <-
+ (
+ w := v;
+ );
+ - get :(E,E,E,E) <-
+ (
+ x, y, z, w
+ );
+
+ - getv:FAST_ARRAY[E] <-
+ (
+ + result:FAST_ARRAY[E];
+
+ result := FAST_ARRAY[E].create 4;
+ result.put x to 0;
+ result.put y to 1;
+ result.put z to 2;
+ result.put w to 3;
+ result
+ );
+
+ - '-' :SELF <-
+ (
+ create (-x, -y, -z, -w)
+ );
+
+ - '+' Left 80 other:SELF :SELF <-
+ (
+ create (x + other.x, y + other.y, z + other.z, w + other.w)
+ );
+
+ - '-' Left 80 other:SELF :SELF <-
+ (
+ create (x - other.x, y - other.y, z - other.z, w - other.w)
+ );
+
+ - '*' Left 100 scalar:E :SELF <-
+ (
+ create (scalar * x, scalar * y, scalar * z, scalar * w)
+ );
+
+ - '/' Left 100 scalar:E :SELF <-
+ (
+ ? {scalar != 0};
+ create (x / scalar, y / scalar, z / scalar, w / scalar)
+ );
+
+ - magnitude:E <-
+ // magnitude = sqrt(x^2 + y^2 + z^2 + w^2)
+ (
+ (x*x + y*y + z*z + w*w).sqrt
+ );
+
+ - normalize <-
+ // normalize self vector (of length 1)
+ ( + m:E;
+
+ m := magnitude;
+ make (x/m, y/m, z/m, w/m);
+ );
+
+ - normalized :SELF <-
+ // return a normalized vector (of length 1) from self
+ (
+ Self / magnitude
+ );
+
+
+ - print <-
+ (
+ "(".print; x.print;", ".print; y.print; ", ".print;
+ z.print; ", ".print; w.print; ")".print;
);
\ No newline at end of file
--
Lisaac library math
More information about the Lisaac-commits
mailing list