按他 2026-10-25 的澄清(规范 §24.5 / §25 已先改对): - **序号不再是给人设的**:标题行 `R… D…` 改成文本读数(就地刷新);Body 里不再有任何序号输入控件。 新增 `RenumberDrawOrder()`:任何结构变化(上移/下移/加/删)之后把每个元素的 `m_DrawOrder` 重写成它在表里的位置 ⇒ **位置更靠后=绘得更晚=盖在上面**,位置是唯一权威; 注册序由类型定死,只显示。↑↓ 的 tooltip 也改成讲层序。 - **矢量场数据口径改对**:前三维=坐标 x/y/z(与圆柱/散点同一套归一化)、**一支箭头=相邻两条记录** (第 i 条起点、第 i+1 条按绝对/相对解释)、**第 4~7 维=颜色**(色相 0..256 色环 / 饱和 / 明度 / 不透明, 全可选)。需求印**三个数**(需要几个数值维 / 需要几条记录 / 表里各有多少)—— "记录不够"与"维数不够"在画面上同形,只有这三个数分得清。 - 支数由纯算术 `XChartVectorFieldMath.ArrowCount(记录数, 上限)` 算(N 条 ⇒ N−1 支,上限裁剪,<2 条 ⇒ 0)。 - **两端各自颜色**:杆用起点色、头用终点色(读两条记录各自的颜色维);沿杆逐顶点渐变留给 P18。 - 生成器 `螺旋矢量场` 改成 **7 维**(坐标 + 色相走满一圈 + 饱和/明度/不透明),自己补列。 判据:编译门三臂 + 3 对照绿;探针 **439** 项 0 失败(新增支数一族); `p4_control` **57/57** 支臂各红在点名断言上(新增两支:一对不再花两条记录、空表不挡而直接进算术); `p2` / `family` / `generator_gate` / `hierarchy_gate` 在同一棵交付树上复跑全绿。 过程记录:第一版给"一对不再花两条记录"点名的清单里放了一条**被更前面的守卫挡住、这支变异体碰不到** 的判据,`did not go red` 当场抓出来 ⇒ 按实测改清单,并给零/一条记录补了它自己那支变异体(§25.7)。
89 lines
4.3 KiB
C#
89 lines
4.3 KiB
C#
using UnityEngine;
|
||
|
||
namespace XericUI.XChart.Mesh
|
||
{
|
||
/// <summary>
|
||
/// 矢量场(箭头)的<b>纯算术</b>:一条记录的两组三维怎么变成一支箭头,以及一组颜色维怎么变成颜色。
|
||
/// 单独拎出来是因为这两条是"看图看不出来"的判据——
|
||
/// 他 2026-10-25 现场:"我把它添加进来了,之后它并没有显示出来",以及"相对和绝对就是这两种区别"。
|
||
/// 读数与算式放在一起,离线探针才能逐条钉住(规范 §25)。
|
||
/// </summary>
|
||
public static class XChartVectorFieldMath
|
||
{
|
||
/// <summary>
|
||
/// 末端位置。<paramref name="mode"/>=<see cref="XChartArrowVectorMode.Absolute"/> 时
|
||
/// <paramref name="second"/> 是<b>方向矢量</b>本身(起点 + 方向×倍率);
|
||
/// =<see cref="XChartArrowVectorMode.Relative"/> 时它是<b>第二个点</b>(起点 + 差向量×倍率)。
|
||
/// 两种读法在同一个数据上画出来是两幅不同的图:前者"刺猬",后者"首尾相接"。
|
||
/// </summary>
|
||
public static Vector3 Tip(XChartArrowVectorMode mode, Vector3 first, Vector3 second, float scale)
|
||
{
|
||
Vector3 direction = mode == XChartArrowVectorMode.Relative ? second - first : second;
|
||
return first + direction * scale;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 一支箭头=相邻两条记录 ⇒ 给定记录数与上限,能画出几支(上限 ≤0 =不限)。
|
||
///
|
||
/// <para>单列出来是因为<b>"记录不够"与"维数不够"在画面上完全同形</b>(都是一条都不画),
|
||
/// 而 N−1 与 0 这两个数是唯一分得清它们的读数(规范 §25.1)。</para>
|
||
/// </summary>
|
||
public static int ArrowCount(int recordCount, int maxArrows)
|
||
{
|
||
if (recordCount < 2) return 0;
|
||
int pairs = recordCount - 1;
|
||
if (maxArrows > 0 && maxArrows < pairs) return maxArrows;
|
||
return pairs;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 读一组颜色维:<paramref name="hue"/> 按 <b>0..256 的色环</b>(256 与 0 是同一个颜色,
|
||
/// 取模,所以 300 也读得动),饱和度/明度/不透明度按 0..1 夹住。
|
||
///
|
||
/// <para><b>任何一个不是有限数就拒绝</b>(返回 false,调用方退回单色):
|
||
/// NaN 经取模与 HSV 换算会得到一个看着像"黑色块"的东西——那不是数据的意思,
|
||
/// 是我们在替它编一个颜色(同 §14.1 的"宁可这一帧不画")。</para>
|
||
/// </summary>
|
||
public static bool TryColor(float hue, float saturation, float value, float alpha, out Color color)
|
||
{
|
||
color = Color.white;
|
||
if (!IsFinite(hue) || !IsFinite(saturation) || !IsFinite(value) || !IsFinite(alpha)) return false;
|
||
|
||
color = HsvToRgb(Mathf.Repeat(hue / 256f, 1f), Mathf.Clamp01(saturation), Mathf.Clamp01(value));
|
||
color.a = Mathf.Clamp01(alpha);
|
||
return true;
|
||
}
|
||
|
||
private static bool IsFinite(float value)
|
||
=> !float.IsNaN(value) && !float.IsInfinity(value);
|
||
|
||
/// <summary>
|
||
/// HSV → RGB(h∈[0,1),s/v∈[0,1])。
|
||
/// <b>自己写而不是调 <c>Color.HSVToRGB</c></b>:后者是引擎侧的静态调用,
|
||
/// 离线探针(mono + CoreModule)里跑不起来,而这条换算恰恰是要离线钉住的(规范 §25)。
|
||
/// </summary>
|
||
private static Color HsvToRgb(float h, float s, float v)
|
||
{
|
||
if (s <= 0f) return new Color(v, v, v, 1f);
|
||
|
||
float sector = h * 6f;
|
||
int index = Mathf.FloorToInt(sector) % 6;
|
||
if (index < 0) index += 6;
|
||
float f = sector - Mathf.Floor(sector);
|
||
|
||
float p = v * (1f - s);
|
||
float q = v * (1f - s * f);
|
||
float t = v * (1f - s * (1f - f));
|
||
|
||
switch (index)
|
||
{
|
||
case 0: return new Color(v, t, p, 1f);
|
||
case 1: return new Color(q, v, p, 1f);
|
||
case 2: return new Color(p, v, t, 1f);
|
||
case 3: return new Color(p, q, v, 1f);
|
||
case 4: return new Color(t, p, v, 1f);
|
||
default: return new Color(v, p, q, 1f);
|
||
}
|
||
}
|
||
}
|
||
} |