//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal methods. /// <summary> /// Adds a difference to the difference list. /// </summary> /// <param name="difference">Difference to add.</param> internal void AddDifference(ComparisonDifference difference) { if (difference != null) { differenceList.Add(difference); } }
/// <summary> /// This lets the class know that no more differences will be added. /// Normally, the ComparisonOperation object is the one that calls /// this method. /// </summary> internal void FinishedComparison() { differences = new ComparisonDifference[differenceList.Count]; for (int i = 0; i < differences.Length; i++) { differences[i] = (ComparisonDifference)differenceList[i]; } }
/// <summary> /// Whether this difference is similar to a difference in /// another position. /// </summary> internal virtual bool IsSimilarTo(ComparisonDifference difference) { if (this == difference) { return(true); } else { return(false); } }
//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private methods. /// <summary> /// Describes the second part of a contiguous range of pixel /// differences by appending into the specified /// StringBuilder. /// </summary> private void DescribeContiguous(ComparisonDifference lastContiguous, System.Text.StringBuilder sb) { System.Diagnostics.Debug.Assert(lastContiguous != null); System.Diagnostics.Debug.Assert(sb != null); sb.Append("-("); sb.Append(lastContiguous.PixelPosition.X); sb.Append(";"); sb.Append(lastContiguous.PixelPosition.Y); sb.Append(")"); }
/// <summary>Returns a string representation of this object.</summary> /// <returns>A string representation of this object.</returns> public override string ToString() { System.Text.StringBuilder sb = new System.Text.StringBuilder( (1 + differences.Length) * 32); sb.Append(ToStringBrief()); ComparisonDifference lastDifference = null; ComparisonDifference lastContiguous = null; for (int i = 0; i < differences.Length; i++) { bool inContiguousRange = lastContiguous != null; ComparisonDifference difference = differences[i]; if (difference.IsSimilarTo(lastDifference)) { if (difference.IsContiguousTo(lastDifference)) { lastContiguous = difference; } else { if (inContiguousRange) { DescribeContiguous(lastContiguous, sb); lastContiguous = null; } sb.AppendFormat(",({0};{1})", difference.PixelPosition.X, difference.PixelPosition.Y); } } else { if (inContiguousRange) { DescribeContiguous(lastContiguous, sb); lastContiguous = null; } if (i != 0) { sb.Append("\r\n"); } sb.AppendFormat(" {0}", difference.ToString()); } lastDifference = difference; } if (lastContiguous != null) { DescribeContiguous(lastContiguous, sb); } sb.Append("\r\n"); return(sb.ToString()); }
/// <summary> /// Whether this difference is adjanct to a difference in /// another position. /// </summary> internal bool IsContiguousTo(ComparisonDifference difference) { if (difference == null) { return(false); } if (this == difference) { return(false); } return(difference.pixelPosition.X == this.pixelPosition.X + 1 || difference.pixelPosition.X == this.pixelPosition.X - 1); }
/// <summary> /// Whether this difference is similar to a difference in /// another position. /// </summary> internal override bool IsSimilarTo(ComparisonDifference difference) { ColorDistanceDifference d = difference as ColorDistanceDifference; if (d == null) { return(false); } if (d.expected == this.expected && d.found == this.found) { return(true); } return(false); }