public Dictionary<string, object> GetSideIntersections(Line intersectLine) { Point intersection1 = null; Line intersectSide1 = null; Point intersection2 = null; Line intersectSide2 = null; foreach(Line side in _sides) { Point possibleIntersection = intersectLine.GetIntersection(side); if(possibleIntersection!=null) { float lesserX = Math.Min(side.P1.X, side.P2.X); float greaterX = Math.Max(side.P1.X, side.P2.X); float lesserY = Math.Min(side.P1.Y, side.P2.Y); float greaterY = Math.Max(side.P1.Y, side.P2.Y); if(lesserX <= possibleIntersection.X && possibleIntersection.X <= greaterX && lesserY <= possibleIntersection.Y && possibleIntersection.Y <= greaterY) { if(intersection1==null) { intersection1 = possibleIntersection; intersectSide1 = side; } else if(!(possibleIntersection.X==intersection1.X && possibleIntersection.Y==intersection1.Y)) { intersection2 = possibleIntersection; intersectSide2 = side; } } } } Dictionary<string, object> result = new Dictionary<string, object>(); result.Add("point1", intersection1); result.Add("side1", intersectSide1); result.Add("point2", intersection2); result.Add("side2", intersectSide2); return result; }