Added boundary safeguards to getSegmentData and getSegmentLocations. New function for area calculation.