pvitkovsky
3/23/2018 - 8:45 AM

triangleSides_functional

functional interfaces for triangle side length; triangle area

	interface resABCD<Res, a, b, c, d> {
	    public Res apply(a A, b B, c C, d D);
	}
	
	interface resABCDEF<Res, a, b, c, d, e, f> {
	    public Res apply(a A, b B, c C, d D, e E, f F);
	}

	public static resABCD <Double, Double, Double, Double, Double> TriSide = (a, b, c, d) -> { 
	    	return Math.sqrt(Math.pow(a - b, 2) + Math.pow(c - d, 2));
	};

	public static resABCDEF <Double, Double, Double, Double, Double, Double, Double> TriArea = (aX, aY, bX, bY, cX, cY) -> { 
    	return Math.abs((aX - cX) *  (bY - aY) - (aX - bX) * (cY - aY)) / 2;
	};
	
	
	///Examples
	/*
	return TriSide.apply(this.getaX(), this.getbX(), this.getaY(), this.getbY());
	return TriArea.apply(super.getaX(), super.getaY(), this.getbX(), this.getbY(), this.getcX(), this.getcY());
	*/