Line支持Clip

This commit is contained in:
monitor1394
2023-05-11 08:34:04 +08:00
parent fab683f5e1
commit bab788d4cb
2 changed files with 74 additions and 35 deletions

View File

@@ -133,14 +133,48 @@ namespace XCharts.Runtime
return Contains(pos.x, pos.y);
}
[Since("v3.7.0")]
public bool Contains(Vector3 pos, bool isYAxis)
{
return isYAxis ? ContainsY(pos.y) : ContainsX(pos.x);
}
public bool Contains(float x, float y)
{
if (x < context.x - 1 || x > context.x + context.width + 1 ||
y < context.y - 1 || y > context.y + context.height + 1)
{
return false;
}
return true;
return ContainsX(x) && ContainsY(y);
}
[Since("v3.7.0")]
public bool ContainsX(float x)
{
return x >= context.x && x <= context.x + context.width;
}
[Since("v3.7.0")]
public bool ContainsY(float y)
{
return y >= context.y && y <= context.y + context.height;
}
[Since("v3.7.0")]
public void Clamp(ref Vector3 pos)
{
ClampX(ref pos);
ClampY(ref pos);
}
[Since("v3.7.0")]
public void ClampX(ref Vector3 pos)
{
if (pos.x < context.x) pos.x = context.x;
else if (pos.x > context.x + context.width) pos.x = context.x + context.width;
}
[Since("v3.7.0")]
public void ClampY(ref Vector3 pos)
{
if (pos.y < context.y) pos.y = context.y;
else if (pos.y > context.y + context.height) pos.y = context.y + context.height;
}
/// <summary>