コード例 #1
0
 /// <summary>
 /// Gets orientation masks of grouped orientations. Resulting array always
 /// includes mask of this orientation.
 /// </summary>
 /// <example>
 /// <para>Retrieve array of orientation masks:</para>
 /// <code language="csharp"><![CDATA[
 /// // Add all four corner orientations using rotational symmetry.
 /// int cornerMask = OrientationUtility.MaskFromName("11010000");
 /// var orientation = orientedBrush.AddOrientation(cornerMask, true);
 ///
 /// // Get list of grouped orientation masks:
 /// int[] groupedMasks = orientation.GetGroupedOrientationMasks();
 ///
 /// // Resulting Array:
 /// // [0] = 11010000
 /// // [1] = 01101000
 /// // [2] = 00010110
 /// // [3] = 00001011
 /// ]]></code>
 ///
 /// <para>This also works for orientations which have not been grouped by
 /// rotational symmetry:</para>
 /// <code language="csharp"><![CDATA[
 /// // Add one corner orientation.
 /// int cornerMask = OrientationUtility.MaskFromName("11010000");
 /// var orientation = orientedBrush.AddOrientation(cornerMask);
 ///
 /// // Get list of grouped orientation masks:
 /// int[] groupedMasks = orientation.GetGroupedOrientationMasks();
 ///
 /// // Resulting Array:
 /// // [0] = 11010000
 /// ]]></code>
 /// </example>
 /// <returns>
 /// An array of orientation bitmasks.
 /// </returns>
 public int[] GetGroupedOrientationMasks()
 {
     return(this.HasRotationalSymmetry
         ? OrientationUtility.GetMasksWithRotationalSymmetry(this.mask)
         : new int[] { this.mask }
            );
 }
コード例 #2
0
        /// <summary>
        /// Adds orientation to brush optionally with rotational symmetry.
        /// </summary>
        /// <param name="mask">Bit mask describing orientation.</param>
        /// <param name="rotationalSymmetry">Indicates whether additional orientations should
        /// be added which have rotational symmetry.</param>
        /// <returns>
        /// First <see cref="BrushOrientation"/> in group with rotational symmetry.
        /// </returns>
        /// <exception cref="System.Exception">
        /// If orientation already exists.
        /// </exception>
        /// <seealso cref="BrushOrientation.AddVariation(Object)">BrushOrientation.AddVariation(Object)</seealso>
        public BrushOrientation AddOrientation(int mask, bool rotationalSymmetry)
        {
            int[] masks = rotationalSymmetry
                ? OrientationUtility.GetMasksWithRotationalSymmetry(mask)
                : new int[] { mask }
            ;

            // Obviously, there is no rotational symmetry if there is only 1!
            if (masks.Length == 1)
            {
                rotationalSymmetry = false;
            }

            // First, make sure that orientations do not alreay exist.
            for (int i = 0; i < masks.Length; ++i)
            {
                if (this.FindOrientation(mask) != null)
                {
                    throw new Exception("Orientation already exists.");
                }
            }

            var newOrientations = new List <BrushOrientation>();

            // Add orientation(s).
            for (int i = 0; i < masks.Length; ++i)
            {
                var orientation = new BrushOrientation(masks[i]);
                orientation.type     = rotationalSymmetry;
                orientation.rotation = i;

                newOrientations.Add(orientation);

                // Upgrade default orientation reference?
                // Note: This is necessary when brush is first created.
                if (masks[i] == this.defaultOrientationMask)
                {
                    this.defaultOrientation = newOrientations[0];
                }
            }

            // Add the new orientation(s).
            int newIndex = this.orientations.Length;

            Array.Resize(ref this.orientations, this.orientations.Length + newOrientations.Count);
            for (int i = 0; i < newOrientations.Count; ++i)
            {
                this.orientations[newIndex + i] = newOrientations[i];
            }

            // Sort orientations by mask.
            this.SortOrientationsByRotationalSymmetry();

            this.RefreshOrientationLookupTable();

            return(newOrientations[0]);
        }