/// <summary> /// Adds the StylusPoints in the StylusPointCollection to this StylusPointCollection /// </summary> /// <param name="stylusPoints">stylusPoints</param> public void Add(StylusPointCollection stylusPoints) { //note that we don't raise an exception if stylusPoints.Count == 0 if (null == stylusPoints) { throw new ArgumentNullException("stylusPoints"); } if (!StylusPointDescription.AreCompatible(stylusPoints.Description, _stylusPointDescription)) { throw new ArgumentException(SR.Get(SRID.IncompatibleStylusPointDescriptions), "stylusPoints"); } // cache count outside of the loop, so if this SPC is ever passed // we don't loop forever int count = stylusPoints.Count; for (int x = 0; x < count; x++) { StylusPoint stylusPoint = stylusPoints[x]; stylusPoint.Description = _stylusPointDescription; //this does not go through our protected virtuals ((List <StylusPoint>) this.Items).Add(stylusPoint); } if (stylusPoints.Count > 0) { OnChanged(EventArgs.Empty); } }
/// <summary> /// Compares two StylusPoint instances for exact equality. /// Note that double values can acquire error when operated upon, such that /// an exact comparison between two values which are logically equal may fail. /// Furthermore, using this equality operator, Double.NaN is not equal to itself. /// Descriptions must match for equality to succeed and additional values must match /// </summary> /// <returns> /// bool - true if the two Stylus instances are exactly equal, false otherwise /// </returns> /// <param name='stylusPoint1'>The first StylusPoint to compare</param> /// <param name='stylusPoint2'>The second StylusPoint to compare</param> public static bool Equals(StylusPoint stylusPoint1, StylusPoint stylusPoint2) { // // do the cheap comparison first // bool membersEqual = stylusPoint1._x == stylusPoint2._x && stylusPoint1._y == stylusPoint2._y && stylusPoint1._pressureFactor == stylusPoint2._pressureFactor; if (!membersEqual) { return(false); } // // before we go checking the descriptions... check to see if both additionalData's are null // we can infer that the SPD's are just X,Y,P and that they are compatible. // if (stylusPoint1._additionalValues == null && stylusPoint2._additionalValues == null) { Debug.Assert(StylusPointDescription.AreCompatible(stylusPoint1.Description, stylusPoint2.Description)); return(true); } // // ok, the members are equal. compare the description and then additional data // if (object.ReferenceEquals(stylusPoint1.Description, stylusPoint2.Description) || StylusPointDescription.AreCompatible(stylusPoint1.Description, stylusPoint2.Description)) { // // descriptions match and there are equal numbers of additional values // let's check the values // for (int x = 0; x < stylusPoint1._additionalValues.Length; x++) { if (stylusPoint1._additionalValues[x] != stylusPoint2._additionalValues[x]) { return(false); } } // // Ok, ok already, we're equal // return(true); } return(false); }
/// <summary> /// called by base class Collection<T> when an item is set in list; /// raises a CollectionChanged event to any listeners /// </summary> protected override sealed void SetItem(int index, StylusPoint stylusPoint) { if (!StylusPointDescription.AreCompatible(stylusPoint.Description, _stylusPointDescription)) { throw new ArgumentException(SR.Get(SRID.IncompatibleStylusPointDescriptions), "stylusPoint"); } stylusPoint.Description = _stylusPointDescription; base.SetItem(index, stylusPoint); OnChanged(EventArgs.Empty); }
/// <summary> /// Helper that transforms and scales in one go /// </summary> internal StylusPointCollection Reformat(StylusPointDescription subsetToReformatTo, GeneralTransform transform) { if (!subsetToReformatTo.IsSubsetOf(this.Description)) { throw new ArgumentException(SR.Get(SRID.InvalidStylusPointDescriptionSubset), "subsetToReformatTo"); } StylusPointDescription subsetToReformatToWithCurrentMetrics = StylusPointDescription.GetCommonDescription(subsetToReformatTo, this.Description); //preserve metrics from this spd if (StylusPointDescription.AreCompatible(this.Description, subsetToReformatToWithCurrentMetrics) && (transform is Transform) && ((Transform)transform).IsIdentity) { //subsetToReformatTo might have different x, y, p metrics return(this.Clone(transform, subsetToReformatToWithCurrentMetrics)); } // // we really need to reformat this... // StylusPointCollection newCollection = new StylusPointCollection(subsetToReformatToWithCurrentMetrics, this.Count); int additionalDataCount = subsetToReformatToWithCurrentMetrics.GetExpectedAdditionalDataCount(); ReadOnlyCollection <StylusPointPropertyInfo> properties = subsetToReformatToWithCurrentMetrics.GetStylusPointProperties(); bool isIdentity = (transform is Transform) ? ((Transform)transform).IsIdentity : false; for (int i = 0; i < this.Count; i++) { StylusPoint stylusPoint = this[i]; double xCoord = stylusPoint.X; double yCoord = stylusPoint.Y; float pressure = stylusPoint.GetUntruncatedPressureFactor(); if (!isIdentity) { Point p = new Point(xCoord, yCoord); transform.TryTransform(p, out p); xCoord = p.X; yCoord = p.Y; } int[] newData = null; if (additionalDataCount > 0) { //don't init, we'll do that below newData = new int[additionalDataCount]; } StylusPoint newStylusPoint = new StylusPoint(xCoord, yCoord, pressure, subsetToReformatToWithCurrentMetrics, newData, false, false); //start at 3, skipping x, y, pressure for (int x = StylusPointDescription.RequiredCountOfProperties /*3*/; x < properties.Count; x++) { int value = stylusPoint.GetPropertyValue(properties[x]); newStylusPoint.SetPropertyValue(properties[x], value, false /*copy on write*/); } //bypass validation ((List <StylusPoint>)newCollection.Items).Add(newStylusPoint); } return(newCollection); }