Пример #1
0
        public IDiff <TType> Compute(TType @base, TType changed)
        {
            if (this.aIsTheSame == null)
            {
                this.aIsTheSame    = IdHelpers.CompileIsTheSame <TItemType>(this.aIDProperty);
                this.aItemDiff     = this.aMergerImplementation.Partial.Algorithms.GetDiffAlgorithm <TItemType>();
                this.aItemComparer = EqualityComparer <TItemType> .Default;
            }

            return(this.ComputeInternal((IEnumerable <TItemType>)@base, (IEnumerable <TItemType>)changed));
        }
Пример #2
0
        public void SetUp()
        {
            _testClass = new ClusterByDistance();

            diff = new DefaultDiffAlgorithm <ArgbPixelDelta, MedianPreprocessor>();

            leftImg1  = Image.FromFile(Path.Combine("Samples", "Sample_1_A.jpg")) as Bitmap;
            rightImg1 = Image.FromFile(Path.Combine("Samples", "Sample_1_B.jpg")) as Bitmap;

            leftImg3  = Image.FromFile(Path.Combine("Samples", "Sample_3_A.jpg")) as Bitmap;
            rightImg3 = Image.FromFile(Path.Combine("Samples", "Sample_3_B.jpg")) as Bitmap;
        }
Пример #3
0
        private Expression <Func <TType, TType, List <IDiffItem> > > Compile()
        {
            List <Expression>   body    = new List <Expression>();
            ParameterExpression ret     = Expression.Parameter(typeof(List <IDiffItem>), "ret");
            ParameterExpression @base   = Expression.Parameter(typeof(TType), "base");
            ParameterExpression changed = Expression.Parameter(typeof(TType), "changed");

            body.Add(
                Expression.Assign(
                    ret,
                    Expression.New(
                        ListMembers.NewWithCount(typeof(IDiffItem)),
                        Expression.Constant(Class <TType> .Properties.Count)                       // maximum number of different items
                        )
                    )
                );

            foreach (Property property in Class <TType> .Properties)
            {
                if (this.aIgnoreProperties.Contains(property))
                {
                    continue;
                }

                IDiffAlgorithm diff = this.aMergerImplementation.Partial.Algorithms.GetDiffAlgorithm(property.Type);

                if (diff.IsDirect)
                {
                    body.Add(this.MightBeReplaced(ret, property, @base, changed));
                }
                else
                {
                    body.Add(this.MightBeChanged(ret, property, @base, changed));
                }
            }

            body.Add(ret);

            return(Expression.Lambda <Func <TType, TType, List <IDiffItem> > >(
                       Expression.Block(new[] { ret }, body),
                       @base, changed
                       ));
        }
Пример #4
0
        private Expression NewDiffChanged(ParameterExpression ret, Property property, ParameterExpression @base, ParameterExpression changed)
        {
            IDiffAlgorithm diff = this.aMergerImplementation.Partial.Algorithms.GetDiffAlgorithm(property.Type);

            if (diff.IsDirect)
            {
                return(this.NewDiffReplaced(ret, property, @base, changed));
            }

            MemberExpression baseProperty    = Expression.Property(@base, property.ReflectionPropertyInfo);
            MemberExpression changedProperty = Expression.Property(changed, property.ReflectionPropertyInfo);

            ParameterExpression tmp = Expression.Parameter(typeof(IDiff <>).MakeGenericType(property.Type), "tmp");

            return(Expression.Block(
                       new[] { tmp },
                       Expression.Assign(
                           tmp,
                           Expression.Call(
                               Expression.Constant(diff),
                               DiffAlgorithmMembers.Compute(property.Type),
                               baseProperty,
                               changedProperty
                               )
                           ),
                       Expression.IfThenElse(
                           Expression.NotEqual(
                               Expression.Property(tmp, DiffMembers.Count()),
                               Expression.Constant(0)
                               ),
                           Expression.Call(
                               ret,
                               ListMembers.Add(typeof(IDiffItem)),
                               Expression.New(
                                   DiffItemsMembers.NewClassChanged(property.Type),
                                   Expression.Constant(property),
                                   tmp
                                   )
                               ),
                           this.NewDiffUnchanged(ret, property, @base)
                           )
                       ));
        }
Пример #5
0
        private ImgDiffCalculator(ImgDiffOptions options)
        {
            _leftPath  = options.LeftFile;
            _rightPath = options.RightFile;

            _left  = Image.FromFile(_leftPath) as Bitmap;
            _right = Image.FromFile(_rightPath) as Bitmap;

            if (_left == null || _right == null)
            {
                throw new NotSupportedException("Image format not supported!");
            }

            if (_left.Size != _right.Size)
            {
                throw new NotSupportedException("Different image sizes are not supported!");
            }

            _diffAlgorithm    = options.DiffAlgorithm;
            _diffHighlighter  = options.Highlighter;
            _progressObserver = options.ProgressObserver;
        }
        public IDiff <TType> Diff <TType>(TType @base, TType changed)
        {
            IDiffAlgorithm <TType> algorithm = this.Algorithms.GetDiffAlgorithm <TType>();

            return(algorithm.Compute(@base, changed));
        }
Пример #7
0
 public DiffText(IList <string> oldLines, IList <string> newLines, IDiffAlgorithm diffAlgorithm)
 {
     this.diff     = diffAlgorithm;
     this.oldLines = oldLines;
     this.newLines = newLines;
 }