Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Sketch Curves, Boulder iOS Meetup April, 2018

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Avatar for Zach Zach
April 23, 2018

Sketch Curves, Boulder iOS Meetup April, 2018

Slides from Boulder iOS Meetup, 2018 from Paul Hollingshead

Avatar for Zach

Zach

April 23, 2018

Other Decks in Programming

Transcript

  1. Structured Comments and Test Coverage (SketchCurves Project) https://github.com/CeranPaul/SketchCurves Paul Hollingshead

    - [email protected] (Put repository address and email on whiteboard) Making geometry is what floats my boat… There are times when expensive CAD software is not the right tool: stiffened panel and gear. Please ask questions as they occur to you.
  2. Closed Perimeter Making something like this shouldn’t be harder than

    grabbing your iPad and spending five minutes. Single path, - no cutouts, yet. Talk about 3D printed letter G, and making offsets. Might also give it thickness for display.
  3. • T argeted for iPad to take advantage of larger

    screen, and Pencil input. Repository is an accumulation of code written for various geometry projects. Useful for ad hoc geometry in an AR app. SolidWorks is one CAD system that has a tool to import sketches. A couple of tools that I have run across are worth sharing.
  4. Structured Comments /// Accumulate a curve. /// This is an

    unsophisticated version. /// Adds to array 'pool'. /// - Parameters: /// - freshCurve: A newly drawn curve func add(freshCurve: PenCurve) -> Void { Lines with three slashes immediately prior to declarations using some key words Jazzy generates HTML that you can post with your repository. (Go to browsing the documentation)
  5. Will also show up in the Quick Help Descriptions preceding

    the class declaration are what show up in Quick Help (Do a command - click demonstration)
  6. /// Number of pieces to divide range let chunks =

    5 /// The possible return value var tighter: ClosedRange<Double> /// Parameter step let parStep = (span.upperBound - span.lowerBound) / Double(chunks) Individual Parameters for Quick Help If you add a description, it shows up. Is it worth your time to add these? If come back to look at code I wrote nine months ago, I’m happy for this. What do you think is necessary for the people who will see your code?
  7. /// - Throws: ZeroVectorError if either input is of zero

    length /// - Returns: A simple flag /// - SeeAlso: isOpposite() /// - See: 'testIsScaled' under Vector3DTests Other Keywords Warning, links, images, copyright, and note. Some keywords are bolded in XCode 9.3. I don’t know the significance of that. I do not know which ones, if any, that Jazzy ignores.
  8. • Jazzy is an open source project on GitHub •

    Documentation will be generated only for public functions and attributes • Perhaps not ideal for your own use. • Future use in an automated scan Claim that it uses some portion of the compiler to understand the source code. A little extra time while coding avoids maintaining a separate document. Audience willingness and ability to read code? Future you? I am trying to cultivate the habit of writing structured comments as I write code.
  9. Erica Sadun’s book (on iBooks) gives more details, and mentions

    Jazzy. Not available through Amazon. “Appledocs” for Objective C.
  10. Doubting your prior work sucks! Not TDD, but capturing or

    writing tests early to add value to my code. I am stunned at the number of GitHub repositories with zero tests.
  11. I find that I am writing as much (or more)

    test code as production code. Capturing code that you write and usually throw away. Unit tests don’t seem to lend themselves to drawing routines.
  12. XCode Test Coverage Tool XCode 9.3 made this generate sensible

    results. Percentage for the project is shown at the top. Don’t get hung up on meeting some coverage number. ViewController will never be 100% Might tell you if one class is ready for prime time. Tests are like the merge lanes on city streets.
  13. Scrub the Colored Bars No bueno! What routines are okay

    to fail? This helps you focus. Unit tests can’t detect the presence of errors, they can only verify the absence of errors.
  14. Granularity down to an individual line An ‘if’ clause, or

    Switch case that hasn’t been proven will stand out. Does anyone know what the stripes indicate? This doesn’t mean that there are 62 XCTAsserts being used.
  15. • Tests are a practical demonstration of meeting the requirements.

    • Useful for regression testing when requirements change. For an open source project, do the tests provide the equivalent of guard rails? “The software is never finished and requirements tend to change.” For an open source project, you might need to help a wide spectrum of people.
  16. • Testing will drive you to write an ‘equals’ function

    for all classes. • There is a difference between thorough testing and complete testing. • Tests are important should I want to re-host this work to another language. • Tests are a useful check if I rework the code to speed it up. I’m willing to invest time in writing tests because I consider them assets for the lifetime of the code. I feel comfortable about the upcoming transition to Swift 5 this fall. If you have exercised each and every line, does that mean that you have covered all of the possible cases? Most of my routines pass tests in the XY plane. Should I have tests in skewed planes? This tool can help you reach your testing goal.
  17. Functional Decomposition I spent a lot of time figuring how

    to break down the problem. More of an object-oriented than functional programming approach. Speak up if you see something that is going to kick my butt later.
  18. • Mixture of structs versus classes Is the class likely

    to be extended? • Decisions about member or static functions. How many of them will be used? • Where do you put complicated functions e.g. line / line intersection? • Testing will influence how you break down your problem. Jazzy documentation doesn’t categorize member or static.
  19. Member Static offset transform hashValue distance midway isThreeUnique isThreeLinear …and

    four others Point I’ve spent time pondering whether functions should belong to the instance, or the class. Compiler’s help to write routines that are thread safe. Triangle counts for the gear and stiffened panel. Automated Reference Counting helps, but you’re still on a machine with limited memory.
  20. PenCurve Protocol • Polymorphism, as opposed to generics /// The

    general framework for a curve. Not limited to 2D. public protocol PenCurve { /// The enum that hints at the meaning of the curve var usage: PenTypes { get set } /// Not used yet var parameterRange: ClosedRange<Double> { get set } /// Supply the point on the curve for the input parameter value func pointAt(t: Double) throws -> Point3D /// Retrieve the starting end func getOneEnd() -> Point3D /// Retrieve the finishing end func getOtherEnd() -> Point3D Finite curves that I want to draw and assemble into a silhouette. Not shown in this code fragment is a ‘draw’ method. (An illustration to serve as a reminder of the goal would be good.)
  21. PenCurve Other LineSeg Point3D Cubic Vector3D Arc Line Spline Transform

    Ellipse Plane In the spirit of strong typing, I didn’t treat Point and Vector the same. Transform is a 4x4, not a 3x3. Transform needed to scale then display in XY. Would want to have a quadratic to go to and from SVG’s. Show construction of the fillet as rationale for Line.
  22. Loop • More than just a grouper • Will set

    a flag when it becomes closed. • Will force a consistent order when closed. Closest equivalent to UIBezierPath. Is a Class that might be extended. Use two volunteers to draw shape, then examine order used? Individual segments of a Loop will be drawn in random order, and in random directions.
  23. Alignment Unaligned curves will make tasks such as offsetting, finding

    area, etc. more difficult. Go through the process of generating the fillet to show offsetting.
  24. Several afternoons a week I work with high schoolers that

    build and fly R/C airplanes. 3/16 foamboard with paper on either side. 60W laser cutter.
  25. The laser cutter works from a flat drawing. Not 1980’s

    with vector displays! Can use color, line weights, and patterns for different meanings. Demonstrates that Keynote is a lousy drawing tool.
  26. PenTypes Enum • Record the intent for each curve. public

    enum PenTypes { case raw case construction case interior case ideal case guide case ordinary } This gets stored in one of the member attributes for PenCurve protocol. Whatever categories you need for the current project. Choices for foamboard app might be: edge, score, bevel, and A-fold.
  27. The corresponding code in the view’s ‘draw’ function sets the

    desired pen characteristics: // Choose the appropriate pen switch wire.usage { case .raw: context.setStrokeColor(blue) context.setLineWidth(standard) context.setLineDash(phase: 0, lengths: []); case .construction: context.setStrokeColor(black) context.setLineWidth(thin) context.setLineDash(phase: 0, lengths: [CGFloat(10), CGFloat(8)]); Custom code for each application This ‘switch’ statement immediately precedes the polymorphic ‘draw’ method call. The goal is to separate out the presentation properties, and have a capable and reusable plotting scheme. Decisions about the palette are made at compile time.
  28. Using Pencil Input a b c d e f g

    Result of a stroke will be an array of points, recorded every 1/30 th of a second. Perhaps more rapidly on last year’s iPads. Our brains can differentiate those readily. Writing code to do it isn’t as easy. How do you turn that data into information? (This really should be a live demonstration)
  29. • Don’t put the Pencil down • How do you

    select a curve? • Drag a box that will contain it • Short stroke across the curve • Scribble across the curve to delete it? Some of the interesting UI questions Recall that you don’t have any indication when the tip is hovering near a point.
  30. Surfaces • Will force use of points defined by U

    and V coordinates Curve tools are the stepping stone to working with surfaces such as the stiffened panel Curves are also a function of U and V. Whole bunch more iterative work. That will be hard to get correct and fast. Reference a surface repository.
  31. Linear Algebra • Offset surface requires solving a 16 x

    16 matrix. Offset curve requires a 4x4, which SIMD library can handle. C function package is callable from Swift, though that isn’t in the repository. “import Accelerate” (Add chart with code sample?) Have not tried large matrices.
  32. Advantages of Swift • Lots of ‘guard’ statements to protect

    functions • Plenty of ‘map’, ‘filter’, and ’reduce’, but no named closures. • (1…10).reverse() for a decrementing loop index Best example of using features of the language. Draw curve and line to show intersection process using tuples and ClosedRange. Default parameters Any discussion of access control?
  33. • Topology, constraints, cutouts, and dimensions. • Import SVG e.g.

    letters. • SVG output is the advancement beyond screen scraping. • Output to JavaScript if running server-side Swift. • How do I tackle ‘Undo’ management? Future Commits (Come up with a beam section view to show dimensions?) Online converters available for SVG to .dwg. Where is a definition of .dwg format?
  34. OrthoVol fileprivate var rangeX: ClosedRange<Double> fileprivate var rangeY: ClosedRange<Double> fileprivate

    var rangeZ: ClosedRange<Double> • Avoids zero thickness (Show an isometric view of a brick) OrthoVol also handy for finding collisions.
  35. /// Exception for when the points should not have be

    coincident class CoincidentPointsError: ErrorType { var ptA: Point3D var description: String { return "Coincident points were specified - no bueno! " + String(ptA) } init(dupePt: Point3D) { self.ptA = dupePt } } An example of how I choose to use ErrorType ErrorType has a blank protocol at the moment Description could be used on the console, on a logger, or in an alert Chose a class in case I want make a subtype
  36. Available debugging identifiers #file, #function, #line, #column, and #dsohandle print(#file

    + error.description) Code and console output Difference between where error was detected and where it was caused Comparison to leaky roof