Beispiel #1
0
 /// <summary>
 /// 创建一个新实例。
 /// 这种创建方式会将 <paramref name="derivation"/> 的 <see cref="IDerivation.Derive(CorePainting)"/> 作为变换函数。
 /// Initialize a new instance.
 /// This will use <paramref name="derivation"/>'s <see cref="IDerivation.Derive(CorePainting)"/> as the derivation function.
 /// </summary>
 /// <param name="derivation">
 /// 在变换时使用的变换过程。
 /// The derivation to be used when deriving.
 /// </param>
 public FunctionDerivation(IDerivation derivation)
 {
     if (derivation is null)
     {
         throw new ArgumentNullException(nameof(derivation));
     }
     this.function = derivation.Derive;
 }
Beispiel #2
0
 /// <summary>
 /// 创建一个新实例。
 /// Initialize a new instance.
 /// </summary>
 /// <param name="function">
 /// 在变换时使用的函数。
 /// The function to be used when deriving.
 /// </param>
 public FunctionDerivation(DerivationFunc function)
 {
     if (function is null)
     {
         throw new ArgumentNullException(nameof(function));
     }
     this.function = function;
 }
Beispiel #3
0
        /// <summary>
        /// 应用指定变换函数。
        /// Apply the given derivation function.
        /// </summary>
        /// <param name="from">
        /// 要变换的卦画。
        /// The painting to derive from.
        /// </param>
        /// <param name="derivationFunction">
        /// 变换函数。
        /// The derivation function.
        /// </param>
        /// <returns>
        /// 变换结果。
        /// The derived painting.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="from"/> 或 <paramref name="derivationFunction"/> 是 <c>null</c>.
        /// <paramref name="from"/> or <paramref name="derivationFunction"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="PaintingDerivationException">
        /// 变换失败。这通常表示此变换过程不适用于指定的卦画。
        /// Derivation failed. This often means that the derivation doesn't fit the given painting.
        /// </exception>
        public static Core.Painting ApplyDerivation(
            this Core.Painting from, DerivationFunc derivationFunction)
        {
            if (from is null)
            {
                throw new ArgumentNullException(nameof(from));
            }
            if (derivationFunction is null)
            {
                throw new ArgumentNullException(nameof(derivationFunction));
            }
            var derivation = new FunctionDerivation(derivationFunction);

            return(derivation.Derive(from));
        }
Beispiel #4
0
        /// <summary>
        /// 判断一个卦画是否由另一个卦画,通过指定的方式变换而来。
        /// Judge whether the object painting is derived from the basis painting,
        /// through the given derivation function.
        /// </summary>
        /// <param name="obj">
        /// 要判断的目标卦画。
        /// The object painting to judge.
        /// </param>
        /// <param name="basis">
        /// 作为判断基础的卦画。
        /// The paintings to be used as the comparing basis.
        /// </param>
        /// <param name="derivationFunction">
        /// 变换过程函数。
        /// The derivation function.
        /// </param>
        /// <returns>
        /// 判断结果。
        /// The result.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="basis"/> 或 <paramref name="derivationFunction"/> 或 <paramref name="obj"/> 是 <c>null</c> 。
        /// <paramref name="basis"/> or <paramref name="derivationFunction"/> or <paramref name="obj"/> is <c>null</c>.
        /// </exception>
        public static bool IsDerivedFrom(
            this Core.Painting obj, Core.Painting basis, DerivationFunc derivationFunction)
        {
            if (obj is null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            if (basis is null)
            {
                throw new ArgumentNullException(nameof(basis));
            }
            if (derivationFunction is null)
            {
                throw new ArgumentNullException(nameof(derivationFunction));
            }
            var functionComparer = new FunctionComparer(derivationFunction);

            return(functionComparer.Compare(basis, obj));
        }