submodule对gitea不管用,所以直接拉了一份拉格兰
This commit is contained in:
22
Lagrange.Core/Lagrange.OneBot/Utility/Vector2Mapper.cs
Normal file
22
Lagrange.Core/Lagrange.OneBot/Utility/Vector2Mapper.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Numerics;
|
||||
using LiteDB;
|
||||
|
||||
namespace Lagrange.OneBot.Utility;
|
||||
|
||||
public static class Vector2Mapper
|
||||
{
|
||||
public static void RegisterType() => BsonMapper.Global.RegisterType(Serialize, Deserialize);
|
||||
|
||||
public static BsonValue Serialize(Vector2 parameter) => new BsonDocument(new Dictionary<string, BsonValue>
|
||||
{
|
||||
{ "X", parameter.X },
|
||||
{ "Y", parameter.Y }
|
||||
});
|
||||
|
||||
public static Vector2 Deserialize(BsonValue bsonValue)
|
||||
{
|
||||
float x = (float)bsonValue["X"].AsDouble;
|
||||
float y = (float)bsonValue["Y"].AsDouble;
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user