Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new <c>JointValues</c> instance that contains only values for joints of the given <c>JointSet</c>.
 /// The <paramref name="subset"/> parameter defines the new order of the joints in the resulting <c>JointValues</c> object.
 /// </summary>
 /// <param name="subset">A <c>JointSet</c> with a subset of the joints.</param>
 /// <returns>A new instance of <c>JointValues</c>.</returns>
 /// <exception cref="ArgumentException">Thrown when the given <paramref name="subset"/> is not a subset of the names the <c>JointSet</c>.</exception>
 public JointValues Select(JointSet subset)
 {
     if (!subset.IsSubset(this.JointSet))
     {
         throw new ArgumentException("The given joint set needs to be a subset of the current joint set.", nameof(subset));
     }
     return(new JointValues(subset, subset.Select(x => this[x])));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the joint values of the given joint set. Values which are not in the given joint set are not changed.
        /// </summary>
        /// <param name="jointSet">The set of joints whose values should be changed.</param>
        /// <param name="values">The new values for the given joint set.</param>
        /// <returns>A new instance of <c>JointValues</c>.</returns>
        /// <exception cref="ArgumentException">Thrown when the given <paramref name="jointSet"/> is not a subset of the names the <c>JointSet</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when the number of elements in the <paramref name="values"/> list does not match the number of joints in the <paramref name="jointSet"/> argument.</exception>
        public JointValues SetValues(JointSet jointSet, IReadOnlyList <double> values)
        {
            if (!jointSet.IsSubset(this.JointSet))
            {
                throw new ArgumentException("The given joint set needs to be a subset of the current joint set.", nameof(jointSet));
            }

            if (jointSet.Count != values.Count)
            {
                throw new ArgumentException("Number of elements in values list does not match number of joints in joint set.", nameof(values));
            }

            double[] newValues = this.ToArray();
            for (var i = 0; i < values.Count; i++)
            {
                string jointName = jointSet[i];
                int    index     = this.JointSet.GetIndexOf(jointName);
                newValues[index] = values[i];
            }

            return(new JointValues(this.JointSet, newValues));
        }