public async Task Setting_FunctionScopeValue_UsesFunctionScopeValue() { var config = new XyzConfiguration() { }; var attr = new XyzAttribute() { }; var outputContent = new StringBuilder(); var output = new StringWriter(outputContent); var target = new XyzAsyncCollector(config, attr, output); await target.AddAsync(new XyzItem() { Text = "From Item" }); await target.FlushAsync(); Assert.Equal("From Item", outputContent.ToString()); }
/// <summary> /// Adds a new sensor to the Robot model, creating a joint and link object for the component being added. /// </summary> /// <param name="component">The component object being added. MUST NOT BE NULL</param> /// <param name="parent">The name of the parent link that this component is linked to. MUST NOT BE NULL OR EMPTY</param> /// <param name="xyz">The XYZ offset of this component from its parent link. MUST NOT BE NULL</param> /// <param name="rpy">The RPY offset of this component from its parent link. MUST NOT BE NULL</param> /// <returns><c>true</c> if the component was successfully added, otherwise <c>false</c></returns> public string AddComponent(Component component, string parent, XyzAttribute xyz, RpyAttribute rpy) { Preconditions.IsNotNull(component, "Cannot add a null component to the Robot"); Preconditions.IsNotEmpty(parent, $"Cannot add component '{component.Name}' to the Robot model with missing parent name"); Preconditions.IsNotNull(xyz, $"Cannot add component '{component.Name}' to '{Name}' Robot model with null XYZ offset"); Preconditions.IsNotNull(rpy, $"Cannot add component '{component.Name}' to '{Name}' Robot model with null RPY offset"); if (!this.Links.ContainsKey(parent)) { //LOGGER.Warn($"Adding component '{component.Name}' to '{Name}' Robot model failed because '{Name}' doesn't contain link called '{parent}'"); return(null); } string linkName = GenerateUniqueKey(component.Name, new List <string>(this.Links.Keys)); string jointName = GenerateUniqueKey($"{component.Name}_joint", new List <string>(this.Joints.Keys)); Geometry geometry = (component.Box != null) ? new Geometry(new Box(component.Box.Size)) : new Geometry(new Mesh.Builder(component.FileName).Build()); Visual visual = new Visual.Builder(geometry).Build(); Link link = new Link.Builder(linkName).SetVisual(visual).Build(); Joint joint = new Joint.Builder(jointName, Joint.JointType.Fixed, this.Links[parent], link).Build(); this.Links.Add(link.Name, link); this.Joints.Add(joint.Name, joint); return(linkName); }
public void ConstructDefault() { XyzAttribute xyz = new XyzAttribute(); Assert.AreEqual(xyz.X, 0); Assert.AreEqual(xyz.Y, 0); Assert.AreEqual(xyz.Z, 0); }
public void ConstructOrigin() { XyzAttribute xyz = new XyzAttribute(1, 2, 3); RpyAttribute rpy = new RpyAttribute(4, 5, 6); Origin origin = new Origin.Builder().SetXyz(xyz).SetRpy(rpy).Build(); Assert.AreEqual(xyz, origin.Xyz); Assert.AreEqual(rpy, origin.Rpy); }
public void ConstructXyzOrigin() { XyzAttribute xyz = new XyzAttribute(1, 2, 3); Origin origin = new Origin.Builder().SetXyz(xyz).Build(); Assert.AreEqual(xyz, origin.Xyz); Assert.AreEqual(0, origin.Rpy.R); Assert.AreEqual(0, origin.Rpy.P); Assert.AreEqual(0, origin.Rpy.Y); }
public void ConstructXyz() { int x = 1; int y = 2; int z = 3; XyzAttribute xyz = new XyzAttribute(x, y, z); Assert.AreEqual(xyz.X, x); Assert.AreEqual(xyz.Y, y); Assert.AreEqual(xyz.Z, z); }
public void ConstructAxis() { double x = 1; double y = 2; double z = 3; XyzAttribute xyz = new XyzAttribute(x, y, z); Axis axis = new Axis(xyz); Assert.AreEqual(xyz, axis.Xyz); Assert.AreEqual(x, axis.Xyz.X); Assert.AreEqual(y, axis.Xyz.Y); Assert.AreEqual(z, axis.Xyz.Z); }
public void EqualsAndHash() { XyzAttribute xyz = new XyzAttribute(1, 2, 3); XyzAttribute same = new XyzAttribute(1, 2, 3); XyzAttribute diff = new XyzAttribute(3, 2, 1); Assert.IsTrue(xyz.Equals(xyz)); Assert.IsFalse(xyz.Equals(null)); Assert.IsTrue(xyz.Equals(same)); Assert.IsTrue(same.Equals(xyz)); Assert.IsFalse(xyz.Equals(diff)); Assert.AreEqual(xyz.GetHashCode(), same.GetHashCode()); Assert.AreNotEqual(xyz.GetHashCode(), diff.GetHashCode()); }
/// <summary> /// Parses a URDF <axis> element from XML. /// </summary> /// <param name="node">The XML node of a <axis> element. MUST NOT BE NULL</param> /// <returns>An Axis object parsed from the XML</returns> public override Axis Parse(XmlNode node) { ValidateXmlNode(node); XmlAttribute xyzAttribute = GetAttributeFromNode(node, UrdfSchema.XYZ_ATTRIBUTE_NAME); if (xyzAttribute == null) { LogMissingRequiredAttribute(UrdfSchema.XYZ_ATTRIBUTE_NAME); return(Axis.DEFAULT_AXIS); } if (!RegexUtils.IsMatchNDoubles(xyzAttribute.Value, 3)) { LogMalformedAttribute(UrdfSchema.XYZ_ATTRIBUTE_NAME); return(Axis.DEFAULT_AXIS); } double[] values = RegexUtils.MatchDoubles(xyzAttribute.Value); XyzAttribute xyz = new XyzAttribute(values[0], values[1], values[2]); return(new Axis(xyz)); }
/// <summary> /// Adds a new sensor to the Robot model, creating a joint object for the component being added. /// </summary> /// <param name="component">The Robot model object being added. MUST NOT BE NULL</param> /// <param name="parent">The name of the parent link on this Robot that this component is linked to. MUST NOT BE NULL OR EMPTY</param> /// <param name="child">The name of the child link on the component Robot that this component is linked by. MUST NOT BE NULL OR EMPTY</param> /// <param name="xyz">The XYZ offset of this component from its parent link. MUST NOT BE NULL</param> /// <param name="rpy">The RPY offset of this component from its parent link. MUST NOT BE NULL</param> /// <returns>The name of the connected Link object if the component was successfully added, otherwise <c>null</c></returns> public string AddComponent(Robot component, string parent, string child, XyzAttribute xyz, RpyAttribute rpy) { Preconditions.IsNotNull(component, "Cannot add a null component to the Robot"); Preconditions.IsNotEmpty(parent, $"Cannot add component '{component.Name}' to the Robot model with missing parent name"); Preconditions.IsNotEmpty(child, $"Cannot add component '{component.Name}' to the Robot model with missing child name"); Preconditions.IsNotNull(xyz, $"Cannot add component '{component.Name}' to '{Name}' Robot model with null XYZ offset"); Preconditions.IsNotNull(rpy, $"Cannot add component '{component.Name}' to '{Name}' Robot model with null RPY offset"); if (!this.Links.ContainsKey(parent)) { //LOGGER.Warn($"Adding component '{component.Name}' to '{Name}' Robot model failed because '{Name}' doesn't contain link called '{parent}'"); return(null); } if (!component.Links.ContainsKey(child)) { //LOGGER.Warn($"Adding component '{component.Name}' to '{Name}' Robot model failed because '{component.Name}' doesn't contain link called '{child}'"); return(null); } string jointName = GenerateUniqueKey($"{component.Name}_joint", new List <string>(this.Joints.Keys)); Joint newJoint = new Joint.Builder(jointName, Joint.JointType.Fixed, this.Links[parent], component.Links[child]).Build(); this.Joints.Add(newJoint.Name, newJoint); foreach (Link link in component.Links.Values) { this.Links.Add(link.Name, link); } foreach (Joint joint in component.Joints.Values) { this.Joints.Add(joint.Name, joint); } return(child); }
/// <summary> /// Creates a new instance of Axis. /// </summary> /// <param name="xyz">The x, y, z components of the axis vector. MUST NOT BE NULL</param> public Axis(XyzAttribute xyz) { Preconditions.IsNotNull(xyz, "Axis xyz property must not be null"); this.Xyz = xyz; }
protected bool Equals(XyzAttribute other) { return(X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z)); }
/// <summary> /// Sets the Origin's XyzAttribute. /// </summary> /// <param name="xyz">The origin element's x, y, z offset. MUST NOT BE NULL</param> /// <returns>This Origin.Builder instance</returns> public Builder SetXyz(XyzAttribute xyz) { Preconditions.IsNotNull(xyz, "Origin xyz property cannot be set to null"); this.xyz = xyz; return(this); }
/// <summary> /// Creates a new instance of Origin with the specified xyz and rpy attribute values. /// An Origin.Builder must be used to instantiate an Origin with optional properties as specified. /// </summary> /// <param name="xyz">The origin element's x, y, z offset.</param> /// <param name="rpy">The origin element's fixed axis roll, pitch and yaw.</param> private Origin(XyzAttribute xyz, RpyAttribute rpy) { this.Xyz = xyz; this.Rpy = rpy; }