Skip to content

Commit

Permalink
Update rotation property to use Point3d
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
glopesdev committed May 12, 2021
1 parent 85992cb commit 42d8d0e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion BonVision/BonVision.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GeneratePackageOnBuild Condition="'$(Configuration)'=='Release'">true</GeneratePackageOnBuild>
<TargetFramework>net462</TargetFramework>
<Features>strict</Features>
<Version>0.9.0</Version>
<Version>0.9.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions BonVision/DegreeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ namespace BonVision
{
class DegreeConverter : SingleConverter
{
public static double RadianToDegree(double value)
{
return value * (180.0 / Math.PI);
}

public static double DegreeToRadian(double value)
{
return value * (Math.PI / 180.0);
}

public static float RadianToDegree(float value)
{
return (float)(value * (180.0 / Math.PI));
return (float)RadianToDegree((double)value);
}

public static float DegreeToRadian(float value)
{
return (float)(value * (Math.PI / 180.0));
return (float)DegreeToRadian((double)value);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
Expand Down Expand Up @@ -42,7 +52,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul

class NullableDegreeConverter : NullableConverter
{
TypeConverter degreeConverter;
readonly TypeConverter degreeConverter;

public NullableDegreeConverter(Type type)
: base(type)
Expand Down
2 changes: 1 addition & 1 deletion BonVision/Environment/ViewWindow.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Rotation" Selector="X,Y,Z" />
<Property Name="Rotation" />
</PropertyMappings>
</Expression>
<Expression xsi:type="ExternalizedMapping">
Expand Down
8 changes: 4 additions & 4 deletions BonVision/RotationConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class RotationConverter : NumericRecordConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var rotation = (Point3f)base.ConvertFrom(context, culture, value);
return new Point3f(
var rotation = (Point3d)base.ConvertFrom(context, culture, value);
return new Point3d(
DegreeConverter.DegreeToRadian(rotation.X),
DegreeConverter.DegreeToRadian(rotation.Y),
DegreeConverter.DegreeToRadian(rotation.Z));
}

public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
var rotation = (Point3f)value;
value = new Point3f(
var rotation = (Point3d)value;
value = new Point3d(
DegreeConverter.RadianToDegree(rotation.X),
DegreeConverter.RadianToDegree(rotation.Y),
DegreeConverter.RadianToDegree(rotation.Z));
Expand Down
20 changes: 10 additions & 10 deletions BonVision/RotationProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace BonVision
[WorkflowElementCategory(ElementCategory.Source)]
public class RotationProperty
{
Point3f value;
event Action<Point3f> ValueChanged;
Point3d value;
event Action<Point3d> ValueChanged;

[XmlIgnore]
[TypeConverter(typeof(RotationConverter))]
[Description("The value of the rotation vector, in euler angle format.")]
public Point3f Value
public Point3d Value
{
get { return value; }
set
Expand All @@ -32,39 +32,39 @@ public Point3f Value

[Browsable(false)]
[XmlElement("Value")]
public Point3f ValueXml
public Point3d ValueXml
{
get
{
var x = DegreeConverter.RadianToDegree(value.X);
var y = DegreeConverter.RadianToDegree(value.Y);
var z = DegreeConverter.RadianToDegree(value.Z);
return new Point3f(x, y, z);
return new Point3d(x, y, z);
}
set
{
var x = DegreeConverter.DegreeToRadian(value.X);
var y = DegreeConverter.DegreeToRadian(value.Y);
var z = DegreeConverter.DegreeToRadian(value.Z);
this.value = new Point3f(x, y, z);
this.value = new Point3d(x, y, z);
}
}

void OnValueChanged(Point3f value)
void OnValueChanged(Point3d value)
{
ValueChanged?.Invoke(value);
}

public IObservable<Point3f> Process()
public IObservable<Point3d> Process()
{
return Observable
.Defer(() => Observable.Return(value))
.Concat(Observable.FromEvent<Point3f>(
.Concat(Observable.FromEvent<Point3d>(
handler => ValueChanged += handler,
handler => ValueChanged -= handler));
}

public IObservable<Point3f> Process<TSource>(IObservable<TSource> source)
public IObservable<Point3d> Process<TSource>(IObservable<TSource> source)
{
return source.Select(x => value);
}
Expand Down

0 comments on commit 42d8d0e

Please sign in to comment.