mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 17:30:10 +00:00
优化数据存储类型由float全部转为double
This commit is contained in:
@@ -28,10 +28,10 @@ namespace XCharts
|
||||
private static Dictionary<string, string> s_AxisLabel = new Dictionary<string, string>();
|
||||
|
||||
|
||||
private static Dictionary<float, Dictionary<string, string>> s_NumberToStr = new Dictionary<float, Dictionary<string, string>>();
|
||||
private static Dictionary<double, Dictionary<string, string>> s_NumberToStr = new Dictionary<double, Dictionary<string, string>>();
|
||||
private static Dictionary<int, Dictionary<string, string>> s_PrecisionToStr = new Dictionary<int, Dictionary<string, string>>();
|
||||
|
||||
public static string FloatToStr(float value, string numericFormatter = "F", int precision = 0)
|
||||
public static string FloatToStr(double value, string numericFormatter = "F", int precision = 0)
|
||||
{
|
||||
if (precision > 0 && numericFormatter.Length == 1)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static string NumberToStr(float value, string formatter)
|
||||
public static string NumberToStr(double value, string formatter)
|
||||
{
|
||||
if (!s_NumberToStr.ContainsKey(value))
|
||||
{
|
||||
|
||||
@@ -725,7 +725,7 @@ namespace XCharts
|
||||
return (Color32)color;
|
||||
}
|
||||
|
||||
public static float GetMaxDivisibleValue(float max, int ceilRate)
|
||||
public static double GetMaxDivisibleValue(double max, int ceilRate)
|
||||
{
|
||||
if (max == 0) return 0;
|
||||
if (max > -1 && max < 1)
|
||||
@@ -742,20 +742,20 @@ namespace XCharts
|
||||
}
|
||||
if (ceilRate == 0)
|
||||
{
|
||||
var bigger = Mathf.Ceil(Mathf.Abs(max));
|
||||
var bigger = Math.Ceiling(Math.Abs(max));
|
||||
int n = 1;
|
||||
while (bigger / (Mathf.Pow(10, n)) > 10)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
float mm = bigger;
|
||||
double mm = bigger;
|
||||
if (mm > 10 && n < 38)
|
||||
{
|
||||
mm = bigger - bigger % (Mathf.Pow(10, n));
|
||||
mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
|
||||
}
|
||||
if (max < 0) return -Mathf.Ceil(mm);
|
||||
else return Mathf.Ceil(mm);
|
||||
if (max < 0) return -Math.Ceiling(mm);
|
||||
else return Math.Ceiling(mm);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -765,7 +765,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static float GetMinDivisibleValue(float min, int ceilRate)
|
||||
public static double GetMinDivisibleValue(double min, int ceilRate)
|
||||
{
|
||||
if (min == 0) return 0;
|
||||
if (min > -1 && min < 1)
|
||||
@@ -782,20 +782,20 @@ namespace XCharts
|
||||
}
|
||||
if (ceilRate == 0)
|
||||
{
|
||||
var bigger = Mathf.Floor(Mathf.Abs(min));
|
||||
var bigger = Math.Floor(Math.Abs(min));
|
||||
int n = 1;
|
||||
while (bigger / (Mathf.Pow(10, n)) > 10)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
float mm = bigger;
|
||||
double mm = bigger;
|
||||
if (mm > 10 && n < 38)
|
||||
{
|
||||
mm = bigger - bigger % (Mathf.Pow(10, n));
|
||||
mm += min < 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
|
||||
}
|
||||
if (min < 0) return -Mathf.Floor(mm);
|
||||
else return Mathf.Floor(mm);
|
||||
if (min < 0) return -Math.Floor(mm);
|
||||
else return Math.Floor(mm);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -805,11 +805,11 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static float GetMaxLogValue(float value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
public static double GetMaxLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
{
|
||||
splitNumber = 0;
|
||||
if (value <= 0) return 0;
|
||||
float max = 0;
|
||||
double max = 0;
|
||||
while (max < value)
|
||||
{
|
||||
if (isLogBaseE)
|
||||
@@ -825,7 +825,7 @@ namespace XCharts
|
||||
return max;
|
||||
}
|
||||
|
||||
public static float GetMinLogValue(float value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
public static float GetMinLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
{
|
||||
splitNumber = 0;
|
||||
if (value > 1) return 1;
|
||||
@@ -845,7 +845,7 @@ namespace XCharts
|
||||
return min;
|
||||
}
|
||||
|
||||
public static int GetFloatAccuracy(float value)
|
||||
public static int GetFloatAccuracy(double value)
|
||||
{
|
||||
if (value > 1 || value < -1) return 0;
|
||||
int count = 1;
|
||||
|
||||
52
Runtime/Internal/Utility/MathUtil.cs
Normal file
52
Runtime/Internal/Utility/MathUtil.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class MathUtil
|
||||
{
|
||||
public static double Abs(double d)
|
||||
{
|
||||
return d > 0 ? d : -d;
|
||||
}
|
||||
|
||||
public static double Clamp(double d, double min, double max)
|
||||
{
|
||||
if (d >= min && d <= max) return d;
|
||||
else if (d < min) return min;
|
||||
else return max;
|
||||
}
|
||||
|
||||
public static bool Approximately(double a, double b)
|
||||
{
|
||||
return Math.Abs(b - a) < Math.Max(0.000001f * Math.Max(Math.Abs(a), Math.Abs(b)), Mathf.Epsilon * 8);
|
||||
}
|
||||
|
||||
public static double Clamp01(double value)
|
||||
{
|
||||
if (value < 0F)
|
||||
return 0F;
|
||||
else if (value > 1F)
|
||||
return 1F;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
public static double Lerp(double a, double b, double t)
|
||||
{
|
||||
return a + (b - a) * Clamp01(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Utility/MathUtil.cs.meta
Normal file
11
Runtime/Internal/Utility/MathUtil.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 094dc7b90e3a049b48f15f990c050db1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user