soywiz-archive/korge-next

Circle defaults to BoxShape

Closed this issue · 0 comments

jobhh commented

If no Shape is specified the registerBodyWithFixture extension function in WorldView defaults to a CircleShape or BoxShape.
It only defaults to CircleShape when the View is an Ellipse and radiusX and radiusY are equal, essentially a circle.
However, because Circle is not a subclass of Ellipse, it defaults to BoxShape, making for odd interactions between objects.

Possible solutions:

  1. Refactor Circle ShapeView to be a subclass of Ellipse with equal radiusX and radiusY
  2. Remove Circle class and use extension functions to create an Ellipse with equal radiusX and radiusY when a circle is required
  3. Add a check if the view is Circle to the when statement in the WordView class

Option 3 will be the least work ;)

As an example, this code:

circle(50.0, Colors.RED)
  .registerBodyWithFixture(
    type = BodyType.DYNAMIC
  )

Reaches this code in the WorldView class:

when {
  view is Ellipse && view.isCircle -> CircleShape(view.radiusX / world.customScale)
  else -> BoxShape(getLocalBounds() / world.customScale)
}