OSDN Git Service

Vector3D[] and Transform[] are modified to accept an LAMatrix argument. The document...
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Thu, 3 May 2012 10:22:50 +0000 (10:22 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Thu, 3 May 2012 10:22:50 +0000 (10:22 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@192 a2be9bc6-48de-4e38-9406-05402d4bc13c

Documents/src/doc_source.html
Documents/src/molby_rb/Molecule.html
Documents/src/molby_rb/Transform.html
Documents/src/molby_rb/Vector3D.html
MolLib/Ruby_bind/ruby_types.c

index 632be81..485f0d2 100644 (file)
@@ -1714,6 +1714,7 @@ It is recommended for you to read the document of the most important class <a hr
 <li><a href="molby_rb/Dialog.html">Dialog</a></li>
 <li><a href="molby_rb/DialogItem.html">DialogItem</a></li>
 <li><a href="molby_rb/IntGroup.html">IntGroup</a></li>
+<li><a href="molby_rb/LAMatrix.html">LAMatrix</a></li>
 <li><a href="molby_rb/MDArena.html">MDArena</a></li>
 <li><a href="molby_rb/MolEnumerable.html">MolEnumerable</a></li>
 <li><a href="molby_rb/Molecule.html">Molecule</a></li>
@@ -1750,6 +1751,7 @@ It is recommended for you to read the document of the most important class <a hr
 <li><a href="molby_rb/Dialog.html">Dialog</a></li>
 <li><a href="molby_rb/DialogItem.html">DialogItem</a></li>
 <li><a href="molby_rb/IntGroup.html">IntGroup</a></li>
+<li><a href="molby_rb/LAMatrix.html">LAMatrix</a></li>
 <li><a href="molby_rb/MDArena.html">MDArena</a></li>
 <li><a href="molby_rb/MolEnumerable.html">MolEnumerable</a></li>
 <li><a href="molby_rb/Molecule.html">Molecule</a></li>
index 461e557..e7db749 100644 (file)
@@ -812,8 +812,15 @@ Same as <a href="Molecule.html#M000336">Molecule#insert_frames</a>(nil, coordina
 </div>
 <div class="method-description">
 <p>
-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 <a href="Vector3D.html">Vector3D</a>s.
-</p>
+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 <a href="Vector3D.html">Vector3D</a>s 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.
+</p>
+<ul>
+<li><b>line</b>: Points correspond to a set of lines (p1, p2), (p2, p3), ..., (p(n-1), pn). Fill has no meaning.</li>
+<li><b>poly</b>: Points correspond to a set of connected triangles (p1, p2, p3), (p1, p3, p4), ..., (p1, p(n-1), pn). Fill has no meaning.</li>
+<li><b>cylinder</b>: p1 = center of the bottom face, p2 = center of the top face, p3 (number) = radius. If fill is true, both faces are drawn. Otherwise, only the side surface is drawn.</li>
+<li><b>cone</b>: p1 = center of the bottom face, p2 = top point, p3 (number) = radius. If fill is true, the bottom face is drawn. Otherwise, only the side surface is drawn.</li>
+<li><b>ellipsoid</b>: Two argument types. (1) p1 = center, p2 (number) = radius. (2) p1 = center, p2, p3, p4 = main axis of the ellipsoid (not necessarily orthogonal each other). Fill has no meaning.</li>
+</ul>
 <p>
 Returns the index of the newly created graphic.
 </p>
index be01443..d212fa1 100644 (file)
@@ -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.
 </p>
 <p>
-In the third form, a new transform is built from a 3x4 matrix. The argument <tt>matrix</tt> must respond to a method call <tt>matrix[col, row]</tt> where <tt>row</tt> is in <tt>0..2</tt> and <tt>col</tt> in <tt>0..3</tt>.
+In the third form, a new transform is built from a 3x4 matrix. The argument <tt>matrix</tt> must respond to a method call <tt>matrix[col, row]</tt> where <tt>row</tt> is in <tt>0..2</tt> and <tt>col</tt> in <tt>0..3</tt>, and must have methods <tt>column_size</tt> and <tt>row_size</tt> (although the size arguments are not evaluated but only their existence is checked).
 </p>
 </div>
 </div>
@@ -471,4 +471,4 @@ the original.
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
index 0d4a8f8..892fdf1 100644 (file)
@@ -44,12 +44,13 @@ The class <a href="Vector3D.html">Vector3D</a> represents a three-dimensional ve
 <div id="method-M000371" class="method-detail">
 <a name="M000371"></a>
 <div class="method-heading">
+<span class="method-name">Vector3d[vx]   &rarr; (new) Vector3D<br />
 <span class="method-name">Vector3d[fx, fy, fz]   &rarr; (new) Vector3D<br />
 </span>
 </div>
 <div class="method-description">
 <p>
-Create a new vector3d object. Equivalent to <a href="#M000347">Vector3D#new</a>([fx, fy, fz]).
+Create a new vector3d object. The first form is equivalent to <a href="#M000347">Vector3D#new</a>(vx), and the second form is equivalent to <a href="#M000347">Vector3D#new</a>([fx, fy, fz]).
 </p>
 </div>
 </div>
@@ -58,13 +59,14 @@ Create a new vector3d object. Equivalent to <a href="#M000347">Vector3D#new</a>(
 <a name="M000347"></a>
 <div class="method-heading">
 <span class="method-name">new &rarr; (new) Vector3D<br />
-new(Vector3D) &rarr; (new) Vector3D<br />
+new(<a href="Vector3D.html">Vector3D</a>) &rarr; (new) Vector3D<br />
+new(<a href="LAMatrix.html">LAMatrix</a>) &rarr; (new) Vector3D<br />
 new([fx, fy, fz]) &rarr; (new) Vector3D<br />
 </span>
 </div>
 <div class="method-description">
 <p>
-Returns a new <a href="Vector3D.html">Vector3D</a> 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 <a href="Vector3D.html">Vector3D</a> 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.
 </p>
 </div>
 </div>
@@ -422,4 +424,4 @@ Set the z element of the vector.
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
index ee39bc7..0bd4063 100644 (file)
@@ -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);