package com.orionplatform.math.geometry.point.tasks.relocation;

import com.orionplatform.core.abstraction.Orion;
import com.orionplatform.math.geometry.point.Point;
import com.orionplatform.math.geometry.point.PointRules;
import com.orionplatform.math.geometry.shape.line.Line;
import com.orionplatform.math.geometry.shape.line.LineRules;
import com.orionplatform.math.number.ANumber;

public class ReflectPointAboutLineTask extends Orion
{
    public static synchronized Point run(Point p, Line line)
    {
        PointRules.isValid(p);
        LineRules.isValid(line);
        ANumber aSquaredPlusBSquared = line.getA().squareGET().addGET(line.getB().squareGET());
        ANumber x = p.getX().multiplyGET(line.getA().squareGET().subtractGET(line.getB().squareGET()));
        x.subtract(line.getB().doubleGET().multiplyGET(line.getA().multiplyGET(p.getY()).addGET(line.getC())));
        x.divide(aSquaredPlusBSquared);
        ANumber y = p.getY().multiplyGET(line.getB().squareGET().subtractGET(line.getA().squareGET()));
        y.subtract(line.getA().doubleGET().multiplyGET(line.getB().multiplyGET(p.getX()).addGET(line.getC())));
        y.divide(aSquaredPlusBSquared);
        return Point.of(x, y);
    }
}