mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-12 11:32:33 +02:00
9c9540646c
* (Improvement) Cache per layer and global used material for faster calculations * (Improvement) Better internal PrintTime management * **(Improvement) GUI:** * Show per layer used material percentage compared to the rest model * Show total of millimeters cured per layer if available * Show bounds and ROI in millimeters if available * Show display width and height below resolution if available * Don't split (Actions / Refresh / Save) region when resize window and keep those fixed * **(Improvement) Calibrate - Grayscale:** * Add a option to convert brightness to exposure time on divisions text * Adjust text position to be better centered and near from the center within divisions * (Fix) Calculate the used material with global layer height instead of calculate height from layer difference which lead to wrong values in parallel computation * (Fix) Converting files were not setting the new file as parent for the layer manager, this affected auto convertions from SL1 and lead to crashes and bad calculations if file were not reloaded from the disk (#150, #151) * (Fix) PositionZ rounding error when removing layers
74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
|
|
namespace UVtools.Core.Extensions
|
|
{
|
|
public static class SizeExtensions
|
|
{
|
|
public static readonly string[] SizeSuffixes =
|
|
{ "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
|
|
|
public static string SizeSuffix(long value, byte decimalPlaces = 2)
|
|
{
|
|
//if (decimalPlaces < 0) { throw new ArgumentOutOfRangeException("decimalPlaces"); }
|
|
if (value < 0) { return "-" + SizeSuffix(-value); }
|
|
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);
|
|
|
|
// 1L << (mag * 10) == 2 ^ (10 * mag)
|
|
// [i.e. the number of bytes in the unit corresponding to mag]
|
|
decimal adjustedSize = (decimal)value / (1L << (mag * 10));
|
|
|
|
// make adjustment when the value is large enough that
|
|
// it would round up to 1000 or more
|
|
if (Math.Round(adjustedSize, decimalPlaces) >= 1000)
|
|
{
|
|
mag += 1;
|
|
adjustedSize /= 1024;
|
|
}
|
|
|
|
return string.Format("{0:n" + decimalPlaces + "} {1}",
|
|
adjustedSize,
|
|
SizeSuffixes[mag]);
|
|
}
|
|
|
|
public static Size Inflate(this Size size, int pixels) => new (size.Width + pixels, size.Height + pixels);
|
|
public static Size Inflate(this Size size, int width, int height) => new (size.Width + width, size.Height + height);
|
|
|
|
public static int Area(this Rectangle rect)
|
|
{
|
|
return rect.Width * rect.Height;
|
|
}
|
|
|
|
public static int Area(this Size size)
|
|
{
|
|
return size.Width * size.Height;
|
|
}
|
|
|
|
public static int Max(this Size size)
|
|
{
|
|
return Math.Max(size.Width, size.Height);
|
|
}
|
|
|
|
public static float Area(this RectangleF rect, int round = -1)
|
|
{
|
|
return round >= 0 ? (float) Math.Round(rect.Width * rect.Height, round) : rect.Width * rect.Height;
|
|
}
|
|
|
|
public static float Area(this SizeF size, int round = -1)
|
|
{
|
|
return round >= 0 ? (float)Math.Round(size.Width * size.Height, round) : size.Width * size.Height;
|
|
}
|
|
|
|
public static float Max(this SizeF size)
|
|
{
|
|
return Math.Max(size.Width, size.Height);
|
|
}
|
|
|
|
}
|
|
}
|