[Vala] [Fwd: Re: 2D Static Array]
- From: JM <interflug1 gmx net>
- To: vala-list <vala-list gnome org>
- Subject: [Vala] [Fwd: Re: 2D Static Array]
- Date: Tue, 20 Apr 2010 14:55:45 +0200
Forgot to include the mailinglist
-------- Weitergeleitete Nachricht --------
Von: JM <interflug1 gmx net>
An: michele cremasco <michele cremasco gmail com>
Betreff: Re: [Vala] 2D Static Array
Datum: Tue, 20 Apr 2010 14:02:30 +0200
Hello
Try it this way. In vala array is part of the type
public class Matrix
{
public Matrix(double[,] x){
mat = x;
}
public double[,] mat;
}
public static int main() {
var y = new Matrix({{ 2.0, 3.0, 4.0, 5.0},
{ 2.0, 3.0, 4.0, 6.0},
{ 2.0, 3.0, 4.0, 7.0},
{ 2.0, 3.0, 4.0, 8.0}});
print("get element: %lf\n", y.mat[2,3]);
return 0;
}
Regards
Jörn
Am Dienstag, den 20.04.2010, 12:03 +0200 schrieb michele cremasco:
typedef struct _Matrix Matrix;
struct _Matrix
{
float mat[4][4];
}
Converting in vala, it becomes:
[Compact]
public class Matrix
{
public float mat[4,4];
}
But compiler doesn't support multi dimensional embedded array!!
If I write in the following way it embeds correctly the mono
dimensional
array:
Compact]
public class Matrix
{
public float mat[16];
}
But it is not what I whant.
Eventually I can add inline getteres and setters:
[Compact]
public class Matrix
{
public float mat[16];
public inline float get(int row, int col)
{
return mat[row*4 + col];
}
public inline void set(int row, int col, float val)
{
mat[row*4 + col] = val;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]