Initial commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2018 The Cartographer Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using CartographerSharp.Common.Time;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CartographerSharp.Models.Transform;
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a timestamped 3D transformation.
|
||||
/// </summary>
|
||||
public struct TimestampedTransform(long time, Rigid3dProto transform)
|
||||
{
|
||||
/// <summary>
|
||||
/// Time in Universal Time Scale ticks (100 nanosecond ticks since epoch).
|
||||
/// </summary>
|
||||
[JsonPropertyName("time")]
|
||||
public long Time { get; set; } = time;
|
||||
|
||||
/// <summary>
|
||||
/// The 3D transformation.
|
||||
/// </summary>
|
||||
[JsonPropertyName("transform")]
|
||||
public Rigid3dProto Transform { get; set; } = transform;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a TimestampedTransform from a DateTime and Rigid3d.
|
||||
/// </summary>
|
||||
public static TimestampedTransform FromDateTime(DateTime time, CartographerSharp.Transform.Rigid3d transform)
|
||||
{
|
||||
return new TimestampedTransform(
|
||||
TimeUtils.ToUniversal(time),
|
||||
transform
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the time to a DateTime.
|
||||
/// </summary>
|
||||
public readonly DateTime ToDateTime()
|
||||
{
|
||||
return TimeUtils.FromUniversal(Time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright 2016 The Cartographer Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using CartographerSharp.Transform;
|
||||
using RobotNet10.Shared.Numbers;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CartographerSharp.Models.Transform;
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a 2D vector (double precision).
|
||||
/// </summary>
|
||||
public struct Vector2d(double x, double y)
|
||||
{
|
||||
[JsonPropertyName("x")]
|
||||
public double X { get; set; } = x;
|
||||
|
||||
[JsonPropertyName("y")]
|
||||
public double Y { get; set; } = y;
|
||||
|
||||
public static implicit operator Vector2(Vector2d v) => new(v.X, v.Y);
|
||||
public static implicit operator Vector2d(Vector2 v) => new(v.X, v.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a 2D vector (single precision).
|
||||
/// </summary>
|
||||
public struct Vector2f(double x, double y)
|
||||
{
|
||||
[JsonPropertyName("x")]
|
||||
public double X { get; set; } = x;
|
||||
|
||||
[JsonPropertyName("y")]
|
||||
public double Y { get; set; } = y;
|
||||
|
||||
public static implicit operator Vector2(Vector2f v) => new(v.X, v.Y);
|
||||
public static implicit operator Vector2f(Vector2 v) => new(v.X, v.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a 3D vector (double precision).
|
||||
/// </summary>
|
||||
public struct Vector3d(double x, double y, double z)
|
||||
{
|
||||
[JsonPropertyName("x")]
|
||||
public double X { get; set; } = x;
|
||||
|
||||
[JsonPropertyName("y")]
|
||||
public double Y { get; set; } = y;
|
||||
|
||||
[JsonPropertyName("z")]
|
||||
public double Z { get; set; } = z;
|
||||
|
||||
public static implicit operator Vector3(Vector3d v) => new(v.X, v.Y, v.Z);
|
||||
public static implicit operator Vector3d(Vector3 v) => new(v.X, v.Y, v.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a 3D vector (single precision).
|
||||
/// </summary>
|
||||
public struct Vector3f(double x, double y, double z)
|
||||
{
|
||||
[JsonPropertyName("x")]
|
||||
public double X { get; set; } = x;
|
||||
|
||||
[JsonPropertyName("y")]
|
||||
public double Y { get; set; } = y;
|
||||
|
||||
[JsonPropertyName("z")]
|
||||
public double Z { get; set; } = z;
|
||||
|
||||
public static implicit operator Vector3(Vector3f v) => new(v.X, v.Y, v.Z);
|
||||
public static implicit operator Vector3f(Vector3 v) => new(v.X, v.Y, v.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a 4D vector (single precision).
|
||||
/// </summary>
|
||||
public struct Vector4f(double x, double y, double z, double t)
|
||||
{
|
||||
[JsonPropertyName("x")]
|
||||
public double X { get; set; } = x;
|
||||
|
||||
[JsonPropertyName("y")]
|
||||
public double Y { get; set; } = y;
|
||||
|
||||
[JsonPropertyName("z")]
|
||||
public double Z { get; set; } = z;
|
||||
|
||||
[JsonPropertyName("t")]
|
||||
public double T { get; set; } = t;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a quaternion (double precision).
|
||||
/// </summary>
|
||||
public struct Quaterniond(double x, double y, double z, double w)
|
||||
{
|
||||
[JsonPropertyName("x")]
|
||||
public double X { get; set; } = x;
|
||||
|
||||
[JsonPropertyName("y")]
|
||||
public double Y { get; set; } = y;
|
||||
|
||||
[JsonPropertyName("z")]
|
||||
public double Z { get; set; } = z;
|
||||
|
||||
[JsonPropertyName("w")]
|
||||
public double W { get; set; } = w;
|
||||
|
||||
public static implicit operator Quaternion(Quaterniond q) => new(q.X, q.Y, q.Z, q.W);
|
||||
public static implicit operator Quaterniond(Quaternion q) => new(q.X, q.Y, q.Z, q.W);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a quaternion (single precision).
|
||||
/// </summary>
|
||||
public struct Quaternionf(double x, double y, double z, double w)
|
||||
{
|
||||
[JsonPropertyName("x")]
|
||||
public double X { get; set; } = x;
|
||||
|
||||
[JsonPropertyName("y")]
|
||||
public double Y { get; set; } = y;
|
||||
|
||||
[JsonPropertyName("z")]
|
||||
public double Z { get; set; } = z;
|
||||
|
||||
[JsonPropertyName("w")]
|
||||
public double W { get; set; } = w;
|
||||
|
||||
public static implicit operator Quaternion(Quaternionf q) => new(q.X, q.Y, q.Z, q.W);
|
||||
public static implicit operator Quaternionf(Quaternion q) => new(q.X, q.Y, q.Z, q.W);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a rigid 2D transformation (double precision).
|
||||
/// </summary>
|
||||
public struct Rigid2dProto(Vector2d translation, double rotation)
|
||||
{
|
||||
[JsonPropertyName("translation")]
|
||||
public Vector2d Translation { get; set; } = translation;
|
||||
|
||||
[JsonPropertyName("rotation")]
|
||||
public double Rotation { get; set; } = rotation;
|
||||
|
||||
public static implicit operator Rigid2d(Rigid2dProto proto)
|
||||
{
|
||||
return new Rigid2d(proto.Translation, proto.Rotation);
|
||||
}
|
||||
|
||||
public static implicit operator Rigid2dProto(Rigid2d rigid)
|
||||
{
|
||||
return new Rigid2dProto(rigid.Translation, rigid.Rotation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a rigid 2D transformation (single precision).
|
||||
/// </summary>
|
||||
public struct Rigid2fProto(Vector2f translation, double rotation)
|
||||
{
|
||||
[JsonPropertyName("translation")]
|
||||
public Vector2f Translation { get; set; } = translation;
|
||||
|
||||
[JsonPropertyName("rotation")]
|
||||
public double Rotation { get; set; } = rotation;
|
||||
|
||||
public static implicit operator Rigid2f(Rigid2fProto proto)
|
||||
{
|
||||
return new Rigid2f(proto.Translation, proto.Rotation);
|
||||
}
|
||||
|
||||
public static implicit operator Rigid2fProto(Rigid2f rigid)
|
||||
{
|
||||
return new Rigid2fProto(rigid.Translation, rigid.Rotation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a rigid 3D transformation (double precision).
|
||||
/// </summary>
|
||||
public struct Rigid3dProto(Vector3d translation, Quaterniond rotation)
|
||||
{
|
||||
[JsonPropertyName("translation")]
|
||||
public Vector3d Translation { get; set; } = translation;
|
||||
|
||||
[JsonPropertyName("rotation")]
|
||||
public Quaterniond Rotation { get; set; } = rotation;
|
||||
|
||||
public static implicit operator Rigid3d(Rigid3dProto proto)
|
||||
{
|
||||
return new Rigid3d(proto.Translation, proto.Rotation);
|
||||
}
|
||||
|
||||
public static implicit operator Rigid3dProto(Rigid3d rigid)
|
||||
{
|
||||
return new Rigid3dProto(rigid.Translation, rigid.Rotation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protocol buffer representation of a rigid 3D transformation (single precision).
|
||||
/// </summary>
|
||||
public struct Rigid3fProto(Vector3f translation, Quaternionf rotation)
|
||||
{
|
||||
[JsonPropertyName("translation")]
|
||||
public Vector3f Translation { get; set; } = translation;
|
||||
|
||||
[JsonPropertyName("rotation")]
|
||||
public Quaternionf Rotation { get; set; } = rotation;
|
||||
|
||||
public static implicit operator Rigid3f(Rigid3fProto proto)
|
||||
{
|
||||
return new Rigid3f(proto.Translation, proto.Rotation);
|
||||
}
|
||||
|
||||
public static implicit operator Rigid3fProto(Rigid3f rigid)
|
||||
{
|
||||
return new Rigid3fProto(rigid.Translation, rigid.Rotation);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user