From: toshinagata1964 Date: Thu, 3 May 2012 10:22:50 +0000 (+0000) Subject: Vector3D[] and Transform[] are modified to accept an LAMatrix argument. The document... X-Git-Tag: v1.0.2~443 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=378a10f3818124d113b7354cc63170e5ad4ebd2d;p=molby%2FMolby.git Vector3D[] and Transform[] are modified to accept an LAMatrix argument. The document is written for LAMatrix. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@192 a2be9bc6-48de-4e38-9406-05402d4bc13c --- diff --git a/Documents/src/doc_source.html b/Documents/src/doc_source.html index 632be81..485f0d2 100644 --- a/Documents/src/doc_source.html +++ b/Documents/src/doc_source.html @@ -1714,6 +1714,7 @@ It is recommended for you to read the document of the most important class Dialog
  • DialogItem
  • IntGroup
  • +
  • LAMatrix
  • MDArena
  • MolEnumerable
  • Molecule
  • @@ -1750,6 +1751,7 @@ It is recommended for you to read the document of the most important class Dialog
  • DialogItem
  • IntGroup
  • +
  • LAMatrix
  • MDArena
  • MolEnumerable
  • Molecule
  • diff --git a/Documents/src/molby_rb/Molecule.html b/Documents/src/molby_rb/Molecule.html index 461e557..e7db749 100644 --- a/Documents/src/molby_rb/Molecule.html +++ b/Documents/src/molby_rb/Molecule.html @@ -812,8 +812,15 @@ Same as Molecule#insert_frames(nil, coordina

    -Create a new graphic object. Kind: a symbol representing the kind of the graphic. :line, :poly, :cylinder, :cone, :ellipsoid. Color: an array of 3 (rgb) or 4 (rgba) floating numbers. Points: an array of Vector3Ds. -

    +Create a new graphic object. Kind: a symbol representing the kind of the graphic. :line, :poly, :cylinder, :cone, :ellipsoid. Color: an array of 3 (rgb) or 4 (rgba) floating numbers. Points: an array of Vector3Ds or Floats (depending on the graphic type). The arguments points = [p1, p2, ..., pn] and fill have the following meanings for each kind of the graphic. +

    +

    Returns the index of the newly created graphic.

    diff --git a/Documents/src/molby_rb/Transform.html b/Documents/src/molby_rb/Transform.html index be01443..d212fa1 100644 --- a/Documents/src/molby_rb/Transform.html +++ b/Documents/src/molby_rb/Transform.html @@ -144,7 +144,7 @@ In the second form, the array must be either of the following two forms: a31 a12 a22 a32 a13 a23 a33 a14 a24 a34] where [a11..a33] denotes the rotation/reflexion part and [a14 a24 a34] denotes the translation part. All vectors in (1) are column vectors.

    -In the third form, a new transform is built from a 3x4 matrix. The argument matrix must respond to a method call matrix[col, row] where row is in 0..2 and col in 0..3. +In the third form, a new transform is built from a 3x4 matrix. The argument matrix must respond to a method call matrix[col, row] where row is in 0..2 and col in 0..3, and must have methods column_size and row_size (although the size arguments are not evaluated but only their existence is checked).

    @@ -471,4 +471,4 @@ the original. - \ No newline at end of file + diff --git a/Documents/src/molby_rb/Vector3D.html b/Documents/src/molby_rb/Vector3D.html index 0d4a8f8..892fdf1 100644 --- a/Documents/src/molby_rb/Vector3D.html +++ b/Documents/src/molby_rb/Vector3D.html @@ -44,12 +44,13 @@ The class Vector3D represents a three-dimensional ve
    +Vector3d[vx] → (new) Vector3D
    Vector3d[fx, fy, fz] → (new) Vector3D

    -Create a new vector3d object. Equivalent to Vector3D#new([fx, fy, fz]). +Create a new vector3d object. The first form is equivalent to Vector3D#new(vx), and the second form is equivalent to Vector3D#new([fx, fy, fz]).

    @@ -58,13 +59,14 @@ Create a new vector3d object. Equivalent to Vector3D#new(
    new → (new) Vector3D
    -new(Vector3D) → (new) Vector3D
    +new(Vector3D) → (new) Vector3D
    +new(LAMatrix) → (new) Vector3D
    new([fx, fy, fz]) → (new) Vector3D

    -Returns a new Vector3D object. In the first form, a zero vector is returned. In the second form, the given vector3d is duplicated. In the third form, a vector [fx, fy, fz] is returned. +Returns a new Vector3D object. In the first form, a zero vector is returned. In the second form, the given vector3d is duplicated. In the third form, a row vector or a column vector (with dimension 3 or larger) is converted to a vector3d. In the fourth form, a vector [fx, fy, fz] is returned.

    @@ -422,4 +424,4 @@ Set the z element of the vector. - \ No newline at end of file + diff --git a/MolLib/Ruby_bind/ruby_types.c b/MolLib/Ruby_bind/ruby_types.c index ee39bc7..0bd4063 100644 --- a/MolLib/Ruby_bind/ruby_types.c +++ b/MolLib/Ruby_bind/ruby_types.c @@ -66,6 +66,10 @@ VectorFromValue(VALUE val, Vector *vp) vp->y = mp->data[1]; vp->z = mp->data[2]; } + } else if (rb_obj_is_kind_of(val, rb_cNumeric)) { + /* Vector3D[1] is rejected; this is desirable because Integer implements + the index method ([]), which could cause confusion. */ + rb_raise(rb_eMolbyError, "single number cannot be converted to a Vector3D"); } else { static ID mname = 0; if (mname == 0) @@ -498,15 +502,19 @@ s_Vector3D_SetZ(VALUE self, VALUE val) /* * call-seq: + * Vector3d[vx] -> (new) Vector3D. * Vector3d[fx, fy, fz] -> (new) Vector3D * - * Create a new vector3d object. Equivalent to Vector3D#new([fx, fy, fz]). + * Create a new vector3d object. The first form is equivalent to Vector3D#new(vx), and + * the second form is equivalent to Vector3D#new([fx, fy, fz]). */ static VALUE s_Vector3D_Create(VALUE klass, VALUE args) { VALUE val = s_Vector3D_Alloc(klass); - s_Vector3D_Initialize(1, &args, val); + if (RARRAY_LEN(args) == 1) + s_Vector3D_Initialize(RARRAY_LEN(args), RARRAY_PTR(args), val); + else s_Vector3D_Initialize(1, &args, val); return val; } @@ -563,6 +571,10 @@ TransformFromValue(VALUE val, Transform *tp) } array_format_error: rb_raise(rb_eMolbyError, "wrong array format; must be an array of either (1) four 3D column vectors or (2) 12 numerics"); + } else if (rb_obj_is_kind_of(val, rb_cNumeric)) { + /* Transform[1] is rejected; this is desirable because Integer implements + the index method ([]), which could cause confusion. */ + rb_raise(rb_eMolbyError, "single number cannot be converted to a Transform"); } else { static ID index_mid = 0, row_size_mid, column_size_mid; if (index_mid == 0) { @@ -1065,12 +1077,17 @@ s_Transform_Eigenvalues(VALUE self) * Transform[*args] -> (new) Transform * * Create a new transform. Equivalent to Transform.new(args). + * If only one argument is given that is not a number, then Transform.new(args[0]) + * is called instead of Transform.new(args). */ static VALUE s_Transform_Create(VALUE klass, VALUE args) { VALUE val = s_Transform_Alloc(klass); - s_Transform_Initialize(1, &args, val); + if (RARRAY_LEN(args) == 1 && !rb_obj_is_kind_of(RARRAY_PTR(args)[0], rb_cNumeric)) + s_Transform_Initialize(RARRAY_LEN(args), RARRAY_PTR(args), val); + else + s_Transform_Initialize(1, &args, val); return val; } @@ -2176,6 +2193,34 @@ s_LAMatrix_Row(VALUE self, VALUE val) /* * call-seq: + * column_size -> LAMatrix + * + * Returns the column size. + */ +static VALUE +s_LAMatrix_ColumnSize(VALUE self) +{ + LAMatrix *mp; + Data_Get_Struct(self, LAMatrix, mp); + return INT2NUM(mp->column); +} + +/* + * call-seq: + * row_size -> LAMatrix + * + * Returns the row size. + */ +static VALUE +s_LAMatrix_RowSize(VALUE self) +{ + LAMatrix *mp; + Data_Get_Struct(self, LAMatrix, mp); + return INT2NUM(mp->row); +} + +/* + * call-seq: * eigenvalues -> [eigenvalues, eigenvectors] * * Calculate the eigenvalues and eigenvectors. The matrix must be symmetric. @@ -2851,6 +2896,8 @@ Init_MolbyTypes(void) rb_define_method(rb_cLAMatrix, "submatrix", s_LAMatrix_Submatrix, 4); rb_define_method(rb_cLAMatrix, "column", s_LAMatrix_Column, 1); rb_define_method(rb_cLAMatrix, "row", s_LAMatrix_Row, 1); + rb_define_method(rb_cLAMatrix, "column_size", s_LAMatrix_ColumnSize, 0); + rb_define_method(rb_cLAMatrix, "row_size", s_LAMatrix_RowSize, 0); rb_define_method(rb_cLAMatrix, "eigenvalues", s_LAMatrix_Eigenvalues, 0); rb_define_method(rb_cLAMatrix, "to_a", s_LAMatrix_ToArray, 0); rb_define_method(rb_cLAMatrix, "inspect", s_LAMatrix_Inspect, 0);