"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeometryQuery = void 0;
const Range_1 = require("../geometry3d/Range");
const Transform_1 = require("../geometry3d/Transform");
/**
 * Queries to be supported by Curve, Surface, and Solid objects.
 * * `GeometryQuery` is an abstract base class with (abstract) methods for querying curve, solid primitive, mesh,
 * and bspline surfaces.
 * @public
 */
class GeometryQuery {
    /** Return the range of the entire GeometryQuery tree. */
    range(transform, result) {
        if (result)
            result.setNull();
        const range = result ? result : Range_1.Range3d.createNull();
        this.extendRange(range, transform);
        return range;
    }
    /** Try to move the geometry by dx,dy,dz. */
    tryTranslateInPlace(dx, dy = 0.0, dz = 0.0) {
        return this.tryTransformInPlace(Transform_1.Transform.createTranslationXYZ(dx, dy, dz));
    }
    /**
     * Return GeometryQuery children for recursive queries.
     * * leaf classes do not need to implement.
     */
    get children() {
        return undefined;
    }
    /**
     * Test for exact structure and nearly identical geometry.
     * *  Leaf classes must implement.
     * *  Base class implementation recurses through children.
     * *  Base implementation is complete for classes with children and no properties.
     * *  Classes with both children and properties must implement for properties, call super for children.
     */
    isAlmostEqual(other) {
        if (this.isSameGeometryClass(other)) {
            const childrenA = this.children;
            const childrenB = other.children;
            if (childrenA && childrenB) {
                if (childrenA.length !== childrenB.length)
                    return false;
                for (let i = 0; i < childrenA.length; i++) {
                    if (!childrenA[i].isAlmostEqual(childrenB[i]))
                        return false;
                }
                return true;
            }
            else if (childrenA || childrenB) { // CurveCollections start with empty arrays for children so these null pointer cases are never reached.
                return false; // plainly different
            }
            else {
                return true; // both children null; call it equal
            }
        }
        return false;
    }
    /**
     * Apply instance method [[isAlmostEqual]] if both are defined.
     * * Both undefined returns true.
     * * Single defined returns false.
     */
    static areAlmostEqual(a, b) {
        if (a instanceof GeometryQuery && b instanceof GeometryQuery)
            return a.isAlmostEqual(b);
        if ((a === undefined) && (b === undefined))
            return true;
        return false;
    }
}
exports.GeometryQuery = GeometryQuery;
//# sourceMappingURL=GeometryQuery.js.map