{"record":{"id":"a8448efe809f78a0","repo":"stride3d/stride","slug":"there-must-be-four-and-only-four-input-values-for-quaternion","errorCode":null,"errorMessage":"There must be four and only four input values for Quaternion.","messagePattern":"There must be four and only four input values for Quaternion\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Quaternion.cs","lineNumber":162,"sourceCode":"    {\n        X = x;\n        Y = y;\n        Z = z;\n        W = w;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Stride.Core.Mathematics.Quaternion\"/> struct.\n    /// </summary>\n    /// <param name=\"values\">The values to assign to the X, Y, Z, and W components of the quaternion. This must be an array with four elements.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"values\"/> is <c>null</c>.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when <paramref name=\"values\"/> contains more or less than four elements.</exception>\n    public Quaternion(float[] values)\n    {\n        if (values == null)\n            throw new ArgumentNullException(nameof(values));\n        if (values.Length != 4)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be four and only four input values for Quaternion.\");\n\n        X = values[0];\n        Y = values[1];\n        Z = values[2];\n        W = values[3];\n    }\n\n    /// <summary>\n    /// Gets a value indicating whether this instance is equivalent to the identity quaternion.\n    /// </summary>\n    /// <value>\n    /// <c>true</c> if this instance is an identity quaternion; otherwise, <c>false</c>.\n    /// </value>\n    public bool IsIdentity\n    {\n        get { return this.Equals(Identity); }\n    }\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Quaternion.cs#L144-L180","documentation":"Quaternion's float[] constructor requires exactly 4 elements (X, Y, Z, W). An array of any other length triggers ArgumentOutOfRangeException because a quaternion is defined by precisely these four components.","triggerScenarios":"Calling new Quaternion(float[] values) with an array whose Length is not 4, e.g. a 3-element vector array or a rotation matrix row.","commonSituations":"Reusing vector (x,y,z) arrays for quaternions; parsing rotation data that includes an extra angle; truncated deserialization of quaternion payloads.","solutions":["Pass an array with exactly 4 floats (X, Y, Z, W)","Check values.Length == 4 before construction and handle otherwise","Use the Quaternion(x, y, z, w) constructor to avoid array length ambiguity"],"exampleFix":"// before\nvar q = new Quaternion(vec3Array); // float[3]\n// after\nvar q = new Quaternion(x, y, z, w);","handlingStrategy":"validation","validationCode":"if (values == null || values.Length != 4) throw new ArgumentException(\"Quaternion requires exactly 4 floats: X, Y, Z, W\");\nvar q = new Quaternion(values);","typeGuard":"bool IsValidQuaternionArray(float[] v) => v != null && v.Length == 4;","tryCatchPattern":"try { var q = new Quaternion(values); }\ncatch (ArgumentOutOfRangeException ex) { /* ex.ParamName == \"values\"; handle wrong-length array */ }","preventionTips":["Never reuse 3-component vector arrays as quaternion data","Assert length 4 at deserialization boundaries","Use the Quaternion(x, y, z, w) constructor for clarity"],"tags":["mathematics","argument-out-of-range","quaternion"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}