{"record":{"id":"c902e1563e50fb69","repo":"stride3d/stride","slug":"indices-for-quaternion-run-from-0-to-3-inclusive","errorCode":null,"errorMessage":"Indices for Quaternion run from 0 to 3, inclusive.","messagePattern":"Indices for Quaternion run from 0 to 3, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Quaternion.cs","lineNumber":254,"sourceCode":"    /// Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the X, Y, Z, or W component, depending on the index.</value>\n    /// <param name=\"index\">The index of the component to access. Use 0 for the X component, 1 for the Y component, 2 for the Z component, and 3 for the W component.</param>\n    /// <returns>The value of the component at the specified index.</returns>\n    /// <exception cref=\"System.ArgumentOutOfRangeException\">Thrown when the <paramref name=\"index\"/> is out of the range [0, 3].</exception>\n    public float this[int index]\n    {\n        get\n        {\n            switch (index)\n            {\n                case 0: return X;\n                case 1: return Y;\n                case 2: return Z;\n                case 3: return W;\n            }\n\n            throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Quaternion run from 0 to 3, inclusive.\");\n        }\n\n        set\n        {\n            switch (index)\n            {\n                case 0: X = value; break;\n                case 1: Y = value; break;\n                case 2: Z = value; break;\n                case 3: W = value; break;\n                default: throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Quaternion run from 0 to 3, inclusive.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Conjugates the quaternion.\n    /// </summary>","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Quaternion.cs#L236-L272","documentation":"The Quaternion indexer bounds-checks the index parameter and throws ArgumentOutOfRangeException when the index is outside [0, 3]. It is a generic guard on component access mapping 0-3 to X, Y, Z, W; any other index (negative or >= 4) fires the error.","triggerScenarios":"Reading quaternion[idx] with idx < 0 or idx > 3, usually from a loop with incorrect bounds or an index computed from other data sizes.","commonSituations":"Component loops copied from vector code with different component counts; off-by-one iterations; generic math utilities indexing blindly.","solutions":["Validate the index is 0..3 before quaternion[index]","Correct loop bounds to iterate exactly 4 components","Access X, Y, Z, W properties directly instead of the indexer"],"exampleFix":"// before\nfor (int i = 0; i < 5; i++) sum += quaternion[i];\n// after\nfor (int i = 0; i < 4; i++) sum += quaternion[i];","handlingStrategy":"validation","validationCode":"if (index >= 0 && index <= 3) { var c = quaternion[index]; }","typeGuard":"bool IsValidQuaternionIndex(int i) => (uint)i <= 3u;","tryCatchPattern":"try { var c = quaternion[index]; }\ncatch (ArgumentOutOfRangeException ex) { /* ex.ParamName == \"index\"; handle invalid component access */ }","preventionTips":["Iterate quaternions with i < 4","Use X/Y/Z/W properties instead of the indexer","Validate computed indices before use"],"tags":["mathematics","index-out-of-range","quaternion"],"backgroundTag":"index-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"}