Abstraction-bridges Berend Schotanus First Flamingo Enterprise B.V.
Contents • Background • Reductionism - Holism • Example: drawing curves in MapKit overlay
My Question: Snow, heat, autumn leaves... storm, bomb threat, signal passed at danger... How can the railway system go down like this, time after time?
What makes this device different? Not infallible... Yet it feels different, flexible, more natural, Less rigid. illustratie: apple-history.com
frequentist probability → Bayesianism analysis → computation homogeneous → composite predictive → explanatory on-to-many → many-to-many analysis → computation equation-based → simulation-based continuous → discrete realism → instrumentalism Aristotelian logic → many-valued logic reductionism → holism centralized → decentralized design → search objective → subjective isolation → interaction linear → non-linear physical law → theory → model deterministic → stochastic determinism → indeterminism abstract → detailed top-down → bottom-up one, two → many bron: A.B. Downey, Think Complexity
Reductionism illustratie: wikipedia/Alan Chia
Holism illustratie: brictechnic.fr illustratie: cjouets.fr
Abstraction-bridges Polyester LEGO-blocks Crane Construction-site Town low level of abstraction high level of abstraction
OS-X layered architecture (from: Apple documentation) Processor User low level of abstraction high level of abstraction
Lessons learned • Railways tend to think in one level of abstraction (timetable) • Finding and connecting appropriate levels of abstraction makes a system more flexible and resilient
Hardware Traffic control Timetable Train-service Traveller
Screen Scroll-view Map Infrastructure Train-service
Drawing curves (1) How to draw a curve on a map using the MapKit overlay API
Drawing curves (2) void CGPathAddArc ( = mapPointA CGMutablePathRef path, const CGAffineTransform *m, CGFloat x, CGFloat y, CGFloat radius, CGFloat startAngle, CGFloat endAngle, bool clockwise ); (x, y) = mapPointC = mapPointB
MapKit overlay drawMapRect:zoomScale:inContext: ask data whatever rendering subclass of protocol your data engine MKOverlayView MKOverlay struct CGPoint { typedef struct { typedef struct { CGFloat x; double x; CLLocationDegrees latitude; CGFloat y; double y; CLLocationDegrees longitude; }; } MKMapPoint; } CLLocationCoordinate2D; typedef struct CGPoint CGPoint;
Transformations CLLocationCoordinate2D MKCoordinateForMapPoint( - (MKMapPoint)mapPointForPoint:(CGPoint) point MKMapPoint mapPoint ); CLLocation CGPoint MKMapPoint Coordinate2D - (CGPoint)pointForMapPoint:(MKMapPoint) mapPoint MKMapPoint MKMapPointForCoordinate( CLLocationCoordinate2D coordinate );
Custom transformations PolarSize polarSizeFromCartesian(CGSize size) { � PolarSize result = polarSizeMake(0, pythagoras(size)); if (result.length > 0) { if (size.height > 0) { result.angle = acos(size.width/result.length); } else { result.angle = -acos(size.width/result.length); } } � return result; } struct CGSize { typedef struct { height CGFloat width; � double angle; CGFloat height; length � double length; }; } PolarSize; typedef struct CGSize CGSize; angle width CGSize cartesianSizeFromPolar(PolarSize polar) { � CGSize result; � result.width = polar.length * cos(polar.angle); � result.height = polar.length * sin(polar.angle); � return result; }
[overlayView drawRect] - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { RLARoute *route = (RLARoute*)self.overlay; CGMutablePathRef path = CGPathCreateMutable(); [route performOnAllMapPoints:^(MKMapPoint mapPointA, MKMapPoint mapPointB, MKMapPoint mapPointC){ CGPoint curveEnterPoint = [self pointForMapPoint:mapPointA]; CGPoint curveExitPoint = [self pointForMapPoint:mapPointB]; CGPoint curveCenterPoint = [self pointForMapPoint:mapPointC]; PolarSize curveEnterRadial = polarSizeFromCartesian(cartesianSizeFromLine(curveCenterPoint, curveEnterPoint)); PolarSize curveExitRadial = polarSizeFromCartesian(cartesianSizeFromLine(curveCenterPoint, curveExitPoint)); double deltaAngle = rangeMinusPiPlusPi(curveExitRadial.angle - curveEnterRadial.angle); CGPathAddArc(path, NULL, curveCenterPoint.x, curveCenterPoint.y, curveEnterRadial.length, curveEnterRadial.angle, curveExitRadial.angle, deltaAngle < 0); }]; CGContextAddPath(context, path); CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]); CGContextSetLineWidth(context, 1.0); CGContextStrokePath(context); CGPathRelease(path); }
Thank you! Berend Schotanus mail: BS@BSchotanus.nl web: http://firstflamingo.nl twitter: @schotanus
Recommend
More recommend