功能更新

This commit is contained in:
GG Z
2026-02-12 21:29:00 +08:00
parent a9faf251be
commit b3479d1f39
342 changed files with 4671 additions and 2223 deletions

View File

@@ -4,6 +4,11 @@ namespace ShrlAlgoToolkit.Core.Assists
{
public class ColorAssist
{
/// <summary>
/// 获取与 ElementId 唯一对应的鲜艳颜色
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static Color GetDistinctColorById(ElementId id)
{
int hash = id.GetHashCode();
@@ -13,7 +18,7 @@ namespace ShrlAlgoToolkit.Core.Assists
// unchecked 关键字确保在某些开启了溢出检查的项目配置中不会报错
unchecked
{
hash = hash * (int)2654435761;
hash *= (int)2654435761;
}
// 2. 将哈希值映射到 0.0 - 1.0 的色相 (Hue)
@@ -32,7 +37,13 @@ namespace ShrlAlgoToolkit.Core.Assists
return HsvToRgb(h, s, v);
}
// 辅助函数HSV 转 Revit Color
/// <summary>
/// 辅助函数HSV 转 Revit Color
/// </summary>
/// <param name="h"></param>
/// <param name="s"></param>
/// <param name="v"></param>
/// <returns></returns>
private static Color HsvToRgb(double h, double s, double v)
{
int hi = (int)(h * 6);
@@ -42,15 +53,15 @@ namespace ShrlAlgoToolkit.Core.Assists
byte t = (byte)(v * (1 - (1 - f) * s) * 255);
byte vByte = (byte)(v * 255);
switch (hi % 6)
return (hi % 6) switch
{
case 0: return new Color(vByte, t, p);
case 1: return new Color(q, vByte, p);
case 2: return new Color(p, vByte, t);
case 3: return new Color(p, q, vByte);
case 4: return new Color(t, p, vByte);
default: return new Color(vByte, p, q);
}
0 => new Color(vByte, t, p),
1 => new Color(q, vByte, p),
2 => new Color(p, vByte, t),
3 => new Color(p, q, vByte),
4 => new Color(t, p, vByte),
_ => new Color(vByte, p, q),
};
}
}
}

View File

@@ -5,6 +5,7 @@ using System.Reflection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using ShrlAlgoToolkit.Revit.Extensions;
namespace ShrlAlgoToolkit.Revit.Assists;

View File

@@ -1,4 +1,5 @@
using Autodesk.Revit.DB;
using ShrlAlgoToolkit.Revit.Extensions;
namespace ShrlAlgoToolkit.Revit.Assists;