Here are the examples of the csharp api System.Math.Log(double, double) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
643 Examples
19
View Source File : Mathd.cs
License : MIT License
Project Creator : 734843327
License : MIT License
Project Creator : 734843327
public static double Log(double d, double p) {
return Math.Log(d, p);
}
19
View Source File : RealtimeWaterfall3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
// Initialize FFT
_transform.init((uint) Math.Log(_pointsPerSlice, 2));
_transformSize = _pointsPerSlice * 2;
_real = new double[_transformSize];
_imaginary = new double[_transformSize];
// Initialize WaterfallDataSeries3D
_waterfallDataSeries = new WaterfallDataSeries3D<double>(_pointsPerSlice, _maxSliceCount)
{
StartX = 10,
StepX = 1,
StartZ = 25,
StepZ = 10
};
WaterfallSeries.DataSeries = _waterfallDataSeries;
MeshSeries.DataSeries = _waterfallDataSeries;
}
19
View Source File : CreateAWaterfall3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
var pointsPerSlice = 100;
var sliceCount = 20;
var logBase = 10;
var slicePositions = new double[sliceCount];
for (int i = 0; i < sliceCount; ++i)
{
slicePositions[i] = Math.Pow(logBase, i);
}
var dataSeries = new WaterfallDataSeries3D<double>(pointsPerSlice, slicePositions)
{
SeriesName = "Waterfall",
StartX = 10,
StepX = 1
};
_transform.init((uint)Math.Log(pointsPerSlice, 2));
FillDataSeries(dataSeries, sliceCount, pointsPerSlice);
WaterfallSeries.DataSeries = dataSeries;
}
19
View Source File : ViewModel3DFactory.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private static WaterfallDataSeries3D<double> GereplacederfallDataSeries()
{
var pointsPerSlice = 100;
var sliceCount = 20;
var logBase = 10;
var slicePositions = new double[sliceCount];
for (int i = 0; i < sliceCount; ++i)
{
slicePositions[i] = i;
}
var dataSeries = new WaterfallDataSeries3D<double>(pointsPerSlice, slicePositions);
dataSeries.StartX = 10;
dataSeries.StepX = 1;
_transform.init((uint)Math.Log(pointsPerSlice, 2));
var count = pointsPerSlice * 2;
var re = new double[count];
var im = new double[count];
for (int sliceIndex = 0; sliceIndex < sliceCount; ++sliceIndex)
{
for (var i = 0; i < count; i++)
{
re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
5 * Math.Sin(2 * Math.PI * i / 10) +
2.0 * _random.NextDouble();
im[i] = -10;
}
_transform.run(re, im);
var scaleCoef = Math.Pow(1.5, sliceIndex * 0.3) / Math.Pow(1.5, sliceCount * 0.3);
for (var pointIndex = 0; pointIndex < pointsPerSlice; pointIndex++)
{
var mag = Math.Sqrt(re[pointIndex] * re[pointIndex] + im[pointIndex] * im[pointIndex]);
var yVal = _random.Next(10, 20) * Math.Log10(mag / pointsPerSlice);
yVal = (yVal < -25 || yVal > -5)
? (yVal < -25) ? -25 : _random.Next(-6, -3)
: yVal;
dataSeries[sliceIndex, pointIndex] = -yVal * scaleCoef;
}
}
return dataSeries;
}
19
View Source File : LinearToLogarithmicValueConverter.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is IConvertible convertible)
{
return Math.Log(convertible.ToDouble(CultureInfo.InvariantCulture), LogarithmicBase);
}
return value;
}
19
View Source File : CreateInvertedIndex.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public static void CreateIndex(IEnumerable<KeyValuePair<Guid, Example>> examples)
{
var ex = examples.ToList();
foreach (var example in ex)
{
string lines = GetTextFromExample(example.Value);
var terms = GetTerms(lines);
// Memory optimisation. Store term indices as ushort (16bit)
if (terms.Count > ushort.MaxValue)
throw new InvalidOperationException("Too many terms in this example: " + example.Value.replacedle);
var termDictExample = new Dictionary<string, List<ushort>>();
for (ushort i = 0; i < terms.Count; i++)
{
var term = terms[i];
if (termDictExample.ContainsKey(term))
{
termDictExample[term].Add(i);
}
else
{
termDictExample[term] = new List<ushort> { i };
}
}
var norm = Math.Sqrt(termDictExample.Sum(termDict => Sqr(termDict.Value.Count)));
foreach (var termDict in termDictExample)
{
var term = termDict.Key;
termDict.Value.TrimExcess();
if (_invertedIndex.ContainsKey(term))
{
var ti = new TermInfo(example.Key, termDict.Value.ToArray(), (float) (termDict.Value.Count / norm));
_invertedIndex[term].TermInfos.Add(ti);
}
else
{
_invertedIndex[term] = new Posting(new List<TermInfo>
{
new TermInfo(example.Key, termDict.Value.ToArray(), (float) (termDict.Value.Count/norm))
});
}
_invertedIndex[term].InvertedDoreplacedentFrequency += 1;
}
}
_invertedIndex.ForEachDo(
x => x.Value.InvertedDoreplacedentFrequency = Math.Log(ex.Count/x.Value.InvertedDoreplacedentFrequency));
}
19
View Source File : CreateInvertedIndex.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public static void CreateIndexForCode(IEnumerable<KeyValuePair<Guid, Example>> examples)
{
var ex = examples.ToList();
foreach (var example in ex)
{
var tokenizer = new NGramTokenizer();
string lines = GetSourceCodeFromExample(example.Value);
var terms = lines.ToLower().Split(' ').Where(x => x != "")
.Select(tokenizer.Tokenize)
.SelectMany(strings => strings.SelectMany(inner => inner))
.Select(sb => sb.ToString())
.Where(s => !string.IsNullOrEmpty(s) && s.Length > 1)
.ToList();
// Memory optimisation. Store term indices as ushort (16bit)
if (terms.Count > ushort.MaxValue)
throw new InvalidOperationException("Too many code terms for example: " + example.Value.replacedle);
var termDictExample = new Dictionary<string, List<ushort>>();
for (ushort i = 0; i < terms.Count; i++)
{
var term = terms[i];
if (termDictExample.ContainsKey(term))
{
termDictExample[term].Add(i);
}
else
{
termDictExample[term] = new List<ushort> { i };
}
}
var norm = Math.Sqrt(termDictExample.Sum(termDict => Sqr(termDict.Value.Count)));
foreach (var termDict in termDictExample)
{
var term = termDict.Key;
var list = termDict.Value;
if (_codeInvertedIndex.ContainsKey(term))
{
var ti = new TermInfo(example.Key, termDict.Value.ToArray(), (float) (termDict.Value.Count / norm));
_codeInvertedIndex[term].TermInfos.Add(ti);
}
else
{
var ti = new TermInfo(example.Key, termDict.Value.ToArray(), (float)(termDict.Value.Count / norm));
_codeInvertedIndex[term] = new Posting(new List<TermInfo>
{
ti,
});
}
_codeInvertedIndex[term].InvertedDoreplacedentFrequency += 1;
}
}
_codeInvertedIndex.ForEachDo(x =>
{
x.Value.InvertedDoreplacedentFrequency = Math.Log(ex.Count/x.Value.InvertedDoreplacedentFrequency);
// Collapse memory of List<TermInfo>
x.Value.TermInfos = x.Value.TermInfos.ToList();
});
}
19
View Source File : PHashTable.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
private static uint GetNumBits(uint num)
{
return (uint)Math.Log(num, 2) + 1;
}
19
View Source File : SoftPlusKernel.cs
License : MIT License
Project Creator : adamtiger
License : MIT License
Project Creator : adamtiger
public static void SoftPlusLambda(IData data)
{
data.ApplyToAll(p =>
{
return Math.Log(1 + Math.Exp(p));
});
}
19
View Source File : TagCloudData.cs
License : MIT License
Project Creator : Adoxio
License : MIT License
Project Creator : Adoxio
protected virtual IEnumerable<TagCloudDataItem> replacedignWeights(int numberOfWeights, IEnumerable<TagCloudDataItem> items)
{
// The call to Max on the next line will fail if there are no items,
// so return if the collection is empty
if (items.Count() == 0) return items;
// Find the highest count in our collection--items with this count will have
// the max weight (i.e., the value of the "weights" param)
var maxFrequency = items.Max(item => item.TaggedItemCount);
// Find the lowest count in our collection--items with this count will have a
// weight of 1
var minFrequency = items.Min(item => item.TaggedItemCount);
// The size of each frequency threshold
var delta = (maxFrequency - minFrequency) / (double)numberOfWeights;
return items.Select(item =>
{
for (var weight = 1; weight <= numberOfWeights; weight++)
{
// We add 2 to each threshold and adjustedFrequency, to cancel out the
// possibility of log(0) or log(1), which would have distorting effects
var threshold = 100 * Math.Log((minFrequency + weight * delta) + 2);
var adjustedFrequency = 100 * Math.Log(item.TaggedItemCount + 2);
if (adjustedFrequency <= threshold)
{
item.Weight = weight;
break;
}
}
return item;
});
}
19
View Source File : DynamicHierarchy.cs
License : The Unlicense
Project Creator : aeroson
License : The Unlicense
Project Creator : aeroson
protected override void UpdateMulreplacedhreaded()
{
lock (Locker)
{
Overlaps.Clear();
if (root != null)
{
//To mulreplacedhread the tree traversals, we have to do a little single threaded work.
//Dive down into the tree far enough that there are enough nodes to split amongst all the threads in the thread manager.
//The depth to which we dive is offset by some precomputed values (when available) or a guess based on whether or not the
//thread count is a power of 2. Thread counts which are a power of 2 match well to the binary tree, while other thread counts
//require going deeper for better distributions.
int offset = ParallelLooper.ThreadCount <= threadSplitOffsets.Length
? threadSplitOffsets[ParallelLooper.ThreadCount - 1]
: (ParallelLooper.ThreadCount & (ParallelLooper.ThreadCount - 1)) == 0 ? 0 : 2;
int splitDepth = offset + (int)Math.Ceiling(Math.Log(ParallelLooper.ThreadCount, 2));
#if PROFILE
startRefit = Stopwatch.GetTimestamp();
#endif
MulreplacedhreadedRefitPhase(splitDepth);
#if PROFILE
endRefit = Stopwatch.GetTimestamp();
#endif
MulreplacedhreadedOverlapPhase(splitDepth);
#if PROFILE
endOverlap = Stopwatch.GetTimestamp();
#endif
}
}
}
19
View Source File : DiscordApplication.cs
License : MIT License
Project Creator : Aiko-IT-Systems
License : MIT License
Project Creator : Aiko-IT-Systems
public string GetAvatarUrl(ImageFormat fmt, ushort size = 1024)
{
if (fmt == ImageFormat.Unknown)
throw new ArgumentException("You must specify valid image format.", nameof(fmt));
if (size < 16 || size > 2048)
throw new ArgumentOutOfRangeException(nameof(size));
var log = Math.Log(size, 2);
if (log < 4 || log > 11 || log % 1 != 0)
throw new ArgumentOutOfRangeException(nameof(size));
var sfmt = "";
sfmt = fmt switch
{
ImageFormat.Gif => "gif",
ImageFormat.Jpeg => "jpg",
ImageFormat.Auto or ImageFormat.Png => "png",
ImageFormat.WebP => "webp",
_ => throw new ArgumentOutOfRangeException(nameof(fmt)),
};
19
View Source File : DiscordUser.cs
License : MIT License
Project Creator : Aiko-IT-Systems
License : MIT License
Project Creator : Aiko-IT-Systems
public string GetAvatarUrl(ImageFormat fmt, ushort size = 1024)
{
if (fmt == ImageFormat.Unknown)
throw new ArgumentException("You must specify valid image format.", nameof(fmt));
if (size < 16 || size > 2048)
throw new ArgumentOutOfRangeException(nameof(size));
var log = Math.Log(size, 2);
if (log < 4 || log > 11 || log % 1 != 0)
throw new ArgumentOutOfRangeException(nameof(size));
var sfmt = "";
sfmt = fmt switch
{
ImageFormat.Gif => "gif",
ImageFormat.Jpeg => "jpg",
ImageFormat.Png => "png",
ImageFormat.WebP => "webp",
ImageFormat.Auto => !string.IsNullOrWhiteSpace(this.AvatarHash) ? (this.AvatarHash.StartsWith("a_") ? "gif" : "png") : "png",
_ => throw new ArgumentOutOfRangeException(nameof(fmt)),
};
19
View Source File : Era.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public static Era Create(uint lifeTime, ulong finalizedHeaderBlockNumber)
{
if (lifeTime == 0)
{
return new Era(0, 0, true);
}
// NODE: { "IsImmortal":false,"Period":64,"Phase":49}
// API: { "IsImmortal":false,"Period":64,"Phase":61}
// RUST Implementation
//let period = period.checked_next_power_of_two()
// .unwrap_or(1 << 16)
// .max(4)
// .min(1 << 16);
//let phase = current % period;
//let quantize_factor = (period >> 12).max(1);
//let quantized_phase = phase / quantize_factor * quantize_factor;
//Era::Mortal(period, quantized_phase)
ulong period = (ulong)Math.Pow(2, Math.Round(Math.Log(lifeTime, 2)));
period = Math.Max(period, 4);
period = Math.Min(period, 65536);
ulong phase = finalizedHeaderBlockNumber % period;
var quantize_factor = Math.Max(period >> 12, 1);
var quantized_phase = phase / quantize_factor * quantize_factor;
return new Era(period, quantized_phase, false);
}
19
View Source File : Program.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
private static void EraTesting()
{
var t1 = Era.Decode(Utils.HexToByteArray("0x1503"));
Console.WriteLine($"NODE: {t1}");
var t2 = Era.Decode(Utils.HexToByteArray("0xD503"));
Console.WriteLine($" API: {t2}");
var t3 = Era.Create(64, 15793);
Console.WriteLine($" API: {t3}");
ulong currentBlockNumber = (ulong)15689;
var lastBit = currentBlockNumber & (ulong)-(long)currentBlockNumber;
var nextPowerOf2 = Math.Pow(2, Math.Round(Math.Log(15689, 2)));
Console.WriteLine($"currentBlockNumber[{currentBlockNumber}]: {Math.Round(Math.Log(15689, 2))} {nextPowerOf2}");
}
19
View Source File : Era.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public byte[] Encode()
{
if (IsImmortal)
{
return new byte[] { 0x00 };
}
var quantizeFactor = Math.Max(1, Period / 4096);
var lastBit = Period & (ulong)-(long)Period;
//var rest = _period;
//var lastBit = 1;
//while (rest % 2 == 0 && rest != 0)
//{
// rest /= 2;
// lastBit *= 2;
//}
var logOf2 = lastBit != 0 ? Math.Log(lastBit, 2) : 64;
var low = (ushort)Math.Min(15, Math.Max(1, logOf2 - 1));
var high = (ushort)(Phase / quantizeFactor << 4);
var encoded = (ushort)(low | high);
return BitConverter.GetBytes(encoded);
}
19
View Source File : UnitsCalculator.cs
License : MIT License
Project Creator : alaabenfatma
License : MIT License
Project Creator : alaabenfatma
public static string SizeCalc(long byteCount)
{
string[] suf = {"B", "KB", "MB", "GB", "TB", "PB", "EB"};
if (byteCount == 0)
return "0" + suf[0];
var bytes = Math.Abs(byteCount);
var place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
var num = Math.Round(bytes / Math.Pow(1024, place), 1);
return Math.Sign(byteCount) * num + suf[place];
}
19
View Source File : TileCover.cs
License : MIT License
Project Creator : alen-smajic
License : MIT License
Project Creator : alen-smajic
public static UnwrappedTileId CoordinateToTileId(Vector2d coord, int zoom)
{
var lat = coord.x;
var lng = coord.y;
// See: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
var x = (int)Math.Floor((lng + 180.0) / 360.0 * Math.Pow(2.0, zoom));
var y = (int)Math.Floor((1.0 - Math.Log(Math.Tan(lat * Math.PI / 180.0)
+ 1.0 / Math.Cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * Math.Pow(2.0, zoom));
return new UnwrappedTileId(zoom, x, y);
}
19
View Source File : FileAttachmentControlViewModel.cs
License : GNU General Public License v3.0
Project Creator : alexdillon
License : GNU General Public License v3.0
Project Creator : alexdillon
private static string BytesToString(long byteCount)
{
string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; // Longs run out around EB
if (byteCount == 0)
{
return "0" + suf[0];
}
long bytes = Math.Abs(byteCount);
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
return (Math.Sign(byteCount) * num).ToString() + " " + suf[place];
}
19
View Source File : RangeAxis.cs
License : MIT License
Project Creator : AlexGyver
License : MIT License
Project Creator : AlexGyver
private double CalculateActualInterval2(double availableSize, double maxIntervalSize)
{
Func<double, double> Exponent = x => Math.Ceiling(Math.Log(x, 10));
Func<double, double> Mantissa = x => x / Math.Pow(10, Exponent(x) - 1);
// reduce intervals for horizontal axis.
// double maxIntervals = Orientation == AxisOrientation.X ? MaximumAxisIntervalsPer200Pixels * 0.8 : MaximumAxisIntervalsPer200Pixels;
// real maximum interval count
double maxIntervalCount = availableSize / maxIntervalSize;
double range = Math.Abs(ActualMinimum - ActualMaximum);
double interval = Math.Pow(10, Exponent(range));
double tempInterval = interval;
// decrease interval until interval count becomes less than maxIntervalCount
while (true)
{
int mantissa = (int)Mantissa(tempInterval);
if (mantissa == 5)
{
// reduce 5 to 2
tempInterval = RemoveNoiseFromDoubleMath(tempInterval / 2.5);
}
else if (mantissa == 2 || mantissa == 1 || mantissa == 10)
{
// reduce 2 to 1,10 to 5,1 to 0.5
tempInterval = RemoveNoiseFromDoubleMath(tempInterval / 2.0);
}
if (range / tempInterval > maxIntervalCount)
{
break;
}
interval = tempInterval;
}
return interval;
}
19
View Source File : DoubleExtensions.cs
License : MIT License
Project Creator : AlexGyver
License : MIT License
Project Creator : AlexGyver
public static double GetExponent(this double x)
{
return Math.Round(Math.Log(Math.Abs(x), 10));
}
19
View Source File : Renderer.cs
License : MIT License
Project Creator : AliFlux
License : MIT License
Project Creator : AliFlux
public async static Task<BitmapSource> Render(Style style, ICanvas canvas, int x, int y, double zoom, double sizeX = 512, double sizeY = 512, double scale = 1, List<string> whiteListLayers = null)
{
Dictionary<Source, Stream> rasterTileCache = new Dictionary<Source, Stream>();
Dictionary<Source, VectorTile> vectorTileCache = new Dictionary<Source, VectorTile>();
Dictionary<string, List<VectorTileLayer>> categorizedVectorLayers = new Dictionary<string, List<VectorTileLayer>>();
double actualZoom = zoom;
if (sizeX < 1024)
{
var ratio = 1024 / sizeX;
var zoomDelta = Math.Log(ratio, 2);
actualZoom = zoom - zoomDelta;
}
sizeX *= scale;
sizeY *= scale;
canvas.StartDrawing(sizeX, sizeY);
var visualLayers = new List<VisualLayer>();
// TODO refactor this messy block
foreach (var layer in style.Layers)
{
if (whiteListLayers != null && layer.Type != "background" && layer.SourceLayer != "")
{
if (!whiteListLayers.Contains(layer.SourceLayer))
{
continue;
}
}
if (layer.Source != null)
{
if (layer.Source.Type == "vector")
{
if (!vectorTileCache.ContainsKey(layer.Source))
{
if (layer.Source.Provider is Sources.IVectorTileSource)
{
var tile = await (layer.Source.Provider as Sources.IVectorTileSource).GetVectorTile(x, y, (int)zoom);
if (tile == null)
{
return null;
// throwing exceptions screws up the performance
throw new FileNotFoundException("Could not load tile : " + x + "," + y + "," + zoom + " of " + layer.SourceName);
}
// magic sauce! :p
if (tile.IsOverZoomed)
{
canvas.ClipOverflow = true;
}
//canvas.ClipOverflow = true;
vectorTileCache[layer.Source] = tile;
// normalize the points from 0 to size
foreach (var vectorLayer in tile.Layers)
{
foreach (var feature in vectorLayer.Features)
{
foreach (var geometry in feature.Geometry)
{
for (int i = 0; i < geometry.Count; i++)
{
var point = geometry[i];
geometry[i] = new Point(point.X / feature.Extent * sizeX, point.Y / feature.Extent * sizeY);
}
}
}
}
foreach (var tileLayer in tile.Layers)
{
if (!categorizedVectorLayers.ContainsKey(tileLayer.Name))
{
categorizedVectorLayers[tileLayer.Name] = new List<VectorTileLayer>();
}
categorizedVectorLayers[tileLayer.Name].Add(tileLayer);
}
}
}
}
else if (layer.Source.Type == "raster")
{
if (!rasterTileCache.ContainsKey(layer.Source))
{
if (layer.Source.Provider != null)
{
if (layer.Source.Provider is Sources.ITileSource)
{
var tile = await (layer.Source.Provider as Sources.ITileSource).GetTile(x, y, (int)zoom);
if (tile == null)
{
continue;
// throwing exceptions screws up the performance
throw new FileNotFoundException("Could not load tile : " + x + "," + y + "," + zoom + " of " + layer.SourceName);
}
rasterTileCache[layer.Source] = tile;
}
}
}
if (rasterTileCache.ContainsKey(layer.Source))
{
if (style.ValidateLayer(layer, (int)zoom, null))
{
var brush = style.ParseStyle(layer, scale, new Dictionary<string, object>());
if (!brush.Paint.Visibility)
{
continue;
}
visualLayers.Add(new VisualLayer()
{
Type = VisualLayerType.Raster,
RasterStream = rasterTileCache[layer.Source],
Brush = brush,
});
}
}
}
if (categorizedVectorLayers.ContainsKey(layer.SourceLayer))
{
var tileLayers = categorizedVectorLayers[layer.SourceLayer];
foreach (var tileLayer in tileLayers)
{
foreach (var feature in tileLayer.Features)
{
//var geometry = localizeGeometry(feature.Geometry, sizeX, sizeY, feature.Extent);
var attributes = new Dictionary<string, object>(feature.Attributes);
attributes["$type"] = feature.GeometryType;
attributes["$id"] = layer.ID;
attributes["$zoom"] = actualZoom;
//if ((string)attributes["$type"] == "Point")
//{
// if (attributes.ContainsKey("clreplaced"))
// {
// if ((string)attributes["clreplaced"] == "country")
// {
// if (layer.ID == "country_label")
// {
// }
// }
// }
//}
if (style.ValidateLayer(layer, actualZoom, attributes))
{
var brush = style.ParseStyle(layer, scale, attributes);
if (!brush.Paint.Visibility)
{
continue;
}
visualLayers.Add(new VisualLayer()
{
Type = VisualLayerType.Vector,
VectorTileFeature = feature,
Geometry = feature.Geometry,
Brush = brush,
});
}
}
}
}
}
else if (layer.Type == "background")
{
var brushes = style.GetStyleByType("background", actualZoom, scale);
foreach (var brush in brushes)
{
canvas.DrawBackground(brush);
}
}
}
// defered rendering to preserve text drawing order
foreach (var layer in visualLayers.OrderBy(item => item.Brush.ZIndex))
{
if (layer.Type == VisualLayerType.Vector)
{
var feature = layer.VectorTileFeature;
var geometry = layer.Geometry;
var brush = layer.Brush;
var attributesDict = feature.Attributes.ToDictionary(key => key.Key, value => value.Value);
if (!brush.Paint.Visibility)
{
continue;
}
try
{
if (feature.GeometryType == "Point")
{
foreach (var point in geometry)
{
canvas.DrawPoint(point.First(), brush);
}
}
else if (feature.GeometryType == "LineString")
{
foreach (var line in geometry)
{
canvas.DrawLineString(line, brush);
}
}
else if (feature.GeometryType == "Polygon")
{
foreach (var polygon in geometry)
{
canvas.DrawPolygon(polygon, brush);
}
}
else if (feature.GeometryType == "Unknown")
{
canvas.DrawUnknown(geometry, brush);
} else
{
}
}
catch (Exception)
{
}
}
else if (layer.Type == VisualLayerType.Raster)
{
canvas.DrawImage(layer.RasterStream, layer.Brush);
layer.RasterStream.Close();
}
}
foreach (var layer in visualLayers.OrderBy(item => item.Brush.ZIndex).Reverse())
{
if (layer.Type == VisualLayerType.Vector)
{
var feature = layer.VectorTileFeature;
var geometry = layer.Geometry;
var brush = layer.Brush;
var attributesDict = feature.Attributes.ToDictionary(key => key.Key, value => value.Value);
if (!brush.Paint.Visibility)
{
continue;
}
if (feature.GeometryType == "Point")
{
foreach (var point in geometry)
{
if (brush.Text != null)
{
canvas.DrawText(point.First(), brush);
}
}
}
else if (feature.GeometryType == "LineString")
{
foreach (var line in geometry)
{
if (brush.Text != null)
{
canvas.DrawTextOnPath(line, brush);
}
}
}
}
}
return canvas.FinishDrawing();
}
19
View Source File : HyperbolicCoordinatesPostProcessorSystem.cs
License : MIT License
Project Creator : allenwp
License : MIT License
Project Creator : allenwp
public static void PostProcess(List<Sample3D[]> samples3D, PostProcessor3D postProcessor)
{
HyperbolicCoordinatesPostProcessor hyperbolicPP = postProcessor as HyperbolicCoordinatesPostProcessor;
var origin = hyperbolicPP.Origin.Position;
var zScale = hyperbolicPP.ZScale;
var rangeParreplacedioner = Parreplacedioner.Create(samples3D);
Parallel.ForEach(rangeParreplacedioner, samples3DArray =>
{
for (int i = 0; i < samples3DArray.Length; i++)
{
var newPosition = samples3DArray[i].Position - origin;
newPosition.Z *= zScale;
// https://stackoverflow.com/questions/23744120/conversion-from-rectangular-to-hyperbolic-coordinates-not-reversible
newPosition = new Vector3(newPosition.X, (float)Math.Sqrt(newPosition.Z * newPosition.Y), (float)Math.Log(newPosition.Y / newPosition.Z));
newPosition += origin;
samples3DArray[i].Position = newPosition;
}
});
}
19
View Source File : OceanRenderer.cs
License : MIT License
Project Creator : AlphaMistral
License : MIT License
Project Creator : AlphaMistral
private void GenerateTexture()
{
float deltaTime = Time.deltaTime;
currentPhase = !currentPhase;
RenderTexture rt = currentPhase ? pingPhaseTexture : pongPhaseTexture;
dispersionMat.SetTexture("_Phase", currentPhase? pongPhaseTexture : pingPhaseTexture);
dispersionMat.SetFloat("_DeltaTime", deltaTime * mult);
Graphics.Blit(null, rt, dispersionMat);
spectrumMat.SetTexture("_Phase", currentPhase? pingPhaseTexture : pongPhaseTexture);
Graphics.Blit(null, spectrumTexture, spectrumMat);
fftMat.EnableKeyword("_HORIZONTAL");
fftMat.DisableKeyword("_VERTICAL");
int iterations = Mathf.CeilToInt((float)Math.Log(resolution * 8, 2)) * 2;
for (int i = 0; i < iterations; i++)
{
RenderTexture blitTarget;
fftMat.SetFloat("_SubTransformSize", Mathf.Pow(2, (i % (iterations / 2)) + 1));
if (i == 0)
{
fftMat.SetTexture("_Input", spectrumTexture);
blitTarget = pingTransformTexture;
}
else if (i == iterations - 1)
{
fftMat.SetTexture("_Input", (iterations % 2 == 0) ? pingTransformTexture : pongTransformTexture);
blitTarget = displacementTexture;
}
else if (i % 2 == 1)
{
fftMat.SetTexture("_Input", pingTransformTexture);
blitTarget = pongTransformTexture;
}
else
{
fftMat.SetTexture("_Input", pongTransformTexture);
blitTarget = pingTransformTexture;
}
if (i == iterations / 2)
{
fftMat.DisableKeyword("_HORIZONTAL");
fftMat.EnableKeyword("_VERTICAL");
}
Graphics.Blit(null, blitTarget, fftMat);
}
heightMat.SetTexture("_Phase", currentPhase? pingPhaseTexture : pongPhaseTexture);
Graphics.Blit(null, spectrumTexture, heightMat);
fftMat.EnableKeyword("_HORIZONTAL");
fftMat.DisableKeyword("_VERTICAL");
for (int i = 0; i < iterations; i++)
{
RenderTexture blitTarget;
fftMat.SetFloat("_SubTransformSize", Mathf.Pow(2, (i % (iterations / 2)) + 1));
if (i == 0)
{
fftMat.SetTexture("_Input", spectrumTexture);
blitTarget = pingTransformTexture;
}
else if (i == iterations - 1)
{
fftMat.SetTexture("_Input", (iterations % 2 == 0) ? pingTransformTexture : pongTransformTexture);
blitTarget = heightTexture;
}
else if (i % 2 == 1)
{
fftMat.SetTexture("_Input", pingTransformTexture);
blitTarget = pongTransformTexture;
}
else
{
fftMat.SetTexture("_Input", pongTransformTexture);
blitTarget = pingTransformTexture;
}
if (i == iterations / 2)
{
fftMat.DisableKeyword("_HORIZONTAL");
fftMat.EnableKeyword("_VERTICAL");
}
Graphics.Blit(null, blitTarget, fftMat);
}
normalMat.SetTexture("_DisplacementMap", displacementTexture);
normalMat.SetTexture("_HeightMap", heightTexture);
Graphics.Blit(null, normalTexture, normalMat);
whiteMat.SetTexture("_Displacement", displacementTexture);
whiteMat.SetTexture("_Bump", normalTexture);
whiteMat.SetFloat("_Resolution", resolution * 8);
whiteMat.SetFloat("_Length", resolution);
Graphics.Blit(null, whiteTexture, whiteMat);
if (!saved)
{
oceanMat.SetTexture("_Anim", displacementTexture);
oceanMat.SetTexture("_Bump", normalTexture);
oceanMat.SetTexture("_White", whiteTexture);
oceanMat.SetTexture("_Height", heightTexture);
saved = true;
}
}
19
View Source File : DoubleExtension.cs
License : MIT License
Project Creator : AlphaYu
License : MIT License
Project Creator : AlphaYu
public static double Log(this double d, double newBase)
{
return Math.Log(d, newBase);
}
19
View Source File : DownloadUpdateDialog.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
private static string BytesToString(long byteCount)
{
string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
if (byteCount == 0)
{
return "0" + suf[0];
}
long bytes = Math.Abs(byteCount);
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
return $"{(Math.Sign(byteCount) * num).ToString(CultureInfo.InvariantCulture)} {suf[place]}";
}
19
View Source File : ExponentialDistribution.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public double Quantile(Probability p) => - Log(1 - p) / Rate;
19
View Source File : FrechetDistribution.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public double Quantile(Probability p)
{
return p.Value switch
{
0 => double.Epsilon,
1 => double.PositiveInfinity,
_ => M + S * Pow(-Log(p), -1 / A)
};
19
View Source File : GumbelDistribution.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public double Quantile(Probability p)
{
return p.Value switch
{
0 => double.NegativeInfinity,
1 => double.PositiveInfinity,
_ => M - S * Log(-Log(p))
};
19
View Source File : LaplaceDistribution.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public double Quantile(Probability p) => p < Probability.Half
? Mu + Sigma * Log(2 * p)
: Mu - Sigma * Log(2 - 2 * p);
19
View Source File : StudentDistribution.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public double Pdf(double x)
{
double df2 = (df + 1) / 2;
// Ln( Г((df + 1) / 2) / Г(df / 2) )
double term1 = GammaFunction.LogValue(df2) - GammaFunction.LogValue(df / 2);
// Ln( (1 + x^2 / df) ^ (-(df + 1) / 2) )
double term2 = Log(1 + x.Sqr() / df) * -df2;
return Exp(term1 + term2) / Sqrt(PI * df);
}
19
View Source File : WeibullDistribution.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public double Quantile(Probability p)
{
return p.Value switch
{
0 => 0,
1 => double.PositiveInfinity,
_ => Lambda * Pow(-Log(1 - p), 1 / K)
};
19
View Source File : BinomialDistribution.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public double Pmf(int k)
{
if (k < 0 || k > N)
return 0;
return Math.Exp(
BinomialCoefficientHelper.GetLogBinomialCoefficient(N, k) +
k * Math.Log(P) +
(N - k) * Math.Log(1 - P)
);
}
19
View Source File : BetaFunction.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public static double IncompleteLogValue(double a, double b, double x)
{
return a * Log(x) - Log(a) + Log(HypergeometricFunction.Value(a, 1 - b, a + 1, x, (int) Round(b)));
}
19
View Source File : HistogramBinSizeCalculator.cs
License : MIT License
Project Creator : AndreyAkinshin
License : MIT License
Project Creator : AndreyAkinshin
public static double CalcSturges(int n, double min, double max)
{
return (max - min) / (Math.Ceiling(Math.Log(n, 2)) + 1);
}
19
View Source File : IdGen.Static.cs
License : MIT License
Project Creator : anet-team
License : MIT License
Project Creator : anet-team
private static int GetBitsLength(long number)
{
return (int)Math.Log(number, 2) + 1;
}
19
View Source File : AxisLabels.cs
License : MIT License
Project Creator : AngeloCresta
License : MIT License
Project Creator : AngeloCresta
internal void FillLabels(bool removeFirstRow)
{
#if SUBAXES
// Process all sub-axis
foreach(SubAxis subAxis in ((Axis)this).SubAxes)
{
subAxis.FillLabels(true);
}
#endif // SUBAXES
// Labels are disabled for this axis
if( !this.LabelStyle.Enabled || !this.enabled )
{
return;
}
// For circular chart area fill only Y axis labels
if(this.ChartArea != null && this.ChartArea.chartAreaIsCurcular)
{
if(this.axisType != AxisName.Y)
{
ICircularChartType type = this.ChartArea.GetCircularChartType();
if(type == null || !type.XAxisLabelsSupported())
{
return;
}
}
}
// Check if the custom labels exist
bool customLabelsFlag = false;
foreach( CustomLabel lab in CustomLabels )
{
if( lab.customLabel )
{
if( lab.RowIndex == 0 ||
this.ChartArea.chartAreaIsCurcular)
{
customLabelsFlag = true;
}
}
}
// Remove the first row of labels if custom labels not exist
if(removeFirstRow)
{
if( customLabelsFlag == false )
{
for( int index = 0; index < CustomLabels.Count; index++ )
{
if( CustomLabels[index].RowIndex == 0 )
{
CustomLabels.RemoveAt( index );
index = -1;
}
}
}
else
{
return;
}
}
// Get data series for this axis.
List<string> dataSeries = null;
switch( axisType )
{
case AxisName.X:
dataSeries = ChartArea.GetXAxesSeries( AxisType.Primary, ((Axis)this).SubAxisName );
break;
case AxisName.Y:
dataSeries = ChartArea.GetYAxesSeries( AxisType.Primary, ((Axis)this).SubAxisName );
break;
case AxisName.X2:
dataSeries = ChartArea.GetXAxesSeries( AxisType.Secondary, ((Axis)this).SubAxisName );
break;
case AxisName.Y2:
dataSeries = ChartArea.GetYAxesSeries( AxisType.Secondary, ((Axis)this).SubAxisName );
break;
}
// There aren't data series connected with this axis.
if( dataSeries.Count == 0 )
{
return;
}
//Let's convert the ArrayList of the series names into to string[]
string[] dataSeriesNames = new string[dataSeries.Count];
for (int i = 0; i < dataSeries.Count; i++)
dataSeriesNames[i] = (string)dataSeries[i];
// Check if series X values all set to zeros
bool seriesXValuesZeros = ChartHelper.SeriesXValuesZeros(this.Common, dataSeriesNames);
// Check if series is indexed (All X values zeros or IsXValueIndexed flag set)
bool indexedSeries = true;
if (!seriesXValuesZeros)
{
indexedSeries = ChartHelper.IndexedSeries(this.Common, dataSeriesNames);
}
// Show End Labels
int endLabels = 0;
if( labelStyle.IsEndLabelVisible )
{
endLabels = 1;
}
// Get chart type of the first series
IChartType chartType = Common.ChartTypeRegistry.GetChartType( ChartArea.GetFirstSeries().ChartTypeName );
bool fromSeries = false;
if( !chartType.RequireAxes )
{
return;
}
else if( axisType == AxisName.Y || axisType == AxisName.Y2 )
{
fromSeries = false;
}
else
{
fromSeries = true;
}
// X values from data points are not 0.
if (fromSeries && !ChartHelper.SeriesXValuesZeros(this.Common, dataSeries.ToArray()))
{
fromSeries = false;
}
// X values from data points are not 0.
if( fromSeries && ( labelStyle.GetIntervalOffset() != 0 || labelStyle.GetInterval() != 0 ) )
{
fromSeries = false;
}
// Get value type
ChartValueType valueType;
if( axisType == AxisName.X || axisType == AxisName.X2 )
{
// If X value is indexed the type is always String. So we use indexed type instead
valueType = Common.DataManager.Series[dataSeries[0]].indexedXValueType;
}
else
{
valueType = Common.DataManager.Series[dataSeries[0]].YValueType;
}
if( labelStyle.GetIntervalType() != DateTimeIntervalType.Auto &&
labelStyle.GetIntervalType() != DateTimeIntervalType.Number )
{
if (valueType != ChartValueType.Time &&
valueType != ChartValueType.Date &&
valueType != ChartValueType.DateTimeOffset)
{
valueType = ChartValueType.DateTime;
}
}
// ***********************************
// Pre calculate some values
// ***********************************
double viewMaximum = this.ViewMaximum;
double viewMinimum = this.ViewMinimum;
// ***********************************
// Labels are filled from data series.
// ***********************************
if( fromSeries )
{
int numOfPoints;
numOfPoints = Common.DataManager.GetNumberOfPoints( dataSeries.ToArray() );
// Show end labels
if( endLabels == 1 )
{
// min position
CustomLabels.Add( - 0.5, 0.5, ValueConverter.FormatValue(
this.Common.Chart,
this,
null,
0.0,
this.LabelStyle.Format,
valueType,
ChartElementType.AxisLabels),
false);
}
// Labels from point position
for( int point = 0; point < numOfPoints; point++ )
{
CustomLabels.Add( ((double)point)+ 0.5, ((double)point)+ 1.5,
ValueConverter.FormatValue(
this.Common.Chart,
this,
null,
point + 1,
this.LabelStyle.Format,
valueType,
ChartElementType.AxisLabels),
false);
}
// Show end labels
if( endLabels == 1 )
{
// max position
CustomLabels.Add( ((double)numOfPoints)+ 0.5, ((double)numOfPoints)+ 1.5,
ValueConverter.FormatValue(
this.Common.Chart,
this,
null,
numOfPoints + 1,
this.LabelStyle.Format,
valueType,
ChartElementType.AxisLabels),
false);
}
int pointIndx;
foreach( string seriesIndx in dataSeries )
{
// End labels enabled
if( endLabels == 1 )
pointIndx = 1;
else
pointIndx = 0;
// Set labels from data points labels
foreach( DataPoint dataPoint in Common.DataManager.Series[ seriesIndx ].Points )
{
// Find first row of labels
while( CustomLabels[pointIndx].RowIndex > 0 )
{
pointIndx++;
}
// Add X labels
if( axisType == AxisName.X || axisType == AxisName.X2 )
{
if( dataPoint.AxisLabel.Length > 0 )
{
CustomLabels[pointIndx].Text = dataPoint.AxisLabel;
}
}
pointIndx++;
}
}
}
// ***********************************
// Labels are filled from axis scale.
// ***********************************
else
{
if( viewMinimum == viewMaximum )
return;
double labValue; // Value, which will be converted to text and used for, labels.
double beginPosition; // Begin position for a label
double endPosition; // End position for a label
double start; // Start position for all labels
// Get first series attached to this axis
Series axisSeries = null;
if(axisType == AxisName.X || axisType == AxisName.X2)
{
List<string> seriesArray = ChartArea.GetXAxesSeries((axisType == AxisName.X) ? AxisType.Primary : AxisType.Secondary, ((Axis)this).SubAxisName);
if(seriesArray.Count > 0)
{
axisSeries = Common.DataManager.Series[seriesArray[0]];
if(axisSeries != null && !axisSeries.IsXValueIndexed)
{
axisSeries = null;
}
}
}
// ***********************************
// Check if the AJAX zooming and scrolling mode is enabled.
// Labels are filled slightly different in this case.
// ***********************************
DateTimeIntervalType offsetType = (labelStyle.GetIntervalOffsetType() == DateTimeIntervalType.Auto) ? labelStyle.GetIntervalType() : labelStyle.GetIntervalOffsetType();
// By default start is equal to minimum
start = viewMinimum;
// Adjust start position depending on the interval type
if(!this.ChartArea.chartAreaIsCurcular ||
this.axisType == AxisName.Y ||
this.axisType == AxisName.Y2 )
{
start = ChartHelper.AlignIntervalStart(start, labelStyle.GetInterval(), labelStyle.GetIntervalType(), axisSeries);
}
// Move start if there is start position
if( labelStyle.GetIntervalOffset() != 0 && axisSeries == null)
{
start += ChartHelper.GetIntervalSize(start, labelStyle.GetIntervalOffset(),
offsetType, axisSeries, 0, DateTimeIntervalType.Number, true, false);
}
// ***************************************
// Date type
// ***************************************
if( valueType == ChartValueType.DateTime ||
valueType == ChartValueType.Date ||
valueType == ChartValueType.Time ||
valueType == ChartValueType.DateTimeOffset ||
axisSeries != null)
{
double position = start;
double dateInterval;
// Too many labels
if ((viewMaximum - start) / ChartHelper.GetIntervalSize(start, labelStyle.GetInterval(), labelStyle.GetIntervalType(), axisSeries, 0, DateTimeIntervalType.Number, true) > ChartHelper.MaxNumOfGridlines)
return;
int counter = 0;
double endLabelMaxPosition = viewMaximum - ChartHelper.GetIntervalSize(viewMaximum, labelStyle.GetInterval(), labelStyle.GetIntervalType(), axisSeries, labelStyle.GetIntervalOffset(), offsetType, true) / 2f;
double endLabelMinPosition = viewMinimum + ChartHelper.GetIntervalSize(viewMinimum, labelStyle.GetInterval(), labelStyle.GetIntervalType(), axisSeries, labelStyle.GetIntervalOffset(), offsetType, true) / 2f;
while( (decimal)position <= (decimal)viewMaximum )
{
dateInterval = ChartHelper.GetIntervalSize(position, labelStyle.GetInterval(), labelStyle.GetIntervalType(), axisSeries, labelStyle.GetIntervalOffset(), offsetType, true);
labValue = position;
// For IsLogarithmic axes
if( this.IsLogarithmic )
{
labValue = Math.Pow( this.logarithmBase, labValue );
}
// Check if we do not exceed max number of elements
if (counter++ > ChartHelper.MaxNumOfGridlines)
{
break;
}
if (endLabels == 0 && position >= endLabelMaxPosition)
{
break;
}
beginPosition = position - dateInterval * 0.5;
endPosition = position + dateInterval * 0.5;
if(endLabels == 0 && position <= endLabelMinPosition)
{
position += dateInterval;
continue;
}
if( (decimal)beginPosition > (decimal)viewMaximum )
{
position += dateInterval;
continue;
}
// NOTE: Fixes issue #6466
// Following code is removed due to the issues caused by the rounding error
//if( (((decimal)beginPosition + (decimal)endPosition) / 2.0m) < (decimal)viewMinimum )
//{
// position += dateInterval;
// continue;
//}
//if ((decimal)viewMaximum < (((decimal)beginPosition + (decimal)endPosition) / 2m))
//{
// position += dateInterval;
// continue;
//}
string pointLabel = GetPointLabel( dataSeries, labValue, !seriesXValuesZeros, indexedSeries );
if( pointLabel.Length == 0 )
{
// Do not draw last label for indexed series
if( position <= this.maximum )
{
// Add a label to the collection
if( position != this.maximum || !Common.DataManager.Series[ dataSeries[0] ].IsXValueIndexed )
{
CustomLabels.Add( beginPosition,
endPosition,
ValueConverter.FormatValue(
this.Common.Chart,
this,
null,
labValue,
this.LabelStyle.Format,
valueType,
ChartElementType.AxisLabels),
false);
}
}
}
else
{
// Add a label to the collection
CustomLabels.Add( beginPosition,
endPosition,
pointLabel,
false);
}
position += dateInterval;
}
}
else
{
// ***************************************
// Scale value type
// ***************************************
// Show First label if Start Label position is used
if( start != viewMinimum )
endLabels = 1;
// Set labels
int labelCounter = 0;
for (double position = start - endLabels * labelStyle.GetInterval(); position < viewMaximum - 1.5 * labelStyle.GetInterval() * (1 - endLabels); position = (double)((decimal)position + (decimal)labelStyle.GetInterval()))
{
// Prevent endless loop that may be caused by very small interval
// and double/decimal rounding errors
++labelCounter;
if(labelCounter > ChartHelper.MaxNumOfGridlines)
{
break;
}
labValue = (double)((decimal)position + (decimal)labelStyle.GetInterval());
// This line is introduce because sometimes 0 value will appear as
// very small value close to zero.
double inter = Math.Log(labelStyle.GetInterval());
double valu = Math.Log(Math.Abs(labValue));
int digits = (int)Math.Abs(inter)+5;
if( digits > 15 )
{
digits = 15;
}
if( Math.Abs(inter) < Math.Abs(valu)-5 )
{
labValue = Math.Round(labValue,digits);
}
// Too many labels
if( ( viewMaximum - start ) / labelStyle.GetInterval() > ChartHelper.MaxNumOfGridlines )
{
return;
}
// For IsLogarithmic axes
if( this.IsLogarithmic )
labValue = Math.Pow( this.logarithmBase, labValue );
beginPosition = (double)((decimal)position + (decimal)labelStyle.GetInterval() * 0.5m);
endPosition = (double)((decimal)position + (decimal)labelStyle.GetInterval() * 1.5m);
if( (decimal)beginPosition > (decimal)viewMaximum )
{
continue;
}
// Show End label if Start Label position is used
// Use decimal type to solve rounding issues
if( (decimal)(( beginPosition + endPosition )/2.0) > (decimal)viewMaximum )
{
continue;
}
string pointLabel = GetPointLabel( dataSeries, labValue, !seriesXValuesZeros, indexedSeries );
if( pointLabel.Length > 15 && labValue < 0.000001)
{
labValue = 0.0;
}
if( pointLabel.Length == 0 )
{
// Do not draw last label for indexed series
if( !(Common.DataManager.Series[ dataSeries[0] ].IsXValueIndexed && position > this.maximum) )
{
// Add a label to the collection
CustomLabels.Add( beginPosition,
endPosition,
ValueConverter.FormatValue(
this.Common.Chart,
this,
null,
labValue,
this.LabelStyle.Format,
valueType,
ChartElementType.AxisLabels),
false);
}
}
else
{
// Add a label to the collection
CustomLabels.Add( beginPosition,
endPosition,
pointLabel,
false);
}
}
}
}
}
19
View Source File : FileSizeFormatConverter.cs
License : MIT License
Project Creator : AngryCarrot789
License : MIT License
Project Creator : AngryCarrot789
static string SizeSuffix(long value, int decimalPlaces = 3)
{
if (decimalPlaces < 0) return "No decimals";
if (value == 0) { return string.Format("{0:n" + decimalPlaces + "} bytes", 0); }
// mag is 0 for bytes, 1 for KB, 2, for MB, etc.
int mag = (int)Math.Log(value, 1024);
decimal adjustedSize = (decimal)value / (1L << (mag * 10));
if (Math.Round(adjustedSize, decimalPlaces) >= 1000)
{
mag += 1;
adjustedSize /= 1024;
}
return string.Format("{0:n" + decimalPlaces + "} {1}", adjustedSize, SizeSuffixes[mag]);
}
19
View Source File : Mathf.cs
License : MIT License
Project Creator : AnotherEnd15
License : MIT License
Project Creator : AnotherEnd15
public static float Log(float f, float p)
{
return (float) Math.Log((double) f, (double) p);
}
19
View Source File : AttributesUtilityWindow.cs
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
private void OnEnable()
{
_lastEntry = -1;
if (AttributesMaster.attributesEnabled)
{
var vals = Enum.GetValues(AttributesMaster.attributesEnumType);
var names = Enum.GetNames(AttributesMaster.attributesEnumType);
int idx = 0;
foreach (int v in vals)
{
var val = Math.Abs((long)v);
if (val > 0)
{
_lastEntry = (int)Math.Log(val, 2);
_entries[_lastEntry] = names[idx];
}
idx++;
}
_fileLocation = LocateAttributeFile();
}
}
19
View Source File : AttributesMaster.cs
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
public static void Refresh()
{
var markerAttribute = typeof(EnreplacedyAttributesEnumAttribute);
#if NETFX_CORE
var markerAttributeInf = markerAttribute.GetTypeInfo();
var defaultAttributeInf = typeof(DefaultEnreplacedyAttributesEnum).GetTypeInfo();
var asm = markerAttributeInf.replacedembly;
attributesEnumType = asm.DefinedTypes.Where(t => t.IsEnum && t.CustomAttributes.Any(a => a.AttributeType == markerAttribute) && t != defaultAttributeInf).FirstOrDefault().AsType();
#else
var asm = markerAttribute.replacedembly;
attributesEnumType = asm.GetTypes().Where(t => t.IsEnum && Attribute.IsDefined(t, markerAttribute) && t != typeof(DefaultEnreplacedyAttributesEnum)).FirstOrDefault();
#endif
if (attributesEnumType == null)
{
attributesEnabled = false;
highestOrderBit = 0;
attributesEnumType = typeof(DefaultEnreplacedyAttributesEnum);
}
else
{
var vals = Enum.GetValues(attributesEnumType);
highestOrderBit = (int)Math.Log((int)vals.GetValue(vals.Length - 1), 2);
attributesEnabled = true;
}
}
19
View Source File : CellCostManager.cs
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
private void SetCost(CellCostType t, int cost)
{
var idx = (int)Math.Log((int)t, 2) + 1;
_costs[idx] = cost;
}
19
View Source File : FractalHeapHeader.cs
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
private (FractalHeapIndirectBlock IndirectBlock, ulong entry) Locate(ulong offset)
{
var (row, column) = this.Lookup(offset);
this.Reader.Seek((long)this.RootBlockAddress, SeekOrigin.Begin);
var indirectBlock = new FractalHeapIndirectBlock(this, this.Reader, _superblock, this.RootIndirectBlockRowsCount);
uint entry;
while (row >= this.MaxDirectRows)
{
/* Compute # of rows in child indirect block */
var nrows = (uint)Math.Log(this.RowBlockSizes[row], 2) - this.FirstRowBits + 1;
if (nrows >= indirectBlock.RowCount)
throw new Exception("Child fractal heap block must be smaller than its parent.");
/* Compute indirect block's entry */
entry = row * this.TableWidth + column;
/* Locate child indirect block */
var indirectBlockEntry = indirectBlock.Entries[entry];
/* Use new indirect block */
this.Reader.Seek((long)indirectBlockEntry.Address, SeekOrigin.Begin);
indirectBlock = new FractalHeapIndirectBlock(this, this.Reader, _superblock, nrows);
/* Look up row & column in new indirect block for object */
(row, column) = this.Lookup(offset - indirectBlock.BlockOffset);
if (row >= indirectBlock.RowCount)
throw new Exception("Child fractal heap block must be smaller than its parent.");
}
entry = row * this.TableWidth + column;
return (indirectBlock, entry);
}
19
View Source File : FractalHeapHeader.cs
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
private (uint Row, uint Column) Lookup(ulong offset)
{
uint row;
uint column;
if (offset < this.StartingBlockSize * this.TableWidth)
{
row = 0;
column = (uint)(offset / this.StartingBlockSize);
}
else
{
var highBit = (uint)Math.Log(offset, 2);
ulong offMask = (ulong)(1 << (int)highBit);
row = highBit - this.FirstRowBits + 1;
column = (uint)((offset - offMask) / this.RowBlockSizes[row]);
}
return (row, column);
}
19
View Source File : FractalHeapHeader.cs
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
private void CalculateBlockSizeTables()
{
// from H5HFdtable.c
this.StartingBits = (uint)Math.Log(this.StartingBlockSize, 2);
this.FirstRowBits = (uint)(this.StartingBits + Math.Log(this.TableWidth, 2));
var maxDirectBits = (uint)Math.Log(this.MaximumDirectBlockSize, 2);
this.MaxDirectRows = maxDirectBits - this.StartingBits + 2;
var maxRootRows = this.MaximumHeapSize - this.FirstRowBits;
this.RowBlockSizes = new ulong[maxRootRows];
this.RowBlockOffsets = new ulong[maxRootRows];
var tmpBlockSize = this.StartingBlockSize;
var acreplacedulatedBlockOffset = this.StartingBlockSize * this.TableWidth;
this.RowBlockSizes[0] = tmpBlockSize;
this.RowBlockOffsets[0] = 0;
for (ulong i = 1; i < maxRootRows; i++)
{
this.RowBlockSizes[i] = tmpBlockSize;
this.RowBlockOffsets[i] = acreplacedulatedBlockOffset;
tmpBlockSize *= 2;
acreplacedulatedBlockOffset *= 2;
}
}
19
View Source File : ExtensibleArrayHeader.cs
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
public uint ComputeSecondaryBlockIndex(ulong index)
{
// H5EAdblock.c (H5EA__dblock_sblk_idx)
/* Adjust index for elements in index block */
index -= this.IndexBlockElementsCount;
/* Determine the superblock information for the index */
var tmp = index / this.DataBlockMininumElementsCount;
var secondaryBlockIndex = (uint)Math.Log(tmp + 1, 2);
return secondaryBlockIndex;
}
19
View Source File : ExtensibleArrayHeader.cs
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
private void Initialize()
{
// H5EA.hdr.c (H5EA__hdr_init)
/* Compute general information */
this.SecondaryBlockCount = 1UL +
this.ExtensibleArrayMaximumNumberOfElementsBits -
(uint)Math.Log(DataBlockMininumElementsCount, 2);
this.DataBlockPageElementsCount = 1UL << this.DataBlockPageMaximumNumberOfElementsBits;
this.ArrayOffsetsSize = (byte)((this.ExtensibleArrayMaximumNumberOfElementsBits + 7) / 8);
/* Allocate information for each super block */
this.SecondaryBlockInfos = new ExtensibleArraySecondaryBlockInformation[this.SecondaryBlockCount];
/* Compute information about each super block */
var elementStartIndex = 0UL;
var dataBlockStartIndex = 0UL;
for (ulong i = 0; i < this.SecondaryBlockCount; i++)
{
this.SecondaryBlockInfos[i].DataBlockCount = (ulong)(1 << ((int)i / 2));
this.SecondaryBlockInfos[i].ElementsCount = (ulong)(1 << (((int)i + 1) / 2)) * this.DataBlockMininumElementsCount;
this.SecondaryBlockInfos[i].ElementStartIndex = elementStartIndex;
this.SecondaryBlockInfos[i].DataBlockStartIndex = dataBlockStartIndex;
/* Advance starting indices for next super block */
elementStartIndex += this.SecondaryBlockInfos[i].DataBlockCount * this.SecondaryBlockInfos[i].ElementsCount;
dataBlockStartIndex += this.SecondaryBlockInfos[i].DataBlockCount;
}
}
19
View Source File : H5Utils.cs
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
License : GNU Lesser General Public License v3.0
Project Creator : Apollo3zehn
public static uint ComputeChunkSizeLength(ulong chunkSize)
{
// H5Dearray.c (H5D__earray_crt_context)
/* Compute the size required for encoding the size of a chunk, allowing
* for an extra byte, in case the filter makes the chunk larger.
*/
var chunkSizeLength = 1 + ((uint)Math.Log(chunkSize, 2) + 8) / 8;
if (chunkSizeLength > 8)
chunkSizeLength = 8;
return chunkSizeLength;
}
19
View Source File : Log.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 1);
var number = ArgToDecimal(arguments, 0);
if (arguments.Count() == 1)
{
return CreateResult(System.Math.Log(number, 10d), DataType.Decimal);
}
var newBase = ArgToDecimal(arguments, 1);
return CreateResult(System.Math.Log(number, newBase), DataType.Decimal);
}
19
View Source File : Ln.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
{
ValidateArguments(arguments, 1);
var arg = ArgToDecimal(arguments, 0);
return CreateResult(System.Math.Log(arg, System.Math.E), DataType.Decimal);
}
See More Examples