/// <summary> /// /// </summary> /// <param name="geom"></param> /// <param name="bounds"></param> public TreeLoader2D(PagedGeometry geom, TBounds bounds) { //Calculate grid size mGeom = geom; mPageSize = mGeom.PageSize; //Reset height function mHeightFunction = null; mHeightFunctionUserData = null; //Make sure the bounds are aligned with PagedGeometry's grid, so the TreeLoader's grid tiles will have a 1:1 relationship mActualBounds = bounds; mGridBounds = bounds; mGridBounds.Left = (float)(mPageSize * System.Math.Floor((mGridBounds.Left - mGeom.Bounds.Left) / mPageSize) + mGeom.Bounds.Left); mGridBounds.Top = (float)(mPageSize * System.Math.Floor((mGridBounds.Top - mGeom.Bounds.Top) / mPageSize) + mGeom.Bounds.Top); mGridBounds.Right = (float)(mPageSize * System.Math.Ceiling((mGridBounds.Right - mGeom.Bounds.Left) / mPageSize) + mGeom.Bounds.Left); mGridBounds.Bottom = (float)(mPageSize * System.Math.Ceiling((mGridBounds.Bottom - mGeom.Bounds.Top) / mPageSize) + mGeom.Bounds.Top); //Calculate page grid size mPageGridX = (int)(System.Math.Ceiling(mGridBounds.Width / mPageSize) + 1); mPageGridZ = (int)(System.Math.Ceiling(mGridBounds.Height / mPageSize) + 1); //Reset color map mColorMap = null; mColorMapFilter = MapFilter.None; //Default scale range mMaximumScale = 2.0f; mMinimumScale = 0.0f; }
public BalancedBoundingNode Insert(TBounds lower, TBounds upper, TPayload value) { if (lower.CompareTo(upper) > 0) { throw new ArgumentOutOfRangeException(nameof(lower), $"lower ({lower}) needs to be <= upper ({upper})"); } if (upper.CompareTo(LowerBound) <= 0) { if (ReferenceEquals(LowerTree, Nil)) { LowerTree = new BalancedBoundingNode(lower, upper, value, Colour.Black) { Parent = this }; return(LowerTree); } return(LowerTree.Insert(lower, upper, value)); } if (lower.CompareTo(UpperBound) >= 0) { if (ReferenceEquals(UpperTree, Nil)) { UpperTree = new BalancedBoundingNode(lower, upper, value, Colour.Black) { Parent = this }; return(UpperTree); } return(UpperTree.Insert(lower, upper, value)); } throw new ArgumentOutOfRangeException($"Lower {lower} and upper {upper} overlap with this tree l:{LowerBound},u:{UpperBound}"); }
public static double LinearInterpolation(double[] srcArray, double xVal) { TBounds bound = GetNeighborIndices(srcArray, xVal); double ylbound = srcArray[bound.LBound]; double yubound = srcArray[bound.UBound]; // interpolation double interp = ylbound + (xVal - bound.LBound) * (yubound - ylbound) / (bound.UBound - bound.LBound); return(interp); }
public bool ReadCurrency(out double doubleValue, TBounds boundsCode, double bound) { bool valueOk = true; string message = ""; string textBoxContent = this.Text; doubleValue = 0.0; textBoxContent = textBoxContent.Replace("$", ""); textBoxContent = textBoxContent.Replace(",", ""); if ((textBoxContent[0] == '(') && (textBoxContent[textBoxContent.Length - 1] == ')')) { textBoxContent = textBoxContent.Replace("(", "-"); textBoxContent = textBoxContent.Replace(")", ""); } try { doubleValue = Double.Parse(textBoxContent); } catch { message = "Invalid currency value"; valueOk = false; } if (valueOk) { if ((boundsCode == TBounds.Lower) && (doubleValue < bound)) { message = String.Format("Value must be >= {0:c}", bound); valueOk = false; } else if ((boundsCode == TBounds.Upper) && (doubleValue > bound)) { message = String.Format("Value must be <= {0:c}", bound); valueOk = false; } else if (boundsCode == TBounds.Both) { message = String.Format("ETextBox.TBounds.Both cannot be used with this version\n" + "of ETextBox.ReadCurrency()"); valueOk = false; } } if (!valueOk) { MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Question); this.Select(); } return(valueOk); }
public BalancedBoundingNode(TBounds lower, TBounds upper, TPayload value, Colour nodeColour) { if (lower.CompareTo(upper) > 0) { throw new ArgumentOutOfRangeException(nameof(lower), $"lower({lower}) must be <= upper({upper}"); } LowerBound = lower; UpperBound = upper; Value = value; NodeColour = nodeColour; LowerTree = Nil; UpperTree = Nil; Parent = Nil; }
public bool ReadDecimal(out decimal decimalValue, TBounds boundsCode, decimal bound1, decimal bound2) { bool valueOk = true; string message = ""; decimalValue = (decimal)0.0; try { decimalValue = decimal.Parse(this.Text); } catch { message = "Invalid decimal value"; valueOk = false; } if (valueOk) { if ((boundsCode == TBounds.Lower) && (decimalValue < bound1)) { message = String.Format("Value must be >= {0}", bound1); valueOk = false; } else if ((boundsCode == TBounds.Upper) && (decimalValue > bound2)) { message = String.Format("Value must be <= {0}", bound2); valueOk = false; } else if ((boundsCode == TBounds.Both) && ((decimalValue < bound1) || (decimalValue > bound2))) { message = String.Format("Value must be >= {0} and <= {1}", bound1, bound2); valueOk = false; } } if (!valueOk) { MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Question); this.Select(); } return(valueOk); }
public bool ReadDecimal(out decimal decimalValue, TBounds boundsCode, decimal bound) { bool valueOk = true; string message = ""; decimalValue = (decimal)0.0; try { decimalValue = decimal.Parse(this.Text); } catch { message = "Invalid decimal value"; valueOk = false; } if (valueOk) { if ((boundsCode == TBounds.Lower) && (decimalValue < bound)) { message = String.Format("Value must be >= {0}", bound); valueOk = false; } else if ((boundsCode == TBounds.Upper) && (decimalValue > bound)) { message = String.Format("Value must be <= {0}", bound); valueOk = false; } else if (boundsCode == TBounds.Both) { message = String.Format("ETextBox.TBounds.Both cannot be used with this version\n" + "of ETextBox.ReadDecimal()"); valueOk = false; } } if (!valueOk) { MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Question); this.Select(); } return(valueOk); }
public bool ReadUInt(out uint uintValue, TBounds boundsCode, uint bound1, uint bound2) { bool valueOk = true; string message = ""; uintValue = 0; try { uintValue = UInt32.Parse(this.Text.Replace(",", "")); } catch { message = "Invalid unsigned integer value"; valueOk = false; } if (valueOk) { if ((boundsCode == TBounds.Lower) && (uintValue < bound1)) { message = String.Format("Value must be >= {0}", bound1); valueOk = false; } else if ((boundsCode == TBounds.Upper) && (uintValue > bound2)) { message = String.Format("Value must be <= {0}", bound2); valueOk = false; } else if ((boundsCode == TBounds.Both) && ((uintValue < bound1) || (uintValue > bound2))) { message = String.Format("Value must be >= {0} and <= {1}", bound1, bound2); valueOk = false; } } if (!valueOk) { MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Question); this.Select(); } return(valueOk); }
public bool ReadInt(out int intValue, TBounds boundsCode, int bound) { bool valueOk = true; string message = ""; intValue = 0; try { intValue = Int32.Parse(this.Text.Replace(",", "")); } catch { message = "Invalid signed integer value"; valueOk = false; } if (valueOk) { if ((boundsCode == TBounds.Lower) && (intValue < bound)) { message = String.Format("Value must be >= {0}", bound); valueOk = false; } else if ((boundsCode == TBounds.Upper) && (intValue > bound)) { message = String.Format("Value must be <= {0}", bound); valueOk = false; } else if (boundsCode == TBounds.Both) { message = String.Format("ETextBox.TBounds.Both cannot be used with this version\n" + "of ETextBox.ReadInt()"); valueOk = false; } } if (!valueOk) { MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Question); this.Select(); } return(valueOk); }
// dimensions should be checked before using this interpolation public static double BilinearInterpolation(double[] srcXAxis, double[] srcYAxis, double[,] srcTable, double dstX, double dstY) { TBounds xbound = GetNeighborIndices(srcXAxis, dstX); TBounds ybound = GetNeighborIndices(srcYAxis, dstY); double q11 = srcTable[ybound.LBound, xbound.LBound]; double q21 = srcTable[ybound.UBound, xbound.LBound]; double q12 = srcTable[ybound.LBound, xbound.UBound]; double q22 = srcTable[ybound.UBound, xbound.UBound]; double x1 = srcXAxis[xbound.LBound]; double x2 = srcXAxis[xbound.UBound]; double y1 = srcYAxis[ybound.LBound]; double y2 = srcYAxis[ybound.UBound]; double interp; // if point exactly found on a node do not interpolate if (xbound.Overlapped && ybound.Overlapped) { interp = q11; } // if point lies exactly on an xAxis node do linear interpolation else if (xbound.Overlapped) { interp = q11 + (q22 - q11) * (dstY - y1) / (y2 - y1); } // if point lies exactly on an yAxis node do liear interpolation else if (ybound.Overlapped) { interp = q11 + (q12 - q11) * (dstX - x1) / (x2 - x1); } else { interp = (q11 * (y2 - dstY) * (x2 - dstX) + q21 * (dstY - y1) * (x2 - dstX) + q12 * (y2 - dstY) * (dstX - x1) + q22 * (dstY - y1) * (dstX - x1)) / ((y2 - y1) * (x2 - x1)); } return(interp); }
/// <summary> /// /// </summary> /// <param name="area"></param> /// <param name="type"></param> /// <returns></returns> public List<object> DeleteTrees(TBounds area, Entity type) { throw new NotImplementedException(); }
public bool ReadCurrency(out double doubleValue, TBounds boundsCode, double bound) { bool valueOk=true; string message=""; string textBoxContent = this.Text; doubleValue = 0.0; textBoxContent = textBoxContent.Replace("$",""); textBoxContent = textBoxContent.Replace(",",""); if ((textBoxContent[0]=='(') && (textBoxContent[textBoxContent.Length-1]==')')) { textBoxContent = textBoxContent.Replace("(","-"); textBoxContent = textBoxContent.Replace(")",""); } try { doubleValue = Double.Parse(textBoxContent); } catch { message = "Invalid currency value"; valueOk = false; } if (valueOk) if ((boundsCode==TBounds.Lower) && (doubleValue<bound)) { message = String.Format("Value must be >= {0:c}",bound); valueOk = false; } else if ((boundsCode==TBounds.Upper) && (doubleValue>bound)) { message = String.Format("Value must be <= {0:c}",bound); valueOk = false; } else if (boundsCode==TBounds.Both) { message = String.Format("ETextBox.TBounds.Both cannot be used with this version\n" + "of ETextBox.ReadCurrency()"); valueOk = false; } if (! valueOk) { MessageBox.Show(message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Question); this.Select(); } return valueOk; }
public bool ReadDouble(out double doubleValue, TBounds boundsCode, double bound1, double bound2) { bool valueOk=true; string message=""; doubleValue = 0.0; try { doubleValue = Double.Parse(this.Text); } catch { message = "Invalid double value"; valueOk = false; } if (valueOk) if ((boundsCode==TBounds.Lower) && (doubleValue<bound1)) { message = String.Format("Value must be >= {0}",bound1); valueOk = false; } else if ((boundsCode==TBounds.Upper) && (doubleValue>bound2)) { message = String.Format("Value must be <= {0}",bound2); valueOk = false; } else if ((boundsCode==TBounds.Both) && ((doubleValue<bound1) || (doubleValue>bound2))) { message = String.Format("Value must be >= {0} and <= {1}",bound1,bound2); valueOk = false; } if (! valueOk) { MessageBox.Show(message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Question); this.Select(); } return valueOk; }
public bool ReadDouble(out double doubleValue, TBounds boundsCode, double bound) { bool valueOk=true; string message=""; doubleValue = 0.0; try { doubleValue = Double.Parse(this.Text); } catch { message = "Invalid double value"; valueOk = false; } if (valueOk) if ((boundsCode==TBounds.Lower) && (doubleValue<bound)) { message = String.Format("Value must be >= {0}",bound); valueOk = false; } else if ((boundsCode==TBounds.Upper) && (doubleValue>bound)) { message = String.Format("Value must be <= {0}",bound); valueOk = false; } else if (boundsCode==TBounds.Both) { message = String.Format("ETextBox.TBounds.Both cannot be used with this version\n" + "of ETextBox.ReadDouble()"); valueOk = false; } if (! valueOk) { MessageBox.Show(message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Question); this.Select(); } return valueOk; }
/// <summary> /// /// </summary> /// <param name="area"></param> /// <returns></returns> public List<object> DeleteTrees(TBounds area) { return DeleteTrees(area, null); }
public bool ReadUInt(out uint uintValue, TBounds boundsCode, uint bound) { bool valueOk=true; string message=""; uintValue = 0; try { uintValue = UInt32.Parse(this.Text.Replace(",","")); } catch { message = "Invalid unsigned integer value"; valueOk = false; } if (valueOk) if ((boundsCode==TBounds.Lower) && (uintValue<bound)) { message = String.Format("Value must be >= {0}",bound); valueOk = false; } else if ((boundsCode==TBounds.Upper) && (uintValue>bound)) { message = String.Format("Value must be <= {0}",bound); valueOk = false; } else if (boundsCode==TBounds.Both) { message = String.Format("ETextBox.TBounds.Both cannot be used with this version\n" + "of ETextBox.ReadUInt()"); valueOk = false; } if (! valueOk) { MessageBox.Show(message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Question); this.Select(); } return valueOk; }
public bool ReadInt(out int intValue, TBounds boundsCode, int bound1, int bound2) { bool valueOk=true; string message=""; intValue = 0; try { intValue = Int32.Parse(this.Text.Replace(",","")); } catch { message = "Invalid signed integer value"; valueOk = false; } if (valueOk) if ((boundsCode==TBounds.Lower) && (intValue<bound1)) { message = String.Format("Value must be >= {0}",bound1); valueOk = false; } else if ((boundsCode==TBounds.Upper) && (intValue>bound2)) { message = String.Format("Value must be <= {0}",bound2); valueOk = false; } else if ((boundsCode==TBounds.Both) && ((intValue<bound1) || (intValue>bound2))) { message = String.Format("Value must be >= {0} and <= {1}",bound1,bound2); valueOk = false; } if (! valueOk) { MessageBox.Show(message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Question); this.Select(); } return valueOk; }