{"record":{"id":"c8fe9ecfd529377f","repo":"stride3d/stride","slug":"indices-for-plane-run-from-0-to-3-inclusive","errorCode":null,"errorMessage":"Indices for Plane run from 0 to 3, inclusive.","messagePattern":"Indices for Plane run from 0 to 3, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Plane.cs","lineNumber":162,"sourceCode":"    /// Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the A, B, C, or D component, depending on the index.</value>\n    /// <param name=\"index\">The index of the component to access. Use 0 for the A component, 1 for the B component, 2 for the C component, and 3 for the D 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 Normal.X;\n                case 1: return Normal.Y;\n                case 2: return Normal.Z;\n                case 3: return D;\n            }\n\n            throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Plane run from 0 to 3, inclusive.\");\n        }\n\n        set\n        {\n            switch (index)\n            {\n                case 0: Normal.X = value; break;\n                case 1: Normal.Y = value; break;\n                case 2: Normal.Z = value; break;\n                case 3: D = value; break;\n                default: throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Plane run from 0 to 3, inclusive.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Negates a plane by negating all its coefficients, which result in a plane in opposite direction.\n    /// </summary>","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Plane.cs#L144-L180","documentation":"The Plane indexer getter only supports indices 0..3, mapping to Normal.X, Normal.Y, Normal.Z and D. Any index outside that range falls through the switch and throws ArgumentOutOfRangeException. This enforces the fixed 4-coefficient layout of a plane.","triggerScenarios":"Reading plane[idx] where idx < 0 or idx > 3, typically from a loop with a wrong bound (e.g. iterating to plane.Length or 5) or a variable index computed elsewhere.","commonSituations":"Generic component-access loops written for vectors of other sizes reused on Plane; off-by-one loop conditions; dynamic indices from parsed data.","solutions":["Clamp or validate the index to 0..3 before accessing plane[index]","Fix the loop bound to use the plane coefficient count (4)","For component-wise access, use the named properties Normal and D instead of the indexer"],"exampleFix":"// before\nfor (int i = 0; i <= 4; i++) Console.WriteLine(plane[i]);\n// after\nfor (int i = 0; i < 4; i++) Console.WriteLine(plane[i]);","handlingStrategy":"validation","validationCode":"if (index >= 0 && index <= 3) { var c = plane[index]; }","typeGuard":"bool IsValidPlaneIndex(int i) => (uint)i <= 3u;","tryCatchPattern":"try { var c = plane[index]; }\ncatch (ArgumentOutOfRangeException ex) { /* ex.ParamName == \"index\"; fall back to default component */ }","preventionTips":["Loop with i < 4, not i <= 4","Use Normal.X/Y/Z and D properties instead of magic indices","Centralize component access in a helper that validates the index"],"tags":["mathematics","index-out-of-range","plane"],"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"}