class PenaltyArea implements IPenaltyArea {

	@Override
	public double intersectionArea(final IVector2 from, final IVector2 to)
	{
		if (isBehindPenaltyArea(from) || isBehindPenaltyArea(to))
		{
			return depth * length * 1e-6;
		}

		ILineSegment line = Lines.segmentFromPoints(
				rectangle.nearestPointOutside(from), rectangle.nearestPointOutside(to));
		List<IVector2> intersections = rectangle.lineIntersections(line);
		if (intersections.size() != 2)
		{
			return 0;
		}
		IVector2 p1 = intersections.get(0);
		IVector2 p2 = intersections.get(1);

		if (SumatraMath.isEqual(p1.x(), goalCenterX) || SumatraMath.isEqual(p2.x(), goalCenterX))
		{
			return depth * length * 1e-6;
		}

		double frontX = goalCenterX - Math.signum(goalCenterX) * depth;
		double dp1 = Math.abs(frontX - p1.x());
		double dp2 = Math.abs(frontX - p2.x());
		double dMin = Math.min(dp1, dp2);
		double a = Math.max(dp1, dp2) - dMin;
		double l = Math.abs(p1.y() - p2.y());
		return (l * dMin + l * a * 0.5) * 1e-6;
	}

	public  PenaltyArea(final IVector2 goalCenter, final double depth, final double length);

}