{"record":{"id":"85f3cc9d2a8a6299","repo":"stride3d/stride","slug":"indices-for-double2-run-from-0-to-1-inclusive","errorCode":null,"errorMessage":"Indices for Double2 run from 0 to 1, inclusive.","messagePattern":"Indices for Double2 run from 0 to 1, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Double2.cs","lineNumber":125,"sourceCode":"        get { return Math.Abs((X * X) + (Y * Y) - 1f) < MathUtil.ZeroTolerance; }\n    }\n\n    /// <summary>\n    /// Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the X or Y component, depending on the index.</value>\n    /// <param name=\"index\">The index of the component to access. Use 0 for the X component and 1 for the Y component.</param>\n    /// <returns>The value of the component at the specified index.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when the <paramref name=\"index\"/> is out of the range [0, 1].</exception>\n    public double this[int index]\n    {\n        readonly get\n        {\n            return index switch\n            {\n                0 => X,\n                1 => Y,\n                _ => throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Double2 run from 0 to 1, inclusive.\"),\n            };\n        }\n\n        set\n        {\n            switch (index)\n            {\n                case 0: X = value; break;\n                case 1: Y = value; break;\n                default: throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Double2 run from 0 to 1, inclusive.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Casts from System.Numerics to Stride.Maths vectors\n    /// </summary>\n    /// <param name=\"v\">Value to cast</param>","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Double2.cs#L107-L143","documentation":"The Double2 indexer bounds-checks the index parameter and throws ArgumentOutOfRangeException when the index is not 0 or 1. It is a guard on component access: 0 maps to the X component and 1 to Y, and since Double2 has only two components, any other index (negative or >= 2) is rejected.","triggerScenarios":"Reading vector[index] where index < 0 or index > 1, e.g. vector[2] in a loop written for a 3- or 4-component vector type.","commonSituations":"Generic vector-processing code with a hardcoded component count of 3 or 4 applied to a 2D vector; off-by-one loops (i <= 2); copy-pasted code from Double3/Double4.","solutions":["Use index 0 (X) or 1 (Y) only.","Fix loop bounds to i < 2, or use the vector's component count genericly.","Access .X/.Y properties directly when the component is known."],"exampleFix":"// before\nfor (int i = 0; i < 3; i++) sum += v[i];\n// after\nfor (int i = 0; i < 2; i++) sum += v[i];","handlingStrategy":"validation","validationCode":"if (index < 0 || index > 1) throw new ArgumentOutOfRangeException(nameof(index));\nvar c = vector[index];","typeGuard":"bool IsValidVector2Index(int i) => i is 0 or 1;","tryCatchPattern":"try { var c = v[i]; }\ncatch (ArgumentOutOfRangeException ex) { /* default component or skip */ }","preventionTips":["Use .X/.Y properties instead of the indexer.","Bound component loops by the actual vector dimension (2).","Do not reuse loops written for Double3/Double4 on Double2."],"tags":["argument-out-of-range","indexer","csharp","vector"],"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"}