Skip to content

Update of Typescript Types #4

Description

@ammanvedi

Hey and thank you for this library, i was also reading "Computation Geometry, Algorithms and Applications" and i was very confused by the type of tree they used there (with information only on the leaf nodes) and how to implement these algorithms with the normal tree (which is from what i can tell has been done here in the case of bentley-ottmann, but please correct me)

so this implementation has helped me alot !

Through usage i have noticed that the TS types could be improved;

I have posted below the declarations i am using locally, i have

  1. added types for options
  2. added types for individual functions in the format that they are exported
  3. i have added a generic param as i have noticed you can add your own metadata to the objects and get this served back to you in the results which i found useful. However i may be levaraging something i am not meant to here.

If its agreeable i will open a pr, just thought i would get some initial thoughts before i did this

Thanks again !

export type Position = {
        x: number;
        y: number;
    };

export type OutputSegment<SEGMENT_META extends MetaBase> = {
    dy: number;
    dx: number;
    angle: number;
} & InputSegment<SEGMENT_META>;

export type OutputIntersection<SEGMENT_META extends MetaBase> = {
    point: Position;
    segments: Array<OutputSegment<SEGMENT_META>>;
};

export type MetaBase = Record<string, any>;

export type InputSegment<SEGMENT_META extends MetaBase> = {
    from: Position;
    to: Position;
} & SEGMENT_META;

export type FunctionResult<SEGMENT_META extends MetaBase> = {
    run: () => Array<OutputIntersection<SEGMENT_META>>;
};

export type Options<SEGMENT_META extends MetaBase> = {
    onError?: () => void;
    onFound?: (intersection: OutputIntersection<SEGMENT_META>) => void;
};

export function sweep<SEGMENT_META extends MetaBase = MetaBase>(
    segments: Array<InputSegment<SEGMENT_META>>,
    opt?: Options<SEGMENT_META>,
): FunctionResult<SEGMENT_META>;

export function brute<SEGMENT_META extends MetaBase = MetaBase>(
    segments: Array<InputSegment<SEGMENT_META>>,
    opt?: Options<SEGMENT_META>,
): FunctionResult<SEGMENT_META>;

export function bush<SEGMENT_META extends MetaBase = MetaBase>(
    segments: Array<InputSegment<SEGMENT_META>>,
    opt?: Options<SEGMENT_META>,
): FunctionResult<SEGMENT_META>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions