/// /// <summary> * inRange - tests if the given x inside of this range /// * </summary> /// * <param name="x"> comparison value /// * </param> /// * <returns> boolean - true if x in range </returns> /// public virtual bool inRange(JDFShape x) { JDFShape min = this.LowerValue; JDFShape max = this.UpperValue; return(x.isGreaterOrEqual(min) && x.isLessOrEqual(max)); }
/// /// <summary> * constructor - constructs a shape with all values set via a JDFShape /// * </summary> /// * <param name="shape"> the given shape /// * </param> /// * <exception cref="FormatException"> - if the JDFShape has not a valid format </exception> /// public JDFShape(JDFShape shape) : base(JDFBaseDataTypes_Fields.MAX_SHAPE_DIMENSION) { Y = shape.Y; X = shape.X; Z = shape.Z; }
/// /// <summary> * constructs a JDFShapeRange with the values of the given String /// * </summary> /// * <param name="s"> the given string representation of the range /// * </param> /// * <exception cref="FormatException"> - if the String has not a valid format </exception> /// public JDFShapeRange(string s) { string[] strArray = s.Split("~".ToCharArray()); if ((strArray.Length <= 0) || (strArray.Length > 2)) { throw new FormatException("JDFShapeRange illegal string: " + s); } try { // the min and the max values are equal if (strArray.Length == 1) { m_left = new JDFShape(strArray[0].Trim()); m_right = new JDFShape(strArray[0].Trim()); } // two different values else { m_left = new JDFShape(strArray[0].Trim()); m_right = new JDFShape(strArray[1].Trim()); } } catch (FormatException) { throw new FormatException("JDFShapeRange illegal string: " + s); } }
/// /// <summary> * isPartOfRange - is range 'r' within this range? /// * </summary> /// * <param name="r"> the range to test /// * </param> /// * <returns> boolean - true if range 'r' is within this range, else false </returns> /// public override bool isPartOfRange(JDFRange ra) { JDFShapeRange r = (JDFShapeRange)ra; JDFShape min = this.LowerValue; JDFShape r_min = r.LowerValue; JDFShape max = this.UpperValue; JDFShape r_max = r.UpperValue; return(r_min.isGreaterOrEqual(min) && r_max.isLessOrEqual(max)); }
public virtual void testShape2() { JDFShape nl = new JDFShape(1, 2); Assert.AreEqual(1, nl.doubleAt(0), 0.0); Assert.AreEqual(2, nl.doubleAt(1), 0.0); Assert.AreEqual(0, nl.doubleAt(2), 0.0); Assert.AreEqual(1, nl.X, 0.0); Assert.AreEqual(2, nl.Y, 0.0); Assert.AreEqual(0, nl.Z, 0.0); }
// **************************************** Methods // ********************************************* /// /// <summary> * inRange - check whether shape 'x' is in the shape range defined by 'this' /// * </summary> /// * <param name="x"> shape value to test </param> /// * <returns> boolean - true if 'x' is in the range defined by 'this' </returns> /// public virtual bool inRange(JDFShape x) { int sz = rangeList.Count; for (int i = 0; i < sz; i++) { if (((JDFShapeRange)rangeList[i]).inRange(x)) { return(true); } } return(false); }
public virtual void testShape() { JDFShape nl = new JDFShape("1.1 2.2 3.3"); Assert.AreEqual(1.1, nl.doubleAt(0), 0.0); Assert.AreEqual(2.2, nl.doubleAt(1), 0.0); Assert.AreEqual(3.3, nl.doubleAt(2), 0.0); Assert.AreEqual(1.1, nl.X, 0.0); Assert.AreEqual(2.2, nl.Y, 0.0); Assert.AreEqual(3.3, nl.Z, 0.0); nl.Y = 5; Assert.AreEqual(5, nl.Y, 0.0); }
/// /// <summary> * isUniqueOrdered - tests if 'this' is UniqueOrdered RangeList /// * </summary> /// * <returns> boolean - true if 'this' is UniqueOrdered RangeList </returns> /// public override bool isUniqueOrdered() { int siz = rangeList.Count; if (siz == 0) { return(false); // attempt to operate on a null element } List <JDFShape> v = new List <JDFShape>(); // vector of ranges for (int i = 0; i < siz; i++) { JDFShapeRange r = (JDFShapeRange)rangeList[i]; v.Add(r.Left); if (!r.Left.Equals(r.Right)) { v.Add(r.Right); } } int n = v.Count - 1; if (n == 0) { return(true); // single value } JDFShape first = v[0]; JDFShape last = v[n]; if (first.Equals(last)) { return(false); } for (int j = 0; j < n; j++) { JDFShape @value = v[j]; JDFShape nextvalue = v[j + 1]; if (((first.isLess(last) && @value.isLess(nextvalue)) || (first.isGreater(last) && @value.isGreater(nextvalue))) == false) { return(false); } } return(true); }
/// /// <summary> * equals - returns true if both JDFShapes are equal, otherwise false /// * </summary> /// * <returns> boolean - true if equal otherwise false </returns> /// public override bool Equals(object other) { if (this == other) { return(true); } if (other == null) { return(false); } if (!other.GetType().Equals(this.GetType())) { return(false); } JDFShape shape = (JDFShape)other; return((Math.Abs(this.Y - shape.Y) <= JDFBaseDataTypes_Fields.EPSILON) && (Math.Abs(this.X - shape.X) <= JDFBaseDataTypes_Fields.EPSILON) && (Math.Abs(this.Z - shape.Z) <= JDFBaseDataTypes_Fields.EPSILON)); }
/// /// <summary> * isLessOrEqual - equality operator <= /// * </summary> /// * <param name="x"> the JDFShape object to compare to </param> /// * <returns> boolean - true if this <= x </returns> /// public virtual bool isLessOrEqual(JDFShape x) { return((Y <= x.Y) && (X <= x.X) && (Z <= x.Z)); }
/// /// <summary> * isGreaterOrEqual - equality operator >= /// * </summary> /// * <param name="x"> the JDFShape object to compare to </param> /// * <returns> boolean - true if this >= x </returns> /// public virtual bool isGreaterOrEqual(JDFShape x) { return((Y >= x.Y) && (X >= x.X) && (Z >= x.Z)); }
/// /// <summary> * constructor a JDFShapeRange with two JDFShape values ("from xmin to xmax") /// * </summary> /// * <param name="xmin"> the given min value </param> /// * <param name="xmax"> the given max value </param> /// public JDFShapeRange(JDFShape xmin, JDFShape xmax) { init(xmin, xmax); }
/// /// <summary> * append - adds an element defined by two JDFShapes: xMin~xMax /// * </summary> /// * <param name="xMin"> the left value of the range to append to the list </param> /// * <param name="xMax"> the right value of the range to append to the list </param> /// public virtual void Append(JDFShape xMin, JDFShape xMax) { Append(new JDFShapeRange(xMin, xMax)); }
/// /// <summary> * append - adds an individual JDFShape element /// * </summary> /// * <param name="x"> the left and right value of the range to append to the list </param> /// public virtual void Append(JDFShape x) { Append(new JDFShapeRange(x)); }
/// /// <summary> * Initialization /// * </summary> /// * <param name="x"> left boundary </param> /// * <param name="y"> right boundary </param> /// protected internal virtual void init(JDFShape x, JDFShape y) { m_left = x; m_right = y; }
/// /// <summary> * isGreater - equality operator > /// * </summary> /// * <param name="x"> the JDFShape object to compare to </param> /// * <returns> boolean - true if this > x </returns> /// public virtual bool isGreater(JDFShape x) { return(!Equals(x) && (Y >= x.Y) && (X >= x.X) && (Z >= x.Z)); }
/// /// <summary> * isLess - equality operator < /// * </summary> /// * <param name="x"> the JDFShape object to compare to </param> /// * <returns> boolean - true if this < x </returns> /// public virtual bool isLess(JDFShape x) { return(!Equals(x) && (Y <= x.Y) && (X <= x.X) && (Z <= x.Z)); }
/// /// <summary> * constructs a JDFShapeRange, both values are equal ("from x to x") /// * </summary> /// * <param name="x"> the given JDFShape </param> /// public JDFShapeRange(JDFShape x) { init(x, x); }