ZMWSLI0-SL2021-GR11/Projekt/MWSProjekt/Assets/Scripts/LSystemNodeLiteral.cs

59 lines
1.7 KiB
C#

using System.Text;
public class LSystemNodeLiteral
{
public string name { get; }
public int values_number { get; }
public float[] values { get; set; }
public LSystemNodeLiteral(string name, int values_number)
{
this.name = name;
this.values_number = values_number;
//in case it would be 0
values = new float[values_number];
}
public LSystemNodeLiteral(LSystemNodeLiteral other)
{
this.name = other.name;
this.values_number = other.values_number;
//in case it would be 0
values = new float[this.values_number];
other.values.CopyTo(values, 0);
}
public static bool operator ==(LSystemNodeLiteral thisLiteral, LSystemNodeLiteral other)
{
return thisLiteral.name == other.name && thisLiteral.values_number == other.values_number;
}
public static bool operator !=(LSystemNodeLiteral thisLiteral, LSystemNodeLiteral other)
{
return !(thisLiteral.name == other.name && thisLiteral.values_number == other.values_number);
}
public override string ToString()
{
if (values_number == 0)
{
return name;
}
else
{
StringBuilder sb = new StringBuilder(name, name.Length + values_number * 7 + 4);
sb.Append("(");
for (int i = 0; i < values_number; i++)
{
var v = values[i];
sb.AppendFormat("{0:0.##}", v);
if (i < values_number - 1)
{
sb.Append(",");
}
}
sb.Append(")");
return sb.ToString();
}
}
}