Prozi / detect-collisions

Detect collisions between different shapes such as Points, Lines, Boxes, Polygons (including concave), Ellipses, and Circles. Features include RayCasting and support for offsets, rotation, scaling, bounding box padding, with options for static and trigger bodies (non-colliding).
https://prozi.github.io/detect-collisions/
MIT License
202 stars 21 forks source link

Types: improvement #55

Closed MeroVinggen closed 1 year ago

MeroVinggen commented 1 year ago

Add explicit params types for **system.create*** functions

otherways, user will need to make unnessecary types declarations, to setup types

such as:

export type BoxParams = {
  height: number;
  width: number;
  vector: Vector;
  options?: BodyOptions;
};

...

addBox({ ... }: BoxParams) {
  ...
}

or getting them by hard manipulations, using other TS Utilities

Prozi commented 1 year ago

hello @Mero-Plaform and thanks for opening an issue

did you see https://github.com/Prozi/detect-collisions#3-create-and-insert-body or https://prozi.github.io/detect-collisions/classes/System.html#createBox ?

the type you're looking for is BodyOptions https://prozi.github.io/detect-collisions/interfaces/BodyOptions.html

MeroVinggen commented 1 year ago

BodyOption contains only: angle, isCentered, isStatic, isTrigger, padding

but not the main props, such as vectors, height and so on

like:

Prozi commented 1 year ago

BodyOption contains only: angle, isCentered, isStatic, isTrigger, padding

but not the main props, such as vectors, height and so on

like:

  • position, width, height for createBox
  • position, radius for createCircle etc...

createBox(position: PotentialVector, width: number, height: number, options?: BodyOptions): Box

createCircle(position: PotentialVector, radius: number, options?: BodyOptions): Circle

the exact types for create* functions are there and are also documented

what is missing here?

I am missing the issue here

Prozi commented 1 year ago

once again I point to https://prozi.github.io/detect-collisions/classes/System.html documentation of API

Prozi commented 1 year ago

also note that

const box = new Box(position, width, height, options)

Box takes 4 parameters for constructor, from which last is optional

it is also noted here https://prozi.github.io/detect-collisions/classes/Box.html#constructor

it doesn't take one argument like you wrote:

addBox({ ... }: BoxParams) {

same goes with createBox, which also takes the same arguments, and is also documented like pointed above

MeroVinggen commented 1 year ago

I thought it over, it can't be solve the way I mean it, so I'm closing the issue