/*
 * Circle.java
 *
 * Circular-shaped model to support collisions.
 *
 * A circle is different from an ellipse in that it has the same dimensions along
 * all axes.  This a big difference, as it means that we do not need to model
 * them with polygons, so we can be much more exact on the shape.
 *
 * @author Walker M. White
 * @version 3/9/2025
 */
package edu.cornell.cis3152.box2d.shape;

import com.badlogic.gdx.math.*;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.physics.box2d.*;

import edu.cornell.cis3152.box2d.*;  // For Entity
import edu.cornell.gdiac.math.Poly2;
import edu.cornell.gdiac.math.PolyFactory;

/**
 * A circular physics object.
 */
public class Circle extends Entity {
	/** Shape information for this ellipse */
	protected CircleShape shape;

	/**
	 * Creates a new ellipse, but do not initialize it yet.
	 */
	public Circle() {}

	/**
     * Creates the collision shape information
     *
     * @param size The object bounding box
     */
	protected void makeFixture(Vector2 size) {
		shape = new CircleShape();
		shape.setRadius(Math.min(size.x, size.y)/2.0f);

		// Create the fixture
		FixtureDef def = new FixtureDef();
		def.density = density;
		def.friction = friction;
		def.restitution = restitution;
		def.shape = shape;

		fixture = body.createFixture(def);
		shape.dispose(); // Do not need it anymore
	}

	/**
     * Creates the drawing shape information
     *
     * @param size  The object bounding box
     */
	protected void makeGraphics(Vector2 size) {
        float r = (size.x < size.y ? size.x : size.y)/2.0f;
        PolyFactory factory = new PolyFactory();
        poly = factory.makeCircle( Vector2.Zero, r*units );
    }
}
