import { Arc3d } from "../curve/Arc3d"; import { AnnounceNumberNumber, AnnounceNumberNumberCurvePrimitive, CurvePrimitive } from "../curve/CurvePrimitive"; import { Point3d } from "../geometry3d/Point3dVector3d"; import { Range3d } from "../geometry3d/Range"; import { Transform } from "../geometry3d/Transform"; import { TransformProps, XYZProps } from "../geometry3d/XYZProps"; import { Matrix4d } from "../geometry4d/Matrix4d"; import { Clipper, ClipPlaneContainment } from "./ClipUtils"; import { ConvexClipPlaneSet } from "./ConvexClipPlaneSet"; import { UnionOfConvexClipPlaneSets, UnionOfConvexClipPlaneSetsProps } from "./UnionOfConvexClipPlaneSets"; /** * Bit mask type for referencing subsets of 6 planes of range box. * @public */ export declare enum ClipMaskXYZRangePlanes { /** no planes */ None = 0, /** low x plane */ XLow = 1, /** high x plane */ XHigh = 2, /** low y plane */ YLow = 4, /** high y plane */ YHigh = 8, /** low z plane */ ZLow = 16, /** high z plane */ ZHigh = 32, /** all x and y planes, neither z plane */ XAndY = 15, /** all 6 planes */ All = 63 } /** * Wire format describing a [[ClipPrimitive]] defined by a set of clip planes. * @public */ export interface ClipPrimitivePlanesProps { planes?: { /** The set of clip planes. */ clips?: UnionOfConvexClipPlaneSetsProps; /** `true` if the primitive is invisible. */ invisible?: boolean; }; } /** * Wire format describing a [[ClipShape]]. * @public */ export interface ClipPrimitiveShapeProps { /** The clip polygon. */ shape?: { /** Points of the polygon, in the xy plane of the local coordinate system. */ points?: XYZProps[]; /** Transform from local to world. */ trans?: TransformProps; /** Lower bound on z (in local coordinates). */ zlow?: number; /** Upper bound on z (in local coordinates). */ zhigh?: number; /** `true` if this shape is considered a hole (keep geometry outside of the polygon). */ mask?: boolean; /** `true` if this shape is invisible. */ invisible?: boolean; }; } /** Wire format describing a [[ClipPrimitive]]. * @public */ export type ClipPrimitiveProps = ClipPrimitivePlanesProps | ClipPrimitiveShapeProps; /** * * ClipPrimitive is a base class for clipping implementations that use: * * A [[UnionOfConvexClipPlaneSets]] designated "clipPlanes". * * An "invisible" flag. * * A ClipPrimitive can be constructed with or without planes. If without planes: * * The derived class is responsible for filling the plane sets. * * The derived class can populate the plane sets at construction time or afterwards with [[ClipPrimitive.ensurePlaneSets]]. * * The prevailing use is via derived class [[ClipShape]]. * * A ClipShape carries a swept shape that generates the planes. * * A ClipShape has an `isMask` property * * `isMask === false` means the plane sets should cover the inside of its polygon. * * `isMask === true` means the plane sets should cover the outside of its polygon, i.e., the ClipShape acts as a hole. * * Note that the ClipShape's `isMask` property and the ClipPrimitive's `invisible` property are distinct flags. * * In normal usage, callers get "outside" clip behavior using ONLY the ClipShape `isMask` property. * * The ClipShape passes its `invisible` flag down to ClipPlanes that it creates. * * At that level, this flag controls whether cut edges are produced on the planes. * @public */ export declare class ClipPrimitive implements Clipper { /** The union of convex regions. */ protected _clipPlanes?: UnionOfConvexClipPlaneSets; /** The invisible flag of the primitive, passed down to the clip planes. */ protected _invisible: boolean; /** * Get a reference to the `UnionOfConvexClipPlaneSets`. * * It triggers construction of the sets by `this.ensurePlaneSets()`. * * Derived class typically caches the set on the first such call. */ fetchClipPlanesRef(): UnionOfConvexClipPlaneSets | undefined; /** Return whether this primitive is invisible. */ get invisible(): boolean; protected constructor(planeSet?: UnionOfConvexClipPlaneSets | undefined, isInvisible?: boolean); /** * Create a ClipPrimitive, capturing the supplied plane set as the clip planes. * @param planes clipper * @param isInvisible set the invisible flag on the ClipPrimitive */ static createCapture(planes: UnionOfConvexClipPlaneSets | ConvexClipPlaneSet | undefined, isInvisible?: boolean): ClipPrimitive; /** Emit json form of the clip planes */ toJSON(): ClipPrimitiveProps; /** * Returns true if the planes are present. * * This can be false (for instance) if a ClipShape is holding a polygon but has not yet been asked to construct * the planes. */ arePlanesDefined(): boolean; /** Return a deep clone. */ clone(): ClipPrimitive; /** * Trigger (if needed) computation of plane sets (if applicable) in the derived class. * * Base class is no op. * * In derived class, on first call create planes sets from defining data (e.g. swept shape). * * In derived class, if planes are present leave them alone. */ ensurePlaneSets(): void; /** * Return true if the point lies inside/on this polygon (or not inside/on if this polygon is a mask). Otherwise, * return false. * * Note that a derived class may choose to (a) implement its own test using its defining data, or (b) accept * this implementation using planes that it inserted in the base class. */ pointInside(point: Point3d, onTolerance?: number): boolean; /** * Method from [[Clipper]] interface. * * Implement as dispatch to clipPlaneSets as supplied by derived class. */ isPointOnOrInside(point: Point3d, onTolerance?: number): boolean; /** * Method from [[Clipper]] interface. * * Implement as dispatch to clip volume as supplied by derived class. */ announceClippedSegmentIntervals(f0: number, f1: number, pointA: Point3d, pointB: Point3d, announce?: AnnounceNumberNumber): boolean; /** * Method from [[Clipper]] interface. * * Implement as dispatch to clip volume as supplied by derived class. */ announceClippedArcIntervals(arc: Arc3d, announce?: AnnounceNumberNumberCurvePrimitive): boolean; /** * Method from [[Clipper]] interface. * * Implement as dispatch to clip volume as supplied by derived class. */ announceClippedCurveIntervals(curve: CurvePrimitive, announce?: AnnounceNumberNumberCurvePrimitive): boolean; /** * Multiply all ClipPlanes DPoint4d by matrix. * @param matrix matrix to apply. * @param invert if true, use in verse of the matrix. * @param transpose if true, use the transpose of the matrix (or inverse, per invert parameter). * @param matrix matrix to apply. * * Note that if matrixA is applied to all of space, the matrix to send to this method to get a corresponding * effect on the plane is the inverse transpose of matrixA. * * Callers that will apply the same matrix to many planes should pre-invert the matrix for efficiency. * * Both params default to true to get the full effect of transforming space. */ multiplyPlanesByMatrix4d(matrix: Matrix4d, invert?: boolean, transpose?: boolean): boolean; /** Apply a transform to the clipper (e.g. transform all planes). */ transformInPlace(transform: Transform): boolean; /** Sets the primitive visibility. */ setInvisible(invisible: boolean): void; /** * Return true if any plane of the primary clipPlanes has (a) non-zero z component in its normal vector and * (b) finite distance from origin. */ containsZClip(): boolean; /** * Quick test of whether the given points fall completely inside or outside. * @param points points to test. * @param _ignoreMasks unused. The [[ClipShape]] override inverts this test when `ignoreMasks` is false and the instance is masked. */ classifyPointContainment(points: Point3d[], _ignoreMasks?: boolean): ClipPlaneContainment; /** * Promote json object form to class instance. * * First try to convert to a ClipShape. * * then try as a standalone instance of the base class ClipPrimitive. */ static fromJSON(json: ClipPrimitiveProps | undefined): ClipPrimitive | undefined; /** Specific converter producing the base class ClipPrimitive. */ static fromJSONClipPrimitive(json: ClipPrimitivePlanesProps | undefined): ClipPrimitive | undefined; } /** * A clipping volume defined by a shape (an array of 3d points using only x and y dimensions). * May be given either a ClipPlaneSet to store directly, or an array of polygon points as well as other parameters * for parsing ClipPlanes from the shape later. * @public */ export declare class ClipShape extends ClipPrimitive { /** Points of the polygon, in the xy plane of the local coordinate system. */ protected _polygon: Point3d[]; /** Optional low z (in local coordinates). */ protected _zLow?: number; /** Optional high z (in local coordinates). */ protected _zHigh?: number; /** True if this is considered a hole (keep geometry outside of the polygon). */ protected _isMask: boolean; /** Transform from local to world. */ protected _transformFromClip?: Transform; /** Transform from world to local. */ protected _transformToClip?: Transform; protected constructor(polygon?: Point3d[], zLow?: number, zHigh?: number, transform?: Transform, isMask?: boolean, invisible?: boolean); /** Returns true if this ClipShape is marked as invisible. */ get invisible(): boolean; /** Return local to world transform, which may be undefined. */ get transformFromClip(): Transform | undefined; /** Return world to local transform, which may be undefined. */ get transformToClip(): Transform | undefined; /** * Returns true if this ClipShape has a local to world transform. * @see type guards [[hasTransformFromClip]], [[hasTransformToClip]], and [[hasTransforms]]. */ get transformValid(): boolean; /** * Returns true if this ClipShape's lower z boundary is set. * @see type guard [[hasZLow]]. */ get zLowValid(): boolean; /** * Returns true if this ClipShape's upper z boundary is set. * @see type guard [[hasZHigh]]. */ get zHighValid(): boolean; /** * Return true if this ClipShape has a local to world transform * @deprecated in 5.5.0 - will not be removed until after 2027-01-05. Use duplicate property [[transformValid]] or * type guard [[hasTransformFromClip]] instead. */ get transformIsValid(): boolean; /** Type guard for [[zLow]]. */ hasZLow(): this is { zLow: number; }; /** Type guard for [[zHigh]]. */ hasZHigh(): this is { zHigh: number; }; /** * Type guard for [[transformFromClip]]. * @see related type guards [[hasTransformToClip]] and [[hasTransforms]]. */ hasTransformFromClip(): this is { transformFromClip: Transform; }; /** * Type guard for [[transformToClip]]. * @see related type guards [[hasTransformFromClip]] and [[hasTransforms]]. */ hasTransformToClip(): this is { transformToClip: Transform; }; /** * Type guard for both [[transformFromClip]] and [[transformToClip]]. * @see individual type guards [[hasTransformFromClip]] and [[hasTransformToClip]]. */ hasTransforms(): this is { transformFromClip: Transform; transformToClip: Transform; }; /** Return this zLow, which may be undefined. */ get zLow(): number | undefined; /** Return this zHigh, which may be undefined. */ get zHigh(): number | undefined; /** Returns a reference to this ClipShape's polygon array. */ get polygon(): Point3d[]; /** Returns true if this ClipShape is a masking set. */ get isMask(): boolean; /** Sets the polygon points array of this ClipShape to the array given (by reference). */ setPolygon(polygon: Point3d[]): void; /** * If the ClipShape's associated `UnionOfConvexClipPlaneSets` is defined, do nothing. * If the ClipShape's associated `UnionOfConvexClipPlaneSets` is undefined, generate it from the `ClipShape` * and transform. */ ensurePlaneSets(): void; /** * Initialize the members of the ClipShape class that may at times be undefined. * zLow and zHigh default to Number.MAX_VALUE, and the transform defaults to an identity transform. */ initSecondaryProps(isMask: boolean, zLow?: number, zHigh?: number, transform?: Transform): void; /** Emit json object form */ toJSON(): ClipPrimitiveShapeProps; /** Parse `json` to a clip shape. */ static fromClipShapeJSON(json: ClipPrimitiveShapeProps | undefined, result?: ClipShape): ClipShape | undefined; /** Returns a new ClipShape that is a deep copy of the ClipShape given */ static createFrom(other: ClipShape, result?: ClipShape): ClipShape; /** Create a new ClipShape from an array of points that make up a 2d shape (stores a deep copy of these points). */ static createShape(polygon?: Point3d[], zLow?: number, zHigh?: number, transform?: Transform, isMask?: boolean, invisible?: boolean, result?: ClipShape): ClipShape | undefined; /** * Create a ClipShape that exists as a 3 dimensional box of the range given. Optionally choose to * also store this shape's zLow and zHigh members from the range through the use of a RangePlaneBitMask. */ static createBlock(extremities: Range3d, clipMask: ClipMaskXYZRangePlanes, isMask?: boolean, invisible?: boolean, transform?: Transform, result?: ClipShape): ClipShape; /** Creates a new ClipShape with undefined members and a polygon points array of zero length. */ static createEmpty(isMask?: boolean, invisible?: boolean, transform?: Transform, result?: ClipShape): ClipShape; /** Checks to ensure that the member polygon has an area, and that the polygon is closed. */ get isValidPolygon(): boolean; /** Returns a deep copy of this instance of ClipShape, storing in an optional result. */ clone(result?: ClipShape): ClipShape; /** * Given the current polygon data, parses clip planes that together form an object, storing the result in * the set given, either clip planes or mask planes. */ private parseClipPlanes; /** * Given a start and end point, populate the given UnionOfConvexClipPlaneSets with ConvexClipPlaneSets * defining the bounded region of linear planes. Returns true if successful. * * This handles the degenerate 2-point polygon case, e.g., select by line. See [[parseConvexPolygonPlanes]]. */ private parseLinearPlanes; /** * Given a convex polygon defined as an array of points, populate the given UnionOfConvexClipPlaneSets with * ConvexClipPlaneSets defining the bounded region. Returns true if successful. * @param polygon convex polygon with closure point. z-coordinates are ignored. * @param direction whether the area described by the polygon is found on its directed edges' left (nonnegative) or * right (negative). Typically this is positive for CCW xy-polygons. * @param buildExteriorClipper whether the returned clippers represent the xy-region *outside* the polygon. * When this is true, `direction` is typically set accordingly. For example, for a CCW polygon, to return clippers * for the exterior region, pass `direction < 0` and `buildExteriorClipper = true`. Currently not implemented for * camera view. */ private parseConvexPolygonPlanes; /** * Given a (possibly non-convex) polygon defined as an array of points, populate the given UnionOfConvexClipPlaneSets * with multiple ConvexClipPlaneSets defining the bounded region. Returns true if successful. */ private parsePolygonPlanes; /** * Multiply all ClipPlanes DPoint4d by matrix. * @param matrix matrix to apply. * @param invert if true, use in verse of the matrix. * @param transpose if true, use the transpose of the matrix (or inverse, per invert parameter). * @param matrix matrix to apply. * * Note that if matrixA is applied to all of space, the matrix to send to this method to get a corresponding effect * on the plane is the inverse transpose of matrixA. * * Callers that will apply the same matrix to many planes should pre-invert the matrix for efficiency. * * Both params default to true to get the full effect of transforming space. */ multiplyPlanesByMatrix4d(matrix: Matrix4d, invert?: boolean, transpose?: boolean): boolean; /** * Apply `transform` to the local to world (`transformFromClip`) transform. * * The world to local transform (`transformToClip` is recomputed from the (changed) `transformToClip` * * the transform is passed to the base class to be applied to clip plane form of the clipper. */ transformInPlace(transform: Transform): boolean; /** * Return true if * * at least one point is defined * * The local to world transform (transformFromClip) either * * is undefined * * has no xy parts in its column Z (local frame Z is parallel to global Z) */ get isXYPolygon(): boolean; /** Transform the input point in place using this instance's `transformToClip` member */ performTransformToClip(point: Point3d): void; /** Transform the input point in place using this instance's `transformFromClip` member */ performTransformFromClip(point: Point3d): void; /** * Quick test of whether the given points fall completely inside or outside. * @param points points to test. * @param ignoreMasks if false, invert the containment test on a masked (hole) instance; otherwise perform the containment test as usual. */ classifyPointContainment(points: Point3d[], ignoreMasks: boolean): ClipPlaneContainment; } //# sourceMappingURL=ClipPrimitive.d.ts.map