/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hyperbolicbrowser.geometriccontrollers;

import hyperbolicbrowser.geometricmodels.HyperboloidSpace;
import hyperbolicbrowser.geometricmodels.geometricobjects.points.*;

import java.util.List;

/**
 *
 * @author Rousselle Rémi (remi.rousselle@isen-lille.fr)
 */
public class BeltramiDiskController extends GeometricController {

    public BeltramiDiskController(HyperboloidSpace space) {
        super(space);
    }

    @Override
    public void translatePoints(EuclideanPoint clickedComplex) {
        HyperboloidPoint hypPoint;

        PoincareDiskPoint complexP;
        clickedComplex.setPolar(clickedComplex.getRadius()/2d, clickedComplex.getAngle());
        for (GeometricPoint point : model.getPoints()) {
            if (point instanceof HyperboloidPoint) {
                hypPoint = (HyperboloidPoint) point;
                complexP = hypPoint.toPoincareDiskPoint();
                complexP.translate(clickedComplex);
                hypPoint.setCoords(complexP.toHyperboloid());
                model.firePointMovedEvent(point);
            }
        }
    }

    @Override
    public void rotate(EuclideanPoint clickedComplex) {
        HyperboloidPoint hTmp;

        BeltramiDiskPoint complexP;
        double angleRotation = -1d * clickedComplex.getAngle();
        for (GeometricPoint p : model.getPoints()) {
            if (p instanceof HyperboloidPoint) {
                hTmp = (HyperboloidPoint) p;
                complexP = hTmp.toBeltramiDiskPoint();
                complexP.rotate(angleRotation);
                hTmp.setCoords(complexP.toHyperboloid());
                model.firePointMovedEvent(p);
            }
        }
    }

    @Override
    public SimpleEuclideanPoint hyperboloidToHyperbolicModel(HyperboloidPoint p) {
        return p.toBeltramiDiskPoint();
    }

    @Override
    public HyperboloidPoint hyperbolicModelPointToHyperboloid(SimpleEuclideanPoint beltramiDiskPoint) {
        return beltramiDiskPoint.toHyperboloid();
    }

    @Override
    public double distanceSegmentHyperbolic(SimpleEuclideanPoint p, SimpleEuclideanPoint q) {
        return p.distance(q);
    }
    
    @Override
	public double getAngle(EuclideanPoint complexPoint) {
		return complexPoint.getAngle();
	}

    @Override
    public SimpleEuclideanPoint getMiddlePoint(SimpleEuclideanPoint p1, SimpleEuclideanPoint p2) {
        return p1.getMiddlePoint(p2);
    }
}
