public void Clamp() { tlog.Debug(tag, $"Clamp START"); double d = 1.0; var testingTarget = NumericExtensions.Clamp(d, 0, 10); Assert.AreEqual(d, testingTarget, "Should be equal."); float f = 1.0f; var testingTarget2 = NumericExtensions.Clamp(f, 0, 10); Assert.AreEqual(f, testingTarget2, "Should be equal."); int i = 1; var testingTarget3 = NumericExtensions.Clamp(i, 0, 10); Assert.AreEqual(i, testingTarget3, "Should be equal."); tlog.Debug(tag, $"Clamp END"); }
/// <summary> /// Arranges and sizes the /// <see cref="T:System.Windows.Controls.WrapPanel" /> control and its /// child elements. /// </summary> /// <param name="finalSize"> /// The area within the parent that the /// <see cref="T:System.Windows.Controls.WrapPanel" /> should use /// arrange itself and its children. /// </param> /// <returns> /// The actual size used by the /// <see cref="T:System.Windows.Controls.WrapPanel" />. /// </returns> protected override Size ArrangeOverride(Size finalSize) { // Variables tracking the size of the current line, and the maximum // size available to fill. Note that the line might represent a row // or a column depending on the orientation. Orientation o = Orientation; OrientedSize lineSize = new OrientedSize(o); OrientedSize maximumSize = new OrientedSize(o, finalSize.Width, finalSize.Height); // Determine the constraints for individual items double itemWidth = ItemWidth; double itemHeight = ItemHeight; bool hasFixedWidth = !double.IsNaN(itemWidth); bool hasFixedHeight = !double.IsNaN(itemHeight); double indirectOffset = 0; double?directDelta = (o == Orientation.Horizontal) ? (hasFixedWidth ? (double?)itemWidth : null) : (hasFixedHeight ? (double?)itemHeight : null); // Measure each of the Children. We will process the elements one // line at a time, just like during measure, but we will wait until // we've completed an entire line of elements before arranging them. // The lineStart and lineEnd variables track the size of the // currently arranged line. UIElementCollection children = Children; int count = children.Count; int lineStart = 0; for (int lineEnd = 0; lineEnd < count; lineEnd++) { UIElement element = children[lineEnd]; // Get the size of the element OrientedSize elementSize = new OrientedSize( o, hasFixedWidth ? itemWidth : element.DesiredSize.Width, hasFixedHeight ? itemHeight : element.DesiredSize.Height); // If this element falls of the edge of the line if (NumericExtensions.IsGreaterThan(lineSize.Direct + elementSize.Direct, maximumSize.Direct)) { // Then we just completed a line and we should arrange it ArrangeLine(lineStart, lineEnd, directDelta, indirectOffset, lineSize.Indirect); // Move the current element to a new line indirectOffset += lineSize.Indirect; lineSize = elementSize; // If the current element is larger than the maximum size if (NumericExtensions.IsGreaterThan(elementSize.Direct, maximumSize.Direct)) { // Arrange the element as a single line ArrangeLine(lineEnd, ++lineEnd, directDelta, indirectOffset, elementSize.Indirect); // Move to a new line indirectOffset += lineSize.Indirect; lineSize = new OrientedSize(o); } // Advance the start index to a new line after arranging lineStart = lineEnd; } else { // Otherwise just add the element to the end of the line lineSize.Direct += elementSize.Direct; lineSize.Indirect = Math.Max(lineSize.Indirect, elementSize.Indirect); } } // Arrange any elements on the last line if (lineStart < count) { ArrangeLine(lineStart, count, directDelta, indirectOffset, lineSize.Indirect); } return(finalSize); }
protected override Size MeasureOverride(Size constraint) { // Variables tracking the size of the current line, the total size // measured so far, and the maximum size available to fill. Note // that the line might represent a row or a column depending on the // orientation. Orientation o = Orientation; OrientedSize lineSize = new OrientedSize(o); OrientedSize totalSize = new OrientedSize(o); OrientedSize maximumSize = new OrientedSize(o, constraint.Width, constraint.Height); // Determine the constraints for individual items double itemWidth = ItemWidth; double itemHeight = ItemHeight; bool hasFixedWidth = !double.IsNaN(itemWidth); bool hasFixedHeight = !double.IsNaN(itemHeight); Size itemSize = new Size( hasFixedWidth ? itemWidth : constraint.Width, hasFixedHeight ? itemHeight : constraint.Height); // Measure each of the Children foreach (UIElement element in Children) { // Determine the size of the element element.Measure(itemSize); OrientedSize elementSize = new OrientedSize( o, hasFixedWidth ? itemWidth : element.DesiredSize.Width, hasFixedHeight ? itemHeight : element.DesiredSize.Height); // If this element falls of the edge of the line if (NumericExtensions.IsGreaterThan(lineSize.Direct + elementSize.Direct, maximumSize.Direct)) { // Update the total size with the direct and indirect growth // for the current line totalSize.Direct = Math.Max(lineSize.Direct, totalSize.Direct); totalSize.Indirect += lineSize.Indirect; // Move the element to a new line lineSize = elementSize; // If the current element is larger than the maximum size, // place it on a line by itself if (NumericExtensions.IsGreaterThan(elementSize.Direct, maximumSize.Direct)) { // Update the total size for the line occupied by this // single element totalSize.Direct = Math.Max(elementSize.Direct, totalSize.Direct); totalSize.Indirect += elementSize.Indirect; // Move to a new line lineSize = new OrientedSize(o); } } else { // Otherwise just add the element to the end of the line lineSize.Direct += elementSize.Direct; lineSize.Indirect = Math.Max(lineSize.Indirect, elementSize.Indirect); } } // Update the total size with the elements on the last line totalSize.Direct = Math.Max(lineSize.Direct, totalSize.Direct); totalSize.Indirect += lineSize.Indirect; // Return the total size required as an un-oriented quantity return(new Size(totalSize.Width, totalSize.Height)); }
public void ToEnglishWords_WithNullModel_ReturnsNull(double source, string expected) { var result = NumericExtensions.ToEnglishWords(source); result.Should().Match(x => x.Equals(expected, StringComparison.OrdinalIgnoreCase)); }
public override string ToString() { CheckSequenceNumber(); return($"AT*LED={SequenceNumber},{(int) ledAnimation},{NumericExtensions.Normalize(frequency)},{duration}\r"); }
public void WriteMultiTraceRegular() { int id = 0, traceNumber = 0, traceCount = 0; // Find an existing time series that has at least one trace and where the // time series type is not irregular String comm = "SELECT TOP(1) x.Id FROM " + _traceTableName + " t\n" + "JOIN " + _paramTableName + " x ON t.TimeSeries_Id=x.Id\n" + "WHERE x.TimeSeriesType != 0"; using (var queryCommand = new SqlCommand(comm, _connx) { CommandTimeout = 0 }) using (var reader = queryCommand.ExecuteReader()) { // Loop through every record in the result set while (reader.Read()) { // Populate an array of Objects with the query results for this record Object[] valueArray = new Object[1]; reader.GetValues(valueArray); id = (int)valueArray[0]; } } // Get the highest existing trace number of the existing time series comm = "SELECT TOP(1) t.[TraceNumber] FROM " + _traceTableName + " t\n" + "where t.[TimeSeries_Id]=" + id + "\norder by t.[TraceNumber] desc"; using (var queryCommand = new SqlCommand(comm, _connx) { CommandTimeout = 0 }) using (var reader = queryCommand.ExecuteReader()) { // Loop through every record in the result set while (reader.Read()) { // Populate an array of Objects with the query results for this record Object[] valueArray = new Object[1]; reader.GetValues(valueArray); traceNumber = (int)valueArray[0]; } } // Get the highest existing trace number of the existing time series comm = "SELECT COUNT(*) FROM " + _traceTableName + " t\n" + "where t.[TimeSeries_Id]=" + id; using (var queryCommand = new SqlCommand(comm, _connx) { CommandTimeout = 0 }) using (var reader = queryCommand.ExecuteReader()) { // Loop through every record in the result set while (reader.Read()) { // Populate an array of Objects with the query results for this record Object[] valueArray = new Object[1]; reader.GetValues(valueArray); traceCount = (int)valueArray[0]; } } // Read the values of the existing trace that has the highest trace number int ArrayDim = 5000; var valArray = new Double[ArrayDim]; int nVals = _lib.ReadValuesRegular(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName), id, traceNumber, ArrayDim, valArray, DateTime.MinValue, DateTime.MaxValue); var newValArray = valArray.Take(nVals).ToArray(); // Create temporary tables that will absorb all data changes. We do this because // the tested methods use SqlBulkCopy, which is not subject to TransactionScope. CreateTempTablesFromExisting(id); // The method being tested--we add another trace that is identical to the one we just // read, but give it a new trace number. _lib.WriteTraceRegular(_connxNumber, GetSbyte(_TestParamTableName), GetSbyte(_TestTraceTableName), id, traceNumber + 1, newValArray); _lib.CommitTraceWrites(_connxNumber, GetSbyte(_TestParamTableName), GetSbyte(_TestTraceTableName)); // Now verify that the new trace is written to the DB, // and that the checksum of the time series includes all traces including the new one comm = "SELECT c.[Checksum], c.[TimeStepUnit], c.[TimeStepQuantity], " + "c.[StartDate],\n t.[TraceNumber], t.[Checksum]\n" + "FROM [" + _TestParamTableName + "] c\n" + "LEFT JOIN [" + _TestTraceTableName + "] t ON c.[Id]=t.[TimeSeries_Id]\n" + "WHERE c.[Id]=" + id; using (var queryCommand = new SqlCommand(comm, _connx) { CommandTimeout = 0 }) using (var reader = queryCommand.ExecuteReader()) { Boolean initialized = false; var traceList = new List <ITimeSeriesTrace>(); Byte[] checksum = new Byte[0]; var timeStepUnit = TSDateCalculator.TimeStepUnitCode.Day; short timeStepQuantity = 1; DateTime startDate = DateTime.MinValue; // Loop through every record in the result set while (reader.Read()) { // Populate an array of Objects with the query results for this record Object[] valueArray = new Object[6]; reader.GetValues(valueArray); if (!initialized) { checksum = (Byte[])valueArray[0]; timeStepUnit = (TSDateCalculator.TimeStepUnitCode)(int) valueArray[1]; timeStepQuantity = (short)(int)valueArray[2]; startDate = (DateTime)valueArray[3]; initialized = true; } // Add to the collection a container object for this trace's properties traceList.Add(new TSTrace { TraceNumber = (int)valueArray[4], Checksum = (Byte[])valueArray[5] }); } // Is the new trace in the DB? Assert.IsTrue(traceList.Any(o => o.TraceNumber == traceNumber + 1)); // Is the actual number of traces incremented by one? Assert.AreEqual(traceCount + 1, traceList.Count); // Do an independent computation of the checksum var correctChecksum = TSBlobCoder.ComputeChecksum(timeStepUnit, timeStepQuantity, startDate, traceList); // was the correct checksum stored in the DB? Assert.IsTrue(NumericExtensions.ByteArraysAreEqual(correctChecksum, checksum)); } }