{"record":{"id":"94fa8b87b8150c16","repo":"BabylonJS/Babylon.js","slug":"can-not-negate-a-color","errorCode":null,"errorMessage":"Can not negate a color","messagePattern":"Can not negate a color","errorType":"exception","errorClass":"ReferenceError","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Maths/math.color.pure.ts","lineNumber":348,"sourceCode":"        return this.r === r && this.g === g && this.b === b;\r\n    }\r\n\r\n    /**\r\n     * Returns true if the current Color3 and the given color coordinates are distant less than epsilon\r\n     * @param otherColor defines the second operand\r\n     * @param epsilon defines the minimal distance to define values as equals\r\n     * @returns true if both colors are distant less than epsilon\r\n     */\r\n    public equalsWithEpsilon(otherColor: DeepImmutable<IColor3Like>, epsilon: number = Epsilon): boolean {\r\n        return WithinEpsilon(this.r, otherColor.r, epsilon) && WithinEpsilon(this.g, otherColor.g, epsilon) && WithinEpsilon(this.b, otherColor.b, epsilon);\r\n    }\r\n\r\n    /**\r\n     * @internal\r\n     * Do not use\r\n     */\r\n    public negate(): never {\r\n        throw new ReferenceError(\"Can not negate a color\");\r\n    }\r\n\r\n    /**\r\n     * @internal\r\n     * Do not use\r\n     */\r\n    public negateInPlace(): never {\r\n        throw new ReferenceError(\"Can not negate a color\");\r\n    }\r\n\r\n    /**\r\n     * @internal\r\n     * Do not use\r\n     */\r\n    public negateToRef(_result: IColor3Like): never {\r\n        throw new ReferenceError(\"Can not negate a color\");\r\n    }\r\n\r","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Maths/math.color.pure.ts#L330-L366","documentation":"Color3.negate is an intentional stub that throws ReferenceError(\"Can not negate a color\"). Producing a negated (inverted-sign) color is not a supported operation in this API. Every call throws; there is no valid path.","triggerScenarios":"Calling color3.negate() directly expecting -color, or generic math code that negates any vector-like operand including colors.","commonSituations":"Reversing/diffing computations ported from Vector3 code; mistaking negate for color inversion (complement); autocomplete-driven misuse.","solutions":["If you want the color complement, compute new Color3(1-r, 1-g, 1-b).","If you truly need negated components, construct manually: new Color3(-c.r, -c.g, -c.b).","Use a Vector3 for full negation support.","Do not assume Color3 implements every Vector3 method."],"exampleFix":"// before\nconst inverted = color.negate();\n// after\nconst inverted = new Color3(1 - color.r, 1 - color.g, 1 - color.b); // complement\n// or true negation:\nconst negated = new Color3(-color.r, -color.g, -color.b);","handlingStrategy":"validation","validationCode":"if (color instanceof Color3) {\n  var inverted = new Color3(1 - color.r, 1 - color.g, 1 - color.b);\n} else {\n  var inverted = color.negate();\n}","typeGuard":"function isColor3(c: unknown): c is Color3 {\n  return c instanceof Color3;\n}","tryCatchPattern":"try {\n  inverted = color.negate();\n} catch (e) {\n  if (e instanceof ReferenceError && e.message === 'Can not negate a color') {\n    inverted = new Color3(1 - color.r, 1 - color.g, 1 - color.b);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use per-channel complement (1 - value) for color inversion instead of negate().","Clarify intent: negation (sign flip) vs inversion (complement) differ.","Use Vector3 when sign negation is genuinely required.","Never call @internal Do-not-use stubs on Color3."],"tags":["color3","unsupported-operation","math","reference-error"],"backgroundTag":"unsupported-color-operation","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}