{"record":{"id":"21f2a3b7d087ed3a","repo":"Yalantis/uCrop","slug":"cross-instance-and-or-specified-image-u-u-u","errorCode":null,"errorMessage":"cross(): Instance and/or specified image (%u,%u,%u,%u,%p) are not 3D vectors.","messagePattern":"cross\\(\\): Instance and/or specified image \\(%u,%u,%u,%u,%p\\) are not 3D vectors\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":32805,"sourceCode":"        return *this;\n      }\n      return get_transpose().move_to(*this);\n    }\n\n    //! Transpose the image, viewed as a matrix \\newinstance.\n    CImg<T> get_transpose() const {\n      return get_permute_axes(\"yxzc\");\n    }\n\n    //! Compute the cross product between two \\c 1x3 images, viewed as 3D vectors.\n    /**\n       \\param img Image used as the second argument of the cross product.\n       \\note The first argument of the cross product is \\c *this.\n     **/\n    template<typename t>\n    CImg<T>& cross(const CImg<t>& img) {\n      if (_width!=1 || _height<3 || img._width!=1 || img._height<3)\n        throw CImgInstanceException(_cimg_instance\n                                    \"cross(): Instance and/or specified image (%u,%u,%u,%u,%p) are not 3D vectors.\",\n                                    cimg_instance,\n                                    img._width,img._height,img._depth,img._spectrum,img._data);\n\n      const T x = (*this)[0], y = (*this)[1], z = (*this)[2];\n      (*this)[0] = (T)(y*img[2] - z*img[1]);\n      (*this)[1] = (T)(z*img[0] - x*img[2]);\n      (*this)[2] = (T)(x*img[1] - y*img[0]);\n      return *this;\n    }\n\n    //! Compute the cross product between two \\c 1x3 images, viewed as 3D vectors \\newinstance.\n    template<typename t>\n    CImg<_cimg_Tt> get_cross(const CImg<t>& img) const {\n      return CImg<_cimg_Tt>(*this).cross(img);\n    }\n\n    //! Invert the instance image, viewed as a matrix.","sourceCodeStart":32787,"sourceCodeEnd":32823,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L32787-L32823","documentation":"CImg::cross() computes the cross product treating the instance and the argument as 3D vectors, which requires both to be column-ish vectors of width 1 and height>=3. The library throws CImgInstanceException naming the offending image's dimensions when either operand violates this.","triggerScenarios":"Calling a.cross(b) where a or b has width!=1, or height<3 (e.g. row vectors 1x3, 2D points of height 2, or full 2D matrices).","commonSituations":"Storing vectors as 1x3 row vectors (CImg convention is width=1, height=3 for a column vector); using 2-element 2D points; accidentally passing an image instead of a vector.","solutions":["Ensure both operands have shape (1,3): assign(w,h) as img.assign(1,3).","Transpose a 1x3 row vector: a.get_transpose().cross(b).","Use a 3-element constructor: CImg<float> v(1,3,1,1, x,y,z)."],"exampleFix":"// before\nCImg<float> a(3,1,1,1,1,0,0), b(3,1,1,1,0,1,0); // row vectors\na.cross(b); // throws\n// after\nCImg<float> a(1,3,1,1,1,0,0), b(1,3,1,1,0,1,0);\na.cross(b);","handlingStrategy":"validation","validationCode":"if (a.width()!=1 || a.height()<3 || b.width()!=1 || b.height()<3) throw std::runtime_error(\"cross() operands must be 1x3 vectors\");","typeGuard":"bool isVec3(const CImg<T>& v){ return v.width()==1 && v.height()>=3; }","tryCatchPattern":"try { a.cross(b); } catch (CImgInstanceException& e) { std::cerr << e.what() << '\\n'; }","preventionTips":["Store 3D vectors as CImg<T>(1,3) column vectors in CImg","Transpose 1x3 row vectors before cross()","Do not pass plain images to vector operations"],"tags":["cimg","vector","cross-product","dimensions"],"backgroundTag":"shape-mismatch","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}