Query that Resolves to nothing != qNothing()

Jonathan_Hutchinson
Jonathan_Hutchinson Member Posts: 162 PRO
edited July 2023 in FeatureScript
I stumbled on some strange behaviour I couldn't figure out. What I thought was quite a straightforward conditional where I do a qSubtraction, resolved weirdly. As below.

                const allGeom = qCreatedBy(id + "extrudeThin", EntityType.FACE);
                const planeGeom = qGeometry(qCreatedBy(id + "extrudeThin", EntityType.FACE), GeometryType.PLANE);
                const curvedGeom = qSubtraction(allGeom, planeGeom);

                debug(context, allGeom, DebugColor.RED);
                debug(context, planeGeom, DebugColor.RED);
                debug(context, curvedGeom, DebugColor.RED);

                if (curvedGeom != qNothing())
                {
                    println("is something");
                }

                else
                {
                    println("is nothing");
                }

Returned in the console:

debug: Query resolves to 6 faces
debug: Query resolves to 6 faces
debug: Query resolves to nothing >>> (curvedGeom variable)
is something >>> (curvedGeom variable, resolves to nothing but isn't equal to qNothing?)

My workaround is to evaluate the query and test if it's equal to an empty array. But I thought equality to qNothing was possible?
Tagged:

Comments

  • Jacob_Corder
    Jacob_Corder Member Posts: 141 PRO
    qNothing is a query structure and is only the same as another qNothing(). An empty query will not resolve to qNothing() it will return [] from evaluateQuery and false with isQueryEmpty. To solve your current code, the fastest ways is
    if(isQueryEmpty(curvedGeom)==false)
    {

    }

    so, use isQueryEmpty(curvedGeom)
  • Jonathan_Hutchinson
    Jonathan_Hutchinson Member Posts: 162 PRO
    edited July 2023
    Ah, thank you! I don't know why I had it in my head that comparing to a qNothing would help me out.
  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    Or, even more succinct:

    if(!isQueryEmpty(curvedGeom))
    {

    }
    Senior Director, Technical Services, EMEA