├── CONTRIBUTERS.md ├── ReformApplication ├── ReformApplication │ ├── Assets.xcassets │ │ ├── Contents.json │ │ ├── arc.imageset │ │ │ ├── arc.pdf │ │ │ └── Contents.json │ │ ├── crop.imageset │ │ │ ├── crop.pdf │ │ │ └── Contents.json │ │ ├── line.imageset │ │ │ ├── line.pdf │ │ │ └── Contents.json │ │ ├── move.imageset │ │ │ ├── move.pdf │ │ │ └── Contents.json │ │ ├── pie.imageset │ │ │ ├── pie.pdf │ │ │ └── Contents.json │ │ ├── text.imageset │ │ │ ├── text.pdf │ │ │ └── Contents.json │ │ ├── morph.imageset │ │ │ ├── morph.pdf │ │ │ └── Contents.json │ │ ├── scale.imageset │ │ │ ├── scale.pdf │ │ │ └── Contents.json │ │ ├── circle.imageset │ │ │ ├── circle.pdf │ │ │ └── Contents.json │ │ ├── cursor.imageset │ │ │ ├── cursor.pdf │ │ │ └── Contents.json │ │ ├── export.imageset │ │ │ ├── export.pdf │ │ │ └── Contents.json │ │ ├── rect.imageset │ │ │ ├── rectangle.pdf │ │ │ └── Contents.json │ │ ├── rotate.imageset │ │ │ ├── rotate.pdf │ │ │ └── Contents.json │ │ ├── gallery.imageset │ │ │ ├── gallery.pdf │ │ │ └── Contents.json │ │ ├── picture.imageset │ │ │ ├── picture.pdf │ │ │ └── Contents.json │ │ ├── preview.imageset │ │ │ ├── preview.pdf │ │ │ └── Contents.json │ │ ├── AppIcon.appiconset │ │ │ ├── reform-icon-2.png │ │ │ ├── reform-icon-3.png │ │ │ └── Contents.json │ │ ├── sidebar-left.imageset │ │ │ ├── sidebar-left.pdf │ │ │ └── Contents.json │ │ ├── sidebar-right.imageset │ │ │ ├── sidebar-right.pdf │ │ │ └── Contents.json │ │ └── example-thumbnail.imageset │ │ │ ├── Bildschirmfoto 2015-08-14 um 19.39.12.png │ │ │ └── Contents.json │ ├── ProjectSession.swift │ ├── InstructionDetailController.swift │ ├── MeasurementController.swift │ ├── AppDelegate.swift │ ├── SheetController.swift │ ├── AttributesViewModel.swift │ ├── ViewController.swift │ ├── MaskUIRenderer.swift │ ├── StageViewModel.swift │ ├── GradientView.swift │ ├── PivotUI.swift │ ├── Modifier.swift │ ├── ExportController.swift │ ├── FormIteratorDetailController.swift │ ├── MorphInstructionDetailController.swift │ ├── CreateFormInstructionDetailController.swift │ ├── RotateInstructionDetailController.swift │ ├── ScaleInstructionDetailController.swift │ ├── Renderer.swift │ ├── GrabUI.swift │ ├── AffineHandleUI.swift │ ├── HandleUI.swift │ ├── ExpressionLexer.swift │ ├── ProcedureCellView.swift │ ├── ProcedureViewModel.swift │ ├── Info.plist │ └── CropUI.swift ├── ReformApplicationTests │ ├── Info.plist │ └── ReformApplicationTests.swift └── ReformApplicationUITests │ ├── Info.plist │ └── ReformApplicationUITests.swift ├── ReformCore ├── ReformCore │ ├── Operators.swift │ ├── Degeneratable.swift │ ├── Analyzable.swift │ ├── DrawingMode.swift │ ├── Evaluatable.swift │ ├── ScaleFactor.swift │ ├── Translator.swift │ ├── Rotator.swift │ ├── Scaler.swift │ ├── ReferenceId.swift │ ├── TranslationDistance.swift │ ├── InitialDestination.swift │ ├── Project.swift │ ├── Attribute.swift │ ├── AbsoluteScaler.swift │ ├── ReformCore.h │ ├── Alignment.swift │ ├── CompositeRotator.swift │ ├── Analyzer.swift │ ├── CompositeScaler.swift │ ├── ConstantLength.swift │ ├── Sequence.swift │ ├── NullOutline.swift │ ├── ProxyTranslator.swift │ ├── ProxyRotator.swift │ ├── BasicPointTranslator.swift │ ├── BasicAngleRotator.swift │ ├── ProxyScaler.swift │ ├── Length.swift │ ├── ReferencePoint.swift │ ├── AnchorPoint.swift │ ├── BasicPointRotator.swift │ ├── FormIdentifier.swift │ ├── RotationAngle.swift │ ├── NameAllocator.swift │ ├── BasicPointScaler.swift │ ├── ConstantScaleFactor.swift │ ├── PointLength.swift │ ├── Outline.swift │ ├── ConstantDistance.swift │ ├── Info.plist │ ├── CenterPoint.swift │ ├── StaticPointAnchor.swift │ ├── PointAngle.swift │ ├── StaticFormReference.swift │ ├── StaticLength.swift │ ├── ConstantAngel.swift │ ├── Picture.swift │ ├── GridPoint.swift │ ├── Axis.swift │ ├── StaticAngle.swift │ ├── Describable.swift │ ├── BasicLengthScaler.swift │ ├── RuntimeError.swift │ ├── StaticPoint.swift │ ├── Form.swift │ ├── Glomp.swift │ ├── Anchor.swift │ ├── FixSizeDestination.swift │ ├── IfConditionInstruction.swift │ ├── ForLoopInstruction.swift │ ├── Runtime.swift │ ├── IntersectionPoint.swift │ ├── ExposedPoint.swift │ ├── LineOutline.swift │ ├── FormInteratorInstruction.swift │ └── RelativeDestination.swift └── ReformCoreTests │ ├── Info.plist │ └── ReformCoreTests.swift ├── ReformStage ├── ReformStage │ ├── Pivot.swift │ ├── ReformStage.h │ ├── ScaleAxis.swift │ ├── SnapPoint.swift │ ├── GlompSnapPoint.swift │ ├── Info.plist │ ├── GridSnapPoint.swift │ ├── IntersectionSnapPoint.swift │ ├── Stage.swift │ ├── CropPoint.swift │ └── Handle.swift └── ReformStageTests │ ├── Info.plist │ └── ReformStageTests.swift ├── ReformExpression ├── ReformExpression │ ├── Result.swift │ ├── Reference.swift │ ├── ReformExpression.h │ ├── Queue.swift │ ├── Stack.swift │ ├── Info.plist │ ├── Parser.swift │ ├── TopologicalSort.swift │ └── Value.swift └── ReformExpressionTests │ ├── Info.plist │ └── ReformExpressionTests.swift ├── ReformSerializer ├── ReformSerializer │ ├── Encoder.swift │ ├── Decoder.swift │ ├── ReformSerializer.h │ ├── Normalizer.swift │ └── Info.plist └── ReformSerializerTests │ ├── Info.plist │ └── ReformSerializerTests.swift ├── STYLEGUIDE.md ├── ReformTools ├── ReformTools │ ├── Camera.swift │ ├── Target.swift │ ├── MaskUI.swift │ ├── PivotUI.swift │ ├── InstructionFocus.swift │ ├── Tool.swift │ ├── HandleUI.swift │ ├── CropUI.swift │ ├── SnapUI.swift │ ├── GrabUI.swift │ ├── AffineHandleUI.swift │ ├── PointType.swift │ ├── ReformTools.h │ ├── SelectionUI.swift │ ├── PivotSwitcher.swift │ ├── NullTool.swift │ ├── Aligner.swift │ ├── ToolController.swift │ ├── FormSelection.swift │ ├── Info.plist │ ├── PreviewTool.swift │ ├── Input.swift │ ├── EntityFinder.swift │ ├── AffineHandleFinder.swift │ └── HandleFinder.swift └── ReformToolsTests │ ├── Info.plist │ └── ReformToolsTests.swift ├── ReformMath ├── ReformMath │ ├── Constants.swift │ ├── Scalar.swift │ ├── Distance.swift │ ├── Relations.swift │ ├── Sector2d.swift │ ├── Segment2d.swift │ ├── AngleScalerOperators.swift │ ├── VectorVectorOperators.swift │ ├── Path2d.swift │ ├── ReformMath.h │ ├── Incidence.swift │ ├── AngleAngleOperators.swift │ ├── LineSegment2d.swift │ ├── AngleRange.swift │ ├── Circle2d.swift │ ├── Ray2d.swift │ ├── Line2d.swift │ ├── Info.plist │ ├── Triangle2d.swift │ ├── Operators.swift │ ├── VectorScalarOperators.swift │ ├── Vec2d.swift │ ├── Containment.swift │ ├── Angle.swift │ ├── Arc2d.swift │ └── Mat3x2.swift └── ReformMathTests │ ├── VectorScalarOperators.swift │ └── Info.plist ├── ReformGraphics ├── ReformGraphics │ ├── Color.swift │ ├── ReformGraphics.h │ ├── Info.plist │ └── Shape.swift └── ReformGraphicsTests │ ├── Info.plist │ └── ReformGraphicsTests.swift ├── .gitignore ├── LICENSE.md ├── Reform.xcworkspace └── contents.xcworkspacedata └── SETUP.md /CONTRIBUTERS.md: -------------------------------------------------------------------------------- 1 | Reform - Contributers 2 | ===================== 3 | 4 | - Laszlo Korte (reform@laszlokorte.de) -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/arc.imageset/arc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/arc.imageset/arc.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/crop.imageset/crop.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/crop.imageset/crop.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/line.imageset/line.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/line.imageset/line.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/move.imageset/move.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/move.imageset/move.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/pie.imageset/pie.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/pie.imageset/pie.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/text.imageset/text.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/text.imageset/text.pdf -------------------------------------------------------------------------------- /ReformCore/ReformCore/Operators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Operators.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/Pivot.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Pivot.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/morph.imageset/morph.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/morph.imageset/morph.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/scale.imageset/scale.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/scale.imageset/scale.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/circle.imageset/circle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/circle.imageset/circle.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/cursor.imageset/cursor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/cursor.imageset/cursor.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/export.imageset/export.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/export.imageset/export.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/rect.imageset/rectangle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/rect.imageset/rectangle.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/rotate.imageset/rotate.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/rotate.imageset/rotate.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/gallery.imageset/gallery.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/gallery.imageset/gallery.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/picture.imageset/picture.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/picture.imageset/picture.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/preview.imageset/preview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/preview.imageset/preview.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/AppIcon.appiconset/reform-icon-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/AppIcon.appiconset/reform-icon-2.png -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/AppIcon.appiconset/reform-icon-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/AppIcon.appiconset/reform-icon-3.png -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/sidebar-left.imageset/sidebar-left.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/sidebar-left.imageset/sidebar-left.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/sidebar-right.imageset/sidebar-right.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/sidebar-right.imageset/sidebar-right.pdf -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/arc.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "arc.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/crop.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "crop.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/line.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "line.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/move.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "move.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/pie.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "pie.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/text.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "text.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/circle.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "circle.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/cursor.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "cursor.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/export.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "export.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/morph.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "morph.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/rect.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "rectangle.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/rotate.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "rotate.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/scale.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "scale.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/gallery.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "gallery.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/picture.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "picture.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/preview.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "preview.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/example-thumbnail.imageset/Bildschirmfoto 2015-08-14 um 19.39.12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laszlokorte/reform-swift/HEAD/ReformApplication/ReformApplication/Assets.xcassets/example-thumbnail.imageset/Bildschirmfoto 2015-08-14 um 19.39.12.png -------------------------------------------------------------------------------- /ReformCore/ReformCore/Degeneratable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Degeneratable.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public protocol Degeneratable { 10 | var isDegenerated : Bool { get } 11 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/Analyzable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Analyzable.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public protocol Analyzable { 10 | func analyze(_ analyzer: T) 11 | } 12 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/Result.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Result.swift 3 | // ExpressionEngine 4 | // 5 | // Created by Laszlo Korte on 10.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public enum Result { 10 | case success(T) 11 | case fail(E) 12 | } 13 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/DrawingMode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrawingMode.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public enum DrawingMode { 10 | case draw 11 | case mask 12 | case guide 13 | } 14 | -------------------------------------------------------------------------------- /ReformSerializer/ReformSerializer/Encoder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Encoder.swift 3 | // ReformSerializer 4 | // 5 | // Created by Laszlo Korte on 31.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | protocol Encoder { 10 | func encode(_ value: NormalizedValue) -> String 11 | } 12 | -------------------------------------------------------------------------------- /STYLEGUIDE.md: -------------------------------------------------------------------------------- 1 | Reform coding style 2 | =================== 3 | 4 | 5 | Swift 6 | ----- 7 | - never force unwrap optionals 8 | - do not use `self` if not needed 9 | - add protocol conformance not in type definition but via extension 10 | - omit get-clause for readonly computed properties 11 | - omit semicolons -------------------------------------------------------------------------------- /ReformTools/ReformTools/Camera.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Camera.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 06.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public final class Camera { 11 | public var zoom : Double = 1 12 | 13 | public init() {} 14 | } -------------------------------------------------------------------------------- /ReformSerializer/ReformSerializer/Decoder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Decoder.swift 3 | // ReformSerializer 4 | // 5 | // Created by Laszlo Korte on 31.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | protocol Decoder { 10 | func decode(_ string: String) throws -> NormalizedValue? 11 | } 12 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Constants.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Constants.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 21.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public let PI = Double.pi 10 | public let TAU = 2*Double.pi 11 | public let E = M_E 12 | public let EPSILON = 0.00001 13 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Evaluatable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Evaluatable.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public protocol Evaluatable : class, Analyzable { 10 | func evaluate(_ runtime: T) where T.Ev == Self 11 | } 12 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ScaleFactor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScaleFactor.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public protocol RuntimeScaleFactor : Degeneratable { 11 | func getFactorFor(_ runtime: R) -> Double? 12 | } 13 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Translator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Translator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol Translator { 12 | func translate(_ runtime: R, delta: Vec2d) 13 | } 14 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Rotator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Rotator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol Rotator { 12 | func rotate(_ runtime: R, angle: Angle, fix: Vec2d) 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Scaler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Scaler.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol Scaler { 12 | func scale(_ runtime : R, factor: Double, fix: Vec2d, axis: Vec2d) 13 | } 14 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/Target.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Target.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 19.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformStage 11 | 12 | public enum Target { 13 | case free(position: Vec2d) 14 | case snap(point: SnapPoint) 15 | } 16 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ReferenceId.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReferenceId.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 26.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformExpression 10 | 11 | extension ReferenceId : SequenceGeneratable { 12 | public init(id: Int) { 13 | self.init(id) 14 | } 15 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/sidebar-left.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "sidebar-left.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/sidebar-right.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "sidebar-right.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/TranslationDistance.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TranslationDistance.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol RuntimeDistance : Degeneratable { 12 | func getDeltaFor(_ runtime: R) -> Vec2d? 13 | } 14 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/InitialDestination.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InitialDestination.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol RuntimeInitialDestination : Degeneratable { 12 | func getMinMaxFor(_ runtime: R) -> (Vec2d,Vec2d)? 13 | } 14 | -------------------------------------------------------------------------------- /ReformMath/ReformMathTests/VectorScalarOperators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VectorScalarOperators.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 12.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import XCTest 11 | @testable import ReformMath 12 | 13 | final class VectorScalerOperatorTest : XCTestCase { 14 | 15 | let PRECISION = 0.0001 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Scalar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Scalar.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 03.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | typealias Scalar = Double 10 | 11 | extension Scalar { 12 | public static let PI = Double.pi 13 | public static let TAU = 2*Double.pi 14 | public static let E = M_E 15 | public static let EPSILON = 0.00001 16 | } 17 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/MaskUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PreviewUI.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 30.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public final class MaskUI { 10 | public enum State { 11 | case disabled 12 | case clip(x: Double, y: Double, width: Double, height: Double) 13 | } 14 | 15 | public var state : State = .disabled 16 | 17 | public init() {} 18 | } 19 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/PivotUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PivotUI.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformStage 11 | 12 | public final class PivotUI { 13 | public enum State { 14 | case hide 15 | case show(SnapPoint) 16 | } 17 | 18 | public var state : State = .hide 19 | 20 | public init() {} 21 | } 22 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Distance.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Distance.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 24.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public func distance(point pointA: Vec2d, point pointB: Vec2d) -> Double { 10 | return (pointB - pointA).length 11 | } 12 | 13 | public func distance(point: Vec2d, line: Line2d) -> Double { 14 | return abs(dot((point - line.from), orthogonal(line.direction))) 15 | } 16 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Project.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Project.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | final public class Project { 10 | public private(set) var pictures : [Picture] 11 | 12 | public init(pictures: Picture...) { 13 | self.pictures = pictures 14 | } 15 | 16 | public init(pictures: [Picture]) { 17 | self.pictures = pictures 18 | } 19 | } -------------------------------------------------------------------------------- /ReformTools/ReformTools/InstructionFocus.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InstructionFocus.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | 11 | public final class InstructionFocus { 12 | public var current : InstructionNode? 13 | 14 | public init() {} 15 | 16 | public func isCurrent(_ node : Evaluatable) -> Bool { 17 | return current === node 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/example-thumbnail.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Bildschirmfoto 2015-08-14 um 19.39.12.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ReformTools/ReformTools/Tool.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Tool.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol Tool { 12 | func setUp() 13 | 14 | func tearDown() 15 | 16 | func refresh() 17 | 18 | func focusChange() 19 | 20 | func process(_ input: Input, atPosition: Vec2d, withModifier: Modifier) 21 | 22 | func cancel() 23 | } 24 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Relations.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Relations.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | func sign(_ p: Vec2d, a: Vec2d, b: Vec2d) -> Double 10 | { 11 | return (p.x - b.x) * (a.y - b.y) - (a.x - b.x) * (p.y - b.y) 12 | } 13 | 14 | public func leftOf(_ point: Vec2d, line: Line2d, epsilon: Double = 0) -> Bool { 15 | return sign(point, a:line.from, b:line.from + line.direction) < epsilon 16 | } 17 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/HandleUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HandleUI.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformStage 11 | 12 | public final class HandleUI { 13 | public enum State { 14 | case hide 15 | case show([Handle]) 16 | case active(Handle, [Handle]) 17 | } 18 | 19 | public var state : State = .hide 20 | 21 | public init() {} 22 | } 23 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/ProjectSession.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProjectSession.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 26.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformExpression 11 | import ReformStage 12 | import ReformMath 13 | import ReformTools 14 | 15 | final class ProjectSession { 16 | 17 | let project : Project 18 | 19 | init(project: Project) { 20 | self.project = project 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /ReformGraphics/ReformGraphics/Color.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Color.swift 3 | // ReformGraphics 4 | // 5 | // Created by Laszlo Korte on 16.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Color { 10 | let red : UInt8 11 | let green : UInt8 12 | let blue: UInt8 13 | let alpha : UInt8 14 | 15 | public init(r:UInt8, g:UInt8, b:UInt8, a:UInt8) { 16 | self.red = r 17 | self.green = g 18 | self.blue = b 19 | self.alpha = a 20 | } 21 | } -------------------------------------------------------------------------------- /ReformTools/ReformTools/CropUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CropUI.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformStage 11 | 12 | public final class CropUI { 13 | public enum State { 14 | case hide 15 | case show([CropPoint]) 16 | case active(CropPoint, [CropPoint]) 17 | } 18 | 19 | public var state : State = .hide 20 | 21 | public init() {} 22 | } 23 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/SnapUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapUI.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformStage 11 | 12 | public final class SnapUI { 13 | public enum State { 14 | case hide 15 | case show([SnapPoint]) 16 | case active(SnapPoint, [SnapPoint]) 17 | } 18 | 19 | public var state : State = .hide 20 | 21 | public init() {} 22 | } 23 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/GrabUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GrabUI.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformStage 11 | 12 | public final class GrabUI { 13 | public enum State { 14 | case hide 15 | case show([EntityPoint]) 16 | case active(EntityPoint, [EntityPoint]) 17 | } 18 | 19 | public var state : State = .hide 20 | 21 | public init() {} 22 | } 23 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Attribute.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Attribute.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | enum AttributeType { 10 | case string 11 | case number 12 | case pictureId 13 | } 14 | 15 | final class Attribute { 16 | let name : String 17 | let type : AttributeType 18 | 19 | init(name: String, type: AttributeType) { 20 | self.name = name 21 | self.type = type 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Sector2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Sector2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 23.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public struct Sector2d : Equatable { 11 | public let arc : Arc2d 12 | 13 | public init(center: Vec2d, radius:Double, range: AngleRange) { 14 | self.arc = Arc2d(center: center, radius: radius, range: range) 15 | } 16 | } 17 | 18 | public func ==(lhs: Sector2d, rhs: Sector2d) -> Bool { 19 | return lhs.arc == rhs.arc 20 | } -------------------------------------------------------------------------------- /ReformMath/ReformMath/Segment2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Segment2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 23.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public struct Segment2d : Equatable { 11 | let arc : Arc2d 12 | 13 | public init(center: Vec2d, radius:Double, range: AngleRange) { 14 | self.arc = Arc2d(center: center, radius: radius, range: range) 15 | } 16 | } 17 | 18 | public func ==(lhs: Segment2d, rhs: Segment2d) -> Bool { 19 | return lhs.arc == rhs.arc 20 | } -------------------------------------------------------------------------------- /ReformTools/ReformTools/AffineHandleUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AffineHandleUI.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 25.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import ReformCore 11 | import ReformStage 12 | 13 | public final class AffineHandleUI { 14 | public enum State { 15 | case hide 16 | case show([AffineHandle]) 17 | case active(AffineHandle, [AffineHandle]) 18 | } 19 | 20 | public var state : State = .hide 21 | 22 | public init() {} 23 | } 24 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/AngleScalerOperators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AngleScalerOperators.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 12.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public func *(lhs: Angle, rhs: Double) -> Angle { 10 | return Angle(radians: lhs.radians * rhs) 11 | } 12 | 13 | public func *(lhs: Double, rhs: Angle) -> Angle { 14 | return Angle(radians: lhs * rhs.radians) 15 | } 16 | 17 | public func /(lhs: Angle, rhs: Double) -> Angle { 18 | return Angle(radians: lhs.radians / rhs) 19 | } -------------------------------------------------------------------------------- /ReformMath/ReformMath/VectorVectorOperators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VectorVectorOperators.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 12.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public func +(lhs: Vec2d, rhs: Vec2d) -> Vec2d { 10 | return Vec2d(x: lhs.x + rhs.x, y: lhs.y + rhs.y) 11 | } 12 | 13 | public func -(lhs: Vec2d, rhs: Vec2d) -> Vec2d { 14 | return Vec2d(x: lhs.x - rhs.x, y: lhs.y - rhs.y) 15 | } 16 | 17 | public prefix func -(op: Vec2d) -> Vec2d { 18 | return Vec2d(x: -op.x, y: -op.y) 19 | } -------------------------------------------------------------------------------- /ReformMath/ReformMath/Path2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Path2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 22.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public typealias SegmentPath = [Segment] 10 | 11 | public enum Segment { 12 | case line(LineSegment2d) 13 | case arc(Arc2d) 14 | } 15 | 16 | extension Segment { 17 | var length : Double { 18 | switch self { 19 | case .line(let line): 20 | return line.length 21 | case .arc(let arc): 22 | return arc.length 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/InstructionDetailController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InstructionDetailController.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 06.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformExpression 11 | 12 | protocol InstructionDetailController : class { 13 | var stringifier : Stringifier? { set get } 14 | var error : String? { set get } 15 | var parser : ((String) -> Result)? { set get } 16 | var intend : (() -> ())? { set get } 17 | } 18 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/AbsoluteScaler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AbsoluteScaler.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 22.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct AbsoluteScaler : Scaler { 12 | private let scaler : Scaler 13 | 14 | init(scaler: Scaler) { 15 | self.scaler = scaler 16 | } 17 | 18 | 19 | func scale(_ runtime: R, factor: Double, fix: Vec2d, axis: Vec2d) { 20 | scaler.scale(runtime, factor: abs(factor), fix: fix, axis: axis) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ReformCore.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReformCore.h 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ReformCore. 12 | FOUNDATION_EXPORT double ReformCoreVersionNumber; 13 | 14 | //! Project version string for ReformCore. 15 | FOUNDATION_EXPORT const unsigned char ReformCoreVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/Reference.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DataSet.swift 3 | // ExpressionEngine 4 | // 5 | // Created by Laszlo Korte on 07.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public protocol DataSet { 10 | func lookUp(_ id: ReferenceId) -> Value? 11 | 12 | func getError(_ id: ReferenceId) -> EvaluationError? 13 | } 14 | 15 | public struct ReferenceId : Hashable { 16 | public let value : Int 17 | 18 | public init(_ value: Int) { 19 | self.value = value 20 | } 21 | 22 | public var hashValue : Int { return value } 23 | } 24 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/ReformMath.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReformMath.h 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ReformMath. 12 | FOUNDATION_EXPORT double ReformMathVersionNumber; 13 | 14 | //! Project version string for ReformMath. 15 | FOUNDATION_EXPORT const unsigned char ReformMathVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/MeasurementController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MeasurementController.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Cocoa 11 | 12 | final class MeasurementController : NSViewController { 13 | 14 | } 15 | 16 | extension MeasurementController : NSTableViewDataSource { 17 | func numberOfRows(in tableView: NSTableView) -> Int { 18 | return 2 19 | } 20 | } 21 | 22 | extension MeasurementController : NSTableViewDelegate { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/ReformStage.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReformStage.h 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ReformStage. 12 | FOUNDATION_EXPORT double ReformStageVersionNumber; 13 | 14 | //! Project version string for ReformStage. 15 | FOUNDATION_EXPORT const unsigned char ReformStageVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/PointType.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PointType.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 18.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformStage 10 | 11 | struct PointType : OptionSet { 12 | let rawValue : Int 13 | 14 | static let `Any` = PointType(rawValue: 1|2|4) 15 | static let None = PointType(rawValue: 0) 16 | static let Form = PointType(rawValue: 1) 17 | static let Intersection = PointType(rawValue: 2) 18 | static let Glomp = PointType(rawValue: 4) 19 | static let Grid = PointType(rawValue: 8) 20 | } 21 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/ReformTools.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReformTools.h 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ReformTools. 12 | FOUNDATION_EXPORT double ReformToolsVersionNumber; 13 | 14 | //! Project version string for ReformTools. 15 | FOUNDATION_EXPORT const unsigned char ReformToolsVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | final class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | 15 | 16 | func applicationDidFinishLaunching(_ aNotification: Notification) { 17 | 18 | } 19 | 20 | func applicationWillTerminate(_ aNotification: Notification) { 21 | // Insert code here to tear down your application 22 | } 23 | 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/SheetController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SheetController.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Cocoa 11 | 12 | final class SheetController : NSViewController { 13 | @IBOutlet var tableView : NSTableView? 14 | } 15 | 16 | 17 | extension SheetController : NSTableViewDataSource { 18 | func numberOfRows(in tableView: NSTableView) -> Int { 19 | return 3 20 | } 21 | } 22 | 23 | extension SheetController : NSTableViewDelegate { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/SelectionUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SelectionUI.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformMath 11 | 12 | public final class SelectionUI { 13 | public enum State { 14 | case hide 15 | case show(FormSelection) 16 | } 17 | 18 | public enum Rect { 19 | case hide 20 | case show(Vec2d, Vec2d) 21 | } 22 | 23 | public var state : State = .hide 24 | public var rect : Rect = .hide 25 | 26 | public init() {} 27 | } 28 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/AttributesViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AttributesViewModel.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 02.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformTools 10 | import ReformCore 11 | import ReformStage 12 | 13 | class AttributesViewModel { 14 | let stage : Stage 15 | let selection : FormSelection 16 | let analyzer : Analyzer 17 | 18 | init(stage : Stage, selection : FormSelection, analyzer: Analyzer) { 19 | self.stage = stage 20 | self.selection = selection 21 | self.analyzer = analyzer 22 | } 23 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | final class ViewController: NSViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | } 18 | 19 | override var representedObject: Any? { 20 | didSet { 21 | // Update the view, if already loaded. 22 | } 23 | } 24 | 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Incidence.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Incidence.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 24.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public func incident(_ point: Vec2d, lineSegment: LineSegment2d, epsilon: Double = .EPSILON) -> Bool 10 | { 11 | let delta = (point - lineSegment.from).length + (point - lineSegment.to).length - lineSegment.length 12 | 13 | return -epsilon < delta && delta < epsilon 14 | } 15 | 16 | public func incident(_ point: Vec2d, arc: Arc2d, epsilon: Double = .EPSILON) -> Bool 17 | { 18 | // TODO: implement 19 | return false 20 | } 21 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Alignment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Alignment.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 18.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public enum RuntimeAlignment { 12 | case leading 13 | case centered 14 | } 15 | 16 | extension RuntimeAlignment { 17 | func getMinMax(from: Vec2d, to: Vec2d) -> (min: Vec2d, max: Vec2d) { 18 | switch self { 19 | case .leading: 20 | return (min: from, max: to) 21 | case .centered: 22 | return (min: 2*from - to, max: to) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/CompositeRotator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CompositeRotator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct CompositeRotator : Rotator { 12 | private let rotators : [Rotator] 13 | 14 | init(rotators:Rotator...) { 15 | self.rotators = rotators 16 | } 17 | 18 | 19 | func rotate(_ runtime: R, angle: Angle, fix: Vec2d) { 20 | for rotator in rotators { 21 | rotator.rotate(runtime, angle: angle, fix: fix) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ReformGraphics/ReformGraphics/ReformGraphics.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReformGraphics.h 3 | // ReformGraphics 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ReformGraphics. 12 | FOUNDATION_EXPORT double ReformGraphicsVersionNumber; 13 | 14 | //! Project version string for ReformGraphics. 15 | FOUNDATION_EXPORT const unsigned char ReformGraphicsVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/PivotSwitcher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PivotSwitcher.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 21.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import ReformCore 11 | import ReformStage 12 | 13 | public enum PivotChoice { 14 | case primary 15 | case secondary 16 | } 17 | 18 | extension PivotChoice { 19 | func pointFor(_ handle : AffineHandle) -> SnapPoint { 20 | switch self { 21 | case .primary: 22 | return handle.defaultPivot.0 23 | case .secondary: 24 | return handle.defaultPivot.1 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Analyzer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Analyzer.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformExpression 10 | 11 | public protocol Analyzer : class { 12 | func analyze(_ block: () -> ()) 13 | 14 | func publish(_ instruction: Analyzable, label: String) 15 | 16 | func publish(_ instruction: Analyzable, label: String, block: () -> ()) 17 | 18 | func announceForm(_ form: Form) 19 | 20 | func announceDepencency(_ id: PictureIdentifier) 21 | 22 | var stringifier : Stringifier { get } 23 | } 24 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/CompositeScaler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CompositeScaler.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct CompositeScaler : Scaler { 12 | private let scalers : [Scaler] 13 | 14 | init(scalers: Scaler...) { 15 | self.scalers = scalers 16 | } 17 | 18 | 19 | func scale(_ runtime: R, factor: Double, fix: Vec2d, axis: Vec2d) { 20 | for scaler in scalers { 21 | scaler.scale(runtime, factor: factor, fix: fix, axis: axis) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ConstantLength.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConstantLength.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | struct ConstantLength : RuntimeLength { 10 | fileprivate let length: Double 11 | 12 | init(length: Double) { 13 | self.length = length 14 | } 15 | 16 | func getLengthFor(_ runtime: R) -> Double? { 17 | return length 18 | } 19 | } 20 | 21 | extension ConstantLength : Equatable { 22 | } 23 | 24 | func ==(lhs: ConstantLength, rhs: ConstantLength) -> Bool { 25 | return lhs.length == rhs.length 26 | } 27 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/ReformExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReformExpression.h 3 | // ReformExpression 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ReformExpression. 12 | FOUNDATION_EXPORT double ReformExpressionVersionNumber; 13 | 14 | //! Project version string for ReformExpression. 15 | FOUNDATION_EXPORT const unsigned char ReformExpressionVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReformSerializer/ReformSerializer/ReformSerializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReformSerializer.h 3 | // ReformSerializer 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ReformSerializer. 12 | FOUNDATION_EXPORT double ReformSerializerVersionNumber; 13 | 14 | //! Project version string for ReformSerializer. 15 | FOUNDATION_EXPORT const unsigned char ReformSerializerVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/AngleAngleOperators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AngleAngleOperators.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 12.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public func +(lhs: Angle, rhs: Angle) -> Angle { 11 | return Angle(radians: lhs.radians + rhs.radians) 12 | } 13 | 14 | public func -(lhs: Angle, rhs: Angle) -> Angle { 15 | return Angle(radians: lhs.radians - rhs.radians) 16 | } 17 | 18 | public prefix func -(op: Angle) -> Angle { 19 | return Angle(radians: -op.radians) 20 | } 21 | 22 | public func /(lhs: Angle, rhs: Angle) -> Double { 23 | return lhs.radians / rhs.radians 24 | } 25 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/LineSegment2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LineSegment2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 21.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct LineSegment2d : Equatable { 10 | public let from: Vec2d 11 | public let to: Vec2d 12 | 13 | public init(from: Vec2d, to: Vec2d) { 14 | self.from = from 15 | self.to = to 16 | } 17 | } 18 | 19 | public func ==(lhs: LineSegment2d, rhs: LineSegment2d) -> Bool { 20 | return lhs.from == rhs.from && lhs.to == rhs.to 21 | } 22 | 23 | extension LineSegment2d { 24 | public var length : Double { 25 | return (to-from).length 26 | } 27 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/Sequence.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Sequence.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 21.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public protocol SequenceGeneratable { 10 | init(id: Int) 11 | } 12 | 13 | public final class IdentifierSequence { 14 | var sequenceValue : Int 15 | let type : T.Type 16 | 17 | public init(type: T.Type = T.self, initialValue : Int) { 18 | self.sequenceValue = initialValue 19 | self.type = type 20 | } 21 | 22 | public func emitId() -> T { 23 | sequenceValue += 1 24 | return type.init(id: sequenceValue) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/NullOutline.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NullOutline.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct NullOutline : Outline { 12 | func getPositionFor(_ runtime: R, t: Double) -> Vec2d? { 13 | return nil 14 | } 15 | 16 | func getLengthFor(_ runtime: R) -> Double? { 17 | return nil 18 | } 19 | 20 | func getSegmentsFor(_ runtime: R) -> SegmentPath { 21 | return [] 22 | } 23 | 24 | func getAABBFor(_ runtime: R) -> AABB2d? { 25 | return nil 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/AngleRange.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AngleRange.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 27.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct AngleRange : Equatable { 10 | public let start: Angle 11 | public let end: Angle 12 | 13 | public init(start: Angle, end: Angle) { 14 | self.start = normalize360(start) 15 | self.end = normalize360(end) 16 | } 17 | } 18 | 19 | public func ==(lhs:AngleRange, rhs:AngleRange) -> Bool { 20 | return lhs.start == rhs.start && lhs.end == rhs.end 21 | } 22 | 23 | extension AngleRange { 24 | var delta : Angle { 25 | return normalize360(end-start) 26 | } 27 | } -------------------------------------------------------------------------------- /ReformMath/ReformMath/Circle2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Circle2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 21.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Circle2d : Equatable { 10 | public let center: Vec2d 11 | public let radius: Double 12 | 13 | public init(center: Vec2d, radius: Double) { 14 | self.center = center 15 | self.radius = radius 16 | } 17 | } 18 | 19 | public func ==(lhs: Circle2d, rhs: Circle2d) -> Bool { 20 | return lhs.center == rhs.center && lhs.radius == rhs.radius 21 | } 22 | 23 | extension Circle2d { 24 | public var circumference : Double { 25 | return 2*Double.TAU*radius 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/NullTool.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NullTool.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformStage 11 | 12 | public final class NullTool : Tool { 13 | 14 | public init() { 15 | } 16 | 17 | public func setUp() { 18 | } 19 | 20 | public func tearDown() { 21 | } 22 | 23 | public func refresh() { 24 | } 25 | 26 | public func focusChange() { 27 | } 28 | 29 | public func cancel() { 30 | } 31 | 32 | public func process(_ input: Input, atPosition: Vec2d, withModifier: Modifier) { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ProxyTranslator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProxyTranslator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 25.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct ProxyTranslator : Translator { 12 | private let formReference : StaticFormReference 13 | 14 | init(formReference: StaticFormReference) { 15 | self.formReference = formReference 16 | } 17 | 18 | func translate(_ runtime: R, delta: Vec2d) { 19 | guard let form = formReference.getFormFor(runtime) as? Translatable else { 20 | return 21 | } 22 | 23 | form.translator.translate(runtime, delta: delta) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/Queue.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.swift 3 | // ExpressionEngine 4 | // 5 | // Created by Laszlo Korte on 08.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Queue { 10 | var _content = [T]() 11 | 12 | var isEmpty : Bool { 13 | return _content.isEmpty 14 | } 15 | 16 | mutating func add(_ element: T) { 17 | _content.append(element) 18 | } 19 | 20 | mutating func poll() -> T? { 21 | guard !_content.isEmpty else { 22 | return nil 23 | } 24 | return _content.removeFirst() 25 | } 26 | 27 | func peek() -> T? { 28 | return _content.first 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/Stack.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Stack.swift 3 | // ExpressionEngine 4 | // 5 | // Created by Laszlo Korte on 08.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Stack { 10 | var _content = [T]() 11 | 12 | var isEmpty : Bool { 13 | return _content.isEmpty 14 | } 15 | 16 | mutating func push(_ element: T) { 17 | _content.append(element) 18 | } 19 | 20 | mutating func pop() -> T? { 21 | guard !_content.isEmpty else { 22 | return nil 23 | } 24 | return _content.removeLast() 25 | } 26 | 27 | func peek() -> T? { 28 | return _content.last 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ProxyRotator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProxyRotator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 25.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct ProxyRotator : Rotator { 12 | private let formReference : StaticFormReference 13 | 14 | init(formReference: StaticFormReference) { 15 | self.formReference = formReference 16 | } 17 | 18 | 19 | func rotate(_ runtime: R, angle: Angle, fix: Vec2d) { 20 | guard let form = formReference.getFormFor(runtime) as? Rotatable else { 21 | return 22 | } 23 | 24 | form.rotator.rotate(runtime, angle: angle, fix: fix) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/BasicPointTranslator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BasicPointTranslator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct BasicPointTranslator : Translator { 12 | private let points : [WriteableRuntimePoint] 13 | 14 | init(points:WriteableRuntimePoint...) { 15 | self.points = points 16 | } 17 | 18 | func translate(_ runtime: R, delta: Vec2d) { 19 | for p in points { 20 | if let oldPos = p.getPositionFor(runtime) { 21 | p.setPositionFor(runtime, position: oldPos + delta) 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/BasicAngleRotator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BasicAngleRotator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct BasicAngleRotator : Rotator { 12 | private let angles : [WriteableRuntimeRotationAngle] 13 | 14 | init(angles:WriteableRuntimeRotationAngle...) { 15 | self.angles = angles 16 | } 17 | 18 | 19 | func rotate(_ runtime: R, angle: Angle, fix: Vec2d) { 20 | for a in angles { 21 | if let old = a.getAngleFor(runtime) { 22 | a.setAngleFor(runtime, angle: old + angle) 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/Aligner.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Alignment.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 19.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | 11 | enum AlignmentMode { 12 | case centered 13 | case aligned 14 | 15 | } 16 | 17 | 18 | public final class Aligner { 19 | var state : AlignmentMode = .aligned 20 | 21 | public init() {} 22 | 23 | func setMode(_ alignment: AlignmentMode) { 24 | state = alignment 25 | } 26 | 27 | func getAlignment() -> RuntimeAlignment { 28 | switch state { 29 | case .centered: return .centered 30 | case .aligned: return .leading 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ProxyScaler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProxyScaler.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 25.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct ProxyScaler : Scaler { 12 | private let formReference : StaticFormReference 13 | 14 | init(formReference: StaticFormReference) { 15 | self.formReference = formReference 16 | } 17 | 18 | 19 | func scale(_ runtime: R, factor: Double, fix: Vec2d, axis: Vec2d) { 20 | guard let form = formReference.getFormFor(runtime) as? Scalable else { 21 | return 22 | } 23 | 24 | form.scaler.scale(runtime, factor: factor, fix: fix, axis: axis) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/ScaleAxis.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Axis.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 21.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | 11 | public enum ScaleAxis { 12 | case none 13 | case named(String, formId: FormIdentifier, ExposedPointIdentifier, ExposedPointIdentifier) 14 | } 15 | 16 | extension ScaleAxis { 17 | public var runtimeAxis : RuntimeAxis { 18 | switch self { 19 | case .none: return .none 20 | case .named(let name, let formId, let a, let b): 21 | return .named(name, from: AnonymousFormPoint(formId: formId, pointId: a), to: AnonymousFormPoint(formId: formId, pointId: b)) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/MaskUIRenderer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MaskUIRenderer.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 30.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ReformStage 11 | import ReformTools 12 | 13 | 14 | struct MaskUIRenderer : Renderer { 15 | let maskUI : MaskUI 16 | 17 | func renderInContext(_ context: CGContext) { 18 | 19 | if case .clip(let x, let y, let width, let height) = maskUI.state { 20 | context.setFillColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 1) 21 | context.fill(context.boundingBoxOfClipPath) 22 | 23 | context.clip(to: CGRect(x: x, y: y, width: width, height: height)) 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Length.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Length.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol RuntimeLength { 12 | func getLengthFor(_ runtime: R) -> Double? 13 | 14 | func isEqualTo(_ other: RuntimeLength) -> Bool 15 | } 16 | 17 | public protocol WriteableRuntimeLength : RuntimeLength { 18 | func setLengthFor(_ runtime: R, length: Double) 19 | } 20 | 21 | extension RuntimeLength where Self : Equatable { 22 | func isEqualTo(_ other: RuntimeLength) -> Bool { 23 | guard let other = other as? Self else { 24 | return false 25 | } 26 | 27 | return self == other 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/SnapPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapPoint.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformCore 11 | 12 | public protocol SnapPoint { 13 | var position : Vec2d { get } 14 | var label : String { get } 15 | 16 | var runtimePoint : LabeledPoint { get } 17 | 18 | func belongsTo(_ formId: FormIdentifier) -> Bool 19 | 20 | func equals(_ other: SnapPoint) -> Bool 21 | } 22 | 23 | extension SnapPoint where Self : Equatable { 24 | public func equals(_ other: SnapPoint) -> Bool { 25 | guard let o = other as? Self else { 26 | return false 27 | } 28 | 29 | return o == self 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ReferencePoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReferencePoint.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import ReformMath 11 | 12 | public protocol RuntimePoint { 13 | func getPositionFor(_ runtime: R) -> Vec2d? 14 | 15 | func isEqualTo(_ other: RuntimePoint) -> Bool 16 | } 17 | 18 | public protocol WriteableRuntimePoint : RuntimePoint { 19 | func setPositionFor(_ runtime: R, position: Vec2d) 20 | } 21 | 22 | extension RuntimePoint where Self : Equatable { 23 | public func isEqualTo(_ other: RuntimePoint) -> Bool { 24 | guard let other = other as? Self else { 25 | return false 26 | } 27 | 28 | return self == other 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ReformSerializer/ReformSerializer/Normalizer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Normalizer.swift 3 | // ReformSerializer 4 | // 5 | // Created by Laszlo Korte on 31.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public enum InitialisationError : Error { 10 | case unknown 11 | } 12 | 13 | public enum NormalizationError : Error { 14 | case notNormalizable(Any.Type) 15 | } 16 | 17 | public enum NormalizedValue { 18 | case null 19 | case bool(Swift.Bool) 20 | case string(Swift.String) 21 | case int(Swift.Int) 22 | case double(Swift.Double) 23 | case array([NormalizedValue]) 24 | case dictionary([Swift.String:NormalizedValue]) 25 | } 26 | 27 | public protocol Normalizable { 28 | func normalize() throws -> NormalizedValue 29 | 30 | init(normalizedValue: NormalizedValue) throws 31 | } 32 | 33 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/AnchorPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AnchorPoint.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct AnchorPoint : RuntimePoint, Labeled { 12 | fileprivate let anchor : Anchor 13 | 14 | init(anchor: Anchor) { 15 | self.anchor = anchor 16 | } 17 | 18 | func getPositionFor(_ runtime: R) -> Vec2d? { 19 | return anchor.getPositionFor(runtime) 20 | } 21 | 22 | func getDescription(_ stringifier: Stringifier) -> String { 23 | return anchor.name 24 | } 25 | } 26 | 27 | 28 | 29 | extension AnchorPoint : Equatable { 30 | 31 | } 32 | 33 | func ==(lhs: AnchorPoint, rhs: AnchorPoint) -> Bool { 34 | return lhs.anchor.isEqualTo(rhs.anchor) 35 | } 36 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/BasicPointRotator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BasicPointRotator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import ReformMath 11 | 12 | struct BasicPointRotator : Rotator { 13 | private let points : [WriteableRuntimePoint] 14 | 15 | init(points:WriteableRuntimePoint...) { 16 | self.points = points 17 | } 18 | 19 | 20 | func rotate(_ runtime: R, angle: Angle, fix: Vec2d) { 21 | for point in points { 22 | if let oldPos = point.getPositionFor(runtime) { 23 | let delta = oldPos - fix 24 | 25 | point.setPositionFor(runtime, position: fix + ReformMath.rotate(delta, angle: angle)) 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ReformCore/ReformCoreTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformMath/ReformMathTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformStage/ReformStageTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformTools/ReformToolsTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpressionTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformGraphics/ReformGraphicsTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformSerializer/ReformSerializerTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplicationTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplicationUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/FormIdentifier.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FormIdentifier.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct FormIdentifier : Hashable { 10 | public let value : Int 11 | 12 | public init(_ value : Int) { 13 | self.value = value 14 | } 15 | 16 | public var hashValue : Int { return Int(value) } 17 | } 18 | 19 | public func ==(lhs: FormIdentifier, rhs: FormIdentifier) -> Bool { 20 | return lhs.value == rhs.value 21 | } 22 | 23 | extension FormIdentifier : CustomDebugStringConvertible { 24 | public var debugDescription : String { 25 | return "FormId(\(value))" 26 | } 27 | } 28 | 29 | extension FormIdentifier : SequenceGeneratable { 30 | public init(id : Int) { 31 | self.init(id) 32 | } 33 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/RotationAngle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RotationAngle.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol RuntimeRotationAngle : Degeneratable { 12 | func getAngleFor(_ runtime: R) -> Angle? 13 | 14 | func isEqualTo(_ other: RuntimeRotationAngle) -> Bool 15 | } 16 | 17 | public protocol WriteableRuntimeRotationAngle : RuntimeRotationAngle { 18 | func setAngleFor(_ runtime: R, angle: Angle) 19 | } 20 | 21 | 22 | 23 | extension RuntimeRotationAngle where Self : Equatable { 24 | public func isEqualTo(_ other: RuntimeRotationAngle) -> Bool { 25 | guard let other = other as? Self else { 26 | return false 27 | } 28 | 29 | return self == other 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/ToolController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ToolController.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public typealias ChangeNotifier = () -> () 12 | 13 | public final class ToolController { 14 | public var currentTool : Tool = NullTool() { 15 | willSet { 16 | currentTool.tearDown() 17 | } 18 | 19 | didSet { 20 | currentTool.setUp() 21 | } 22 | } 23 | 24 | public init() { 25 | 26 | } 27 | 28 | 29 | public func process(_ input: Input, atPosition: Vec2d, withModifier: Modifier) { 30 | currentTool.process(input, atPosition: atPosition, withModifier: withModifier) 31 | } 32 | 33 | public func cancel() { 34 | currentTool.cancel() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Ray2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Ray2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 21.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Ray2d : Equatable { 10 | public let from: Vec2d 11 | public let direction: Vec2d 12 | 13 | public init?(from: Vec2d, direction: Vec2d) { 14 | guard let dir = normalize(direction) else { 15 | return nil 16 | } 17 | self.from = from 18 | self.direction = dir 19 | } 20 | 21 | public init(from: Vec2d, angle: Angle) { 22 | self.from = from 23 | self.direction = Vec2d(radius: 1, angle: angle) 24 | } 25 | } 26 | 27 | public func ==(lhs: Ray2d, rhs: Ray2d) -> Bool { 28 | return lhs.from == rhs.from && lhs.direction == rhs.direction 29 | } 30 | 31 | extension Ray2d { 32 | public var angle : Angle { 33 | return ReformMath.angle(direction) 34 | } 35 | } -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/StageViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StageViewModel.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 26.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformStage 10 | import ReformTools 11 | 12 | final class StageViewModel { 13 | let stage : Stage 14 | let stageUI : StageUI 15 | let toolController : ToolController 16 | let selection : FormSelection 17 | let camera: Camera 18 | let selectionChanger : FormSelectionChanger 19 | 20 | init(stage: Stage, stageUI: StageUI, toolController : ToolController, selection: FormSelection, camera: Camera, selectionChanger: FormSelectionChanger) { 21 | self.stage = stage 22 | self.stageUI = stageUI 23 | self.toolController = toolController 24 | self.selection = selection 25 | self.camera = camera 26 | self.selectionChanger = selectionChanger 27 | } 28 | } -------------------------------------------------------------------------------- /ReformMath/ReformMath/Line2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Line2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 23.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public struct Line2d : Equatable { 11 | public let from: Vec2d 12 | public let direction: Vec2d 13 | 14 | public init?(from: Vec2d, direction: Vec2d) { 15 | guard let dir = normalize(direction) else { 16 | return nil 17 | } 18 | self.from = from 19 | self.direction = dir 20 | } 21 | 22 | public init(from: Vec2d, angle: Angle) { 23 | self.from = from 24 | self.direction = Vec2d(radius: 1, angle: angle) 25 | } 26 | } 27 | 28 | public func ==(lhs: Line2d, rhs: Line2d) -> Bool { 29 | return lhs.from == rhs.from && lhs.direction == rhs.direction 30 | } 31 | 32 | extension Line2d { 33 | public var angle : Angle { 34 | return ReformMath.angle(direction) 35 | } 36 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/NameAllocator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NameAllocator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 21.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public class NameAllocator { 10 | private var taken = Set() 11 | 12 | public init() { 13 | } 14 | 15 | public func reset() { 16 | taken.removeAll(keepingCapacity: true) 17 | } 18 | 19 | public func alloc(_ requested: String, numbered: Bool = false) -> String { 20 | var tested = requested 21 | var count = 0 22 | 23 | if numbered { 24 | count += 1 25 | tested = "\(requested) \(count)" 26 | } 27 | 28 | while taken.contains(tested) { 29 | count += 1 30 | tested = "\(requested) \(count)" 31 | } 32 | 33 | return tested 34 | } 35 | 36 | public func announce(_ name: String) { 37 | taken.insert(name) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/BasicPointScaler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BasicPointRotator.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct BasicPointScaler : Scaler { 12 | private let points : [WriteableRuntimePoint] 13 | 14 | init(points:WriteableRuntimePoint...) { 15 | self.points = points 16 | } 17 | 18 | 19 | func scale(_ runtime : R, factor: Double, fix: Vec2d, axis: Vec2d) { 20 | 21 | for point in points { 22 | if let pos = point.getPositionFor(runtime) { 23 | let delta = pos - fix 24 | 25 | let projected = project(delta, onto: axis) 26 | 27 | let scaled = delta + projected * (factor - 1) 28 | 29 | point.setPositionFor(runtime, position: fix + scaled) 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ConstantScaleFactor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConstantScaleFactor.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 21.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | public struct ConstantScaleFactor : RuntimeScaleFactor, Labeled { 13 | fileprivate let factor: Double 14 | 15 | public init(factor: Double) { 16 | self.factor = factor 17 | } 18 | 19 | public func getFactorFor(_ runtime: R) -> Double? { 20 | return factor 21 | } 22 | 23 | public func getDescription(_ stringifier: Stringifier) -> String { 24 | return String(format: "%.2f%%", factor * 100) 25 | } 26 | 27 | public var isDegenerated : Bool { 28 | return factor == 1 29 | } 30 | } 31 | 32 | func combine(factor a: ConstantScaleFactor, factor b: ConstantScaleFactor) -> ConstantScaleFactor { 33 | return ConstantScaleFactor(factor: a.factor * b.factor) 34 | } 35 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/PointLength.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PointLength.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 22.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct PointLength : RuntimeLength { 12 | fileprivate let pointA : RuntimePoint 13 | fileprivate let pointB : RuntimePoint 14 | 15 | init(pointA: RuntimePoint, pointB: RuntimePoint) { 16 | self.pointA = pointA 17 | self.pointB = pointB 18 | } 19 | 20 | func getLengthFor(_ runtime: R) -> Double? { 21 | guard let a = pointA.getPositionFor(runtime), 22 | let b = pointB.getPositionFor(runtime) else { 23 | return nil 24 | } 25 | return (b-a).length 26 | } 27 | } 28 | 29 | extension PointLength : Equatable { 30 | } 31 | 32 | func ==(lhs: PointLength, rhs: PointLength) -> Bool { 33 | return lhs.pointA.isEqualTo(rhs.pointA) && lhs.pointB.isEqualTo(rhs.pointB) 34 | } 35 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Outline.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Outline.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol Outline { 12 | func getPositionFor(_ runtime: R, t: Double) -> Vec2d? 13 | 14 | func getLengthFor(_ runtime: R) -> Double? 15 | 16 | func getSegmentsFor(_ runtime: R) -> SegmentPath 17 | 18 | func getAABBFor(_ runtime: R) -> AABB2d? 19 | } 20 | 21 | 22 | func intersectionsForRuntime(_ runtime: R, a: Outline, b: Outline) -> [Vec2d] { 23 | var result : [Vec2d] = [] 24 | 25 | for segmentA in a.getSegmentsFor(runtime) { 26 | for segmentB in b.getSegmentsFor(runtime) { 27 | for intersection in intersect(segment: segmentA, and: segmentB) { 28 | result.append(intersection) 29 | } 30 | } 31 | } 32 | 33 | return result 34 | } 35 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/GradientView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GradientView.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 30.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Cocoa 11 | 12 | final class GradientView : NSView { 13 | 14 | override func draw(_ dirtyRect: NSRect) { 15 | if let main = self.window?.isKeyWindow, !main { 16 | NSGradient( 17 | starting: NSColor(red: 0.9647, green:0.9647, blue: 0.9647, alpha: 1.0), 18 | ending: NSColor(red: 0.9647, green:0.9647, blue: 0.9647, alpha: 1.0) 19 | 20 | )?.draw(in: self.bounds, angle: -90) 21 | } else { 22 | NSGradient( 23 | starting: NSColor(red: 0.8157, green:0.8118, blue: 0.8157, alpha: 1.0), 24 | ending: NSColor(red: 0.69, green:0.69, blue: 0.69, alpha: 1.0) 25 | 26 | )?.draw(in: self.bounds, angle: -90) 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ConstantDistance.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConstantDistance.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 19.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct ConstantDistance : RuntimeDistance, Labeled { 12 | public typealias PointType = RuntimePoint & Labeled 13 | 14 | public let delta: Vec2d 15 | 16 | public init(delta: Vec2d) { 17 | self.delta = delta 18 | } 19 | 20 | public func getDeltaFor(_ runtime: R) -> Vec2d? { 21 | return delta 22 | } 23 | 24 | public func getDescription(_ stringifier: Stringifier) -> String { 25 | return delta.label 26 | } 27 | 28 | 29 | 30 | public var isDegenerated : Bool { 31 | return delta.x == 0 && delta.y == 0 32 | } 33 | } 34 | 35 | func combine(distance a: ConstantDistance, distance b: ConstantDistance) -> ConstantDistance { 36 | return ConstantDistance(delta: a.delta + b.delta) 37 | } 38 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/GlompSnapPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GlompSnapPoint.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformCore 11 | 12 | public struct GlompSnapPoint : SnapPoint, Equatable { 13 | public let position : Vec2d 14 | public let label : String 15 | let point : GlompPoint 16 | 17 | public init(position: Vec2d, label: String, point: ReformCore.GlompPoint) { 18 | self.position = position 19 | self.label = label 20 | self.point = point 21 | } 22 | 23 | public var runtimePoint : LabeledPoint { 24 | return point 25 | } 26 | 27 | public func belongsTo(_ formId: FormIdentifier) -> Bool { 28 | return point.formId == formId 29 | } 30 | } 31 | 32 | public func ==(lhs: GlompSnapPoint, rhs: GlompSnapPoint) -> Bool { 33 | return lhs.position == rhs.position && lhs.label == rhs.label && lhs.point == rhs.point 34 | } 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Xcode 4 | # 5 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 6 | 7 | ## Build generated 8 | build/ 9 | DerivedData 10 | 11 | ## Various settings 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata 21 | 22 | ## Other 23 | *.xccheckout 24 | *.moved-aside 25 | *.xcuserstate 26 | *.xcscmblueprint 27 | 28 | ## Obj-C/Swift specific 29 | *.hmap 30 | *.ipa 31 | 32 | # CocoaPods 33 | # 34 | # We recommend against adding the Pods directory to your .gitignore. However 35 | # you should judge for yourself, the pros and cons are mentioned at: 36 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 37 | # 38 | # Pods/ 39 | 40 | # Carthage 41 | # 42 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 43 | # Carthage/Checkouts 44 | 45 | Carthage/Build 46 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2015 Laszlo Korte. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2015 Laszlo Korte. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2015 Laszlo Korte. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/FormSelection.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EntitySelection.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformStage 11 | 12 | public final class FormSelection { 13 | public fileprivate(set) var selected : Set = Set() 14 | 15 | public init() {} 16 | } 17 | 18 | 19 | extension FormSelection { 20 | public var one : FormIdentifier? { 21 | if selected.count == 1 { 22 | return selected.first 23 | } else { 24 | return nil 25 | } 26 | } 27 | 28 | public func clear() { 29 | selected.removeAll() 30 | } 31 | 32 | public func select(_ formIds: Set) { 33 | selected.removeAll() 34 | 35 | selected.formUnion(formIds) 36 | } 37 | 38 | public func select(_ formId: FormIdentifier) { 39 | selected.removeAll() 40 | 41 | selected.insert(formId) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2015 Laszlo Korte. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/CenterPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CenterPoint.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct CenterPoint : RuntimePoint { 12 | fileprivate let pointA : RuntimePoint 13 | fileprivate let pointB : RuntimePoint 14 | 15 | init(pointA: RuntimePoint, pointB: RuntimePoint) { 16 | self.pointA = pointA 17 | self.pointB = pointB 18 | } 19 | 20 | func getPositionFor(_ runtime: R) -> Vec2d? { 21 | guard let 22 | a = pointA.getPositionFor(runtime), 23 | let b = pointB.getPositionFor(runtime) else { 24 | return nil 25 | } 26 | 27 | return (a + b) / 2 28 | } 29 | } 30 | 31 | 32 | extension CenterPoint : Equatable { 33 | 34 | } 35 | 36 | 37 | func ==(lhs: CenterPoint, rhs: CenterPoint) -> Bool { 38 | return lhs.pointA.isEqualTo(rhs.pointA) && lhs.pointB.isEqualTo(rhs.pointB) 39 | } 40 | 41 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2015 Laszlo Korte. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ReformGraphics/ReformGraphics/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2015 Laszlo Korte. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ReformSerializer/ReformSerializer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2015 Laszlo Korte. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/GridSnapPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GridSnapPoint.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 01.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformCore 11 | 12 | public struct GridSnapPoint : SnapPoint, Equatable { 13 | public let position : Vec2d 14 | let point : GridPoint 15 | 16 | public init(position: Vec2d, point: GridPoint) { 17 | self.position = position 18 | self.point = point 19 | } 20 | 21 | public var label : String { 22 | return String(format: "%.1%% Horizontally, %.1f%% Vertically", point.percent.x * 100, point.percent.y * 100) 23 | } 24 | 25 | public var runtimePoint : LabeledPoint { 26 | return point 27 | } 28 | 29 | public func belongsTo(_ formId: FormIdentifier) -> Bool { 30 | return false 31 | } 32 | } 33 | 34 | public func ==(lhs: GridSnapPoint, rhs: GridSnapPoint) -> Bool { 35 | return lhs.position == rhs.position && lhs.point == rhs.point 36 | } 37 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/PivotUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PivotUI.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 18.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ReformTools 11 | import ReformStage 12 | 13 | struct PivotUIRenderer : Renderer { 14 | let pivotUI : PivotUI 15 | let camera: Camera 16 | 17 | func renderInContext(_ context: CGContext) { 18 | let inverse = CGFloat(1 / camera.zoom) 19 | 20 | context.setFillColor(red: 0.9, green: 0.3, blue: 0.8, alpha: 1) 21 | context.setStrokeColor(red: 0.8, green: 0.2, blue: 0.7, alpha: 1) 22 | context.setLineWidth(1*inverse) 23 | let dotSize : Double = 4 / camera.zoom 24 | 25 | switch pivotUI.state { 26 | case .hide: 27 | return 28 | case .show(let point): 29 | drawDotAt(context, position: point.position, size: dotSize*1.5) 30 | context.drawPath(using: .fillStroke) 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/StaticPointAnchor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StaticPointAnchor.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct StaticPointAnchor : Anchor { 12 | 13 | fileprivate let point : WriteableRuntimePoint 14 | let name : String 15 | 16 | init(point : WriteableRuntimePoint, name: String) { 17 | self.point = point 18 | self.name = name 19 | } 20 | 21 | func getPositionFor(_ runtime: R) -> Vec2d? { 22 | return point.getPositionFor(runtime) 23 | } 24 | 25 | func translate(_ runtime: R, delta: Vec2d) { 26 | if let oldPos = point.getPositionFor(runtime) { 27 | point.setPositionFor(runtime, position: oldPos + delta) 28 | } 29 | } 30 | } 31 | 32 | extension StaticPointAnchor : Equatable { 33 | } 34 | 35 | func ==(lhs: StaticPointAnchor, rhs: StaticPointAnchor) -> Bool { 36 | return lhs.point.isEqualTo(rhs.point) 37 | } 38 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/Parser.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Precedence.swift 3 | // ExpressionEngine 4 | // 5 | // Created by Laszlo Korte on 08.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Precedence : Comparable { 10 | fileprivate let value : Int8 11 | 12 | public init(_ value : Int8) { 13 | self.value = value 14 | } 15 | } 16 | 17 | public func <(lhs: Precedence, rhs: Precedence) -> Bool { 18 | return lhs.value < rhs.value 19 | } 20 | 21 | public func ==(lhs: Precedence, rhs: Precedence) -> Bool { 22 | return lhs.value == rhs.value 23 | } 24 | 25 | 26 | public enum OperatorArity { 27 | case binary 28 | case unary 29 | } 30 | 31 | public enum Associativity { 32 | case left 33 | case right 34 | } 35 | 36 | public protocol Parser { 37 | associatedtype NodeType 38 | associatedtype TokenType 39 | associatedtype ParseErrorType : Error 40 | 41 | func parse(_ tokens: T) -> Result where T.Iterator.Element==TokenType 42 | } 43 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Modifier.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Modifier.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 18.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ReformTools 11 | 12 | extension Modifier { 13 | static func fromEvent(_ event: NSEvent) -> Modifier { 14 | var result : Modifier = [] 15 | 16 | 17 | if event.modifierFlags.contains(NSEvent.ModifierFlags.shift) { 18 | result.formUnion(Modifier.Streight) 19 | } 20 | 21 | if event.modifierFlags.contains(NSEvent.ModifierFlags.option) { 22 | result.formUnion(Modifier.AlternativeAlignment) 23 | } 24 | 25 | if event.modifierFlags.contains(NSEvent.ModifierFlags.command) { 26 | result.formUnion(Modifier.Glomp) 27 | } 28 | 29 | if event.modifierFlags.contains(NSEvent.ModifierFlags.control) { 30 | result.formUnion(Modifier.Free) 31 | } 32 | 33 | 34 | return result 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/ExportController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExportController.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 07.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import ReformCore 11 | import ReformSerializer 12 | 13 | final class ExportController : NSViewController { 14 | @IBOutlet var jsonField : NSTextField? 15 | 16 | let jsonFormat = JsonFormat() 17 | 18 | var projectSession : ProjectSession? { 19 | didSet { updateJson() } 20 | } 21 | 22 | override func viewDidAppear() { 23 | updateJson() 24 | } 25 | 26 | func cancel(_ sender: Any?) { 27 | dismissViewController(self) 28 | } 29 | 30 | func updateJson() { 31 | do { 32 | guard let normProj = try projectSession?.project.normalize() else { 33 | return 34 | } 35 | 36 | jsonField?.stringValue = jsonFormat.encode(normProj) 37 | } catch let e { 38 | jsonField?.stringValue = String(describing: e) 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/PointAngle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PointAngle.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 22.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct PointAngle : RuntimeRotationAngle { 12 | fileprivate let center : RuntimePoint 13 | fileprivate let point : RuntimePoint 14 | 15 | init(center: RuntimePoint, point: RuntimePoint) { 16 | self.center = center 17 | self.point = point 18 | } 19 | 20 | func getAngleFor(_ runtime: R) -> Angle? { 21 | guard let c = center.getPositionFor(runtime), 22 | let p = point.getPositionFor(runtime) else { 23 | return nil 24 | } 25 | return normalize360(angle(p-c)) 26 | } 27 | 28 | var isDegenerated : Bool { 29 | return false 30 | } 31 | } 32 | 33 | 34 | extension PointAngle : Equatable { 35 | } 36 | 37 | func ==(lhs: PointAngle, rhs: PointAngle) -> Bool { 38 | return lhs.center.isEqualTo(rhs.center) && lhs.point.isEqualTo(rhs.point) 39 | } 40 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/StaticFormReference.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FormReference.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 25.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | struct StaticFormReference : Equatable { 10 | fileprivate let formId : FormIdentifier 11 | fileprivate let offset : Int 12 | 13 | 14 | init(formId: FormIdentifier, offset: Int) { 15 | self.formId = formId 16 | self.offset = offset 17 | } 18 | 19 | func getFormFor(_ runtime: R) -> Form? { 20 | guard let 21 | id = runtime.read(formId, offset: offset) else { 22 | return nil 23 | } 24 | 25 | return runtime.get(FormIdentifier(Int(id))) 26 | } 27 | 28 | func setFormFor(_ runtime: R, form: Form) { 29 | runtime.write(formId, offset: offset, value: UInt64(bitPattern: Int64(form.identifier.value))) 30 | 31 | } 32 | } 33 | 34 | func ==(lhs: StaticFormReference, rhs: StaticFormReference) -> Bool { 35 | return lhs.formId == rhs.formId && lhs.offset == rhs.offset 36 | } 37 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/StaticLength.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StaticLength.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | struct StaticLength : WriteableRuntimeLength { 11 | fileprivate let formId : FormIdentifier 12 | fileprivate let offset : Int 13 | 14 | init(formId: FormIdentifier, offset: Int) { 15 | self.formId = formId 16 | self.offset = offset 17 | } 18 | 19 | func getLengthFor(_ runtime: R) -> Double? { 20 | guard let l = runtime.read(formId, offset: offset) else { 21 | return nil 22 | } 23 | return Double(bitPattern: l) 24 | } 25 | 26 | 27 | func setLengthFor(_ runtime: R, length: Double) { 28 | runtime.write(formId, offset: offset, value: length.bitPattern) 29 | } 30 | } 31 | 32 | 33 | extension StaticLength : Equatable { 34 | } 35 | 36 | func ==(lhs: StaticLength, rhs: StaticLength) -> Bool { 37 | return lhs.formId == rhs.formId && lhs.offset == rhs.offset 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Laszlo Korte 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /ReformMath/ReformMath/Triangle2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Triangle2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 21.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Triangle2d : Equatable { 10 | public let a: Vec2d 11 | public let b: Vec2d 12 | public let c: Vec2d 13 | 14 | public init(a: Vec2d, b: Vec2d, c: Vec2d) { 15 | self.a = a 16 | self.b = b 17 | self.c = c 18 | } 19 | } 20 | 21 | public func ==(lhs: Triangle2d, rhs: Triangle2d) -> Bool { 22 | return lhs.a == rhs.a && lhs.b == rhs.b && lhs.c == rhs.c 23 | } 24 | 25 | extension Triangle2d { 26 | public var area : Double { 27 | // Heron's formula 28 | let s = circumference / 2 29 | let la = distance(point: a,point: b) 30 | let lb = distance(point: b,point: c) 31 | let lc = distance(point: c,point: a) 32 | return sqrt(s * (s-la) * (s-lb) * (s-lc)) 33 | } 34 | 35 | public var circumference : Double { 36 | return distance(point: a, point: b) + distance(point: b, point: c) + distance(point: c, point: a) 37 | } 38 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/ConstantAngel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConstantAngel.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct ConstantAngle : RuntimeRotationAngle, Labeled { 12 | public let angle: Angle 13 | 14 | public init(angle: Angle = Angle()) { 15 | self.angle = angle 16 | } 17 | 18 | public func getAngleFor(_ runtime: R) -> Angle? { 19 | return angle 20 | } 21 | 22 | public func getDescription(_ stringifier: Stringifier) -> String { 23 | return String(format: "%.2f%%", angle.percent) 24 | } 25 | 26 | public var isDegenerated : Bool { 27 | return angle.radians == 0 28 | } 29 | } 30 | 31 | extension ConstantAngle : Equatable { 32 | } 33 | 34 | public func ==(lhs: ConstantAngle, rhs: ConstantAngle) -> Bool { 35 | return lhs.angle == rhs.angle 36 | } 37 | 38 | func combine(angle a: ConstantAngle, angle b: ConstantAngle) -> ConstantAngle { 39 | return ConstantAngle(angle: normalize360(a.angle + b.angle)) 40 | } 41 | -------------------------------------------------------------------------------- /ReformGraphics/ReformGraphics/Shape.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Shape.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct Shape { 12 | let background: Background 13 | let stroke: Stroke 14 | let area : FillArea 15 | 16 | public init() { 17 | background = .none 18 | stroke = .none 19 | area = .pathArea(Path()) 20 | } 21 | 22 | public init(area : FillArea, background : Background = .none, stroke: Stroke = .none) { 23 | self.area = area 24 | self.stroke = stroke 25 | self.background = background 26 | } 27 | } 28 | 29 | public enum Aligment { 30 | case left 31 | case right 32 | case center 33 | } 34 | 35 | public enum FillArea { 36 | case pathArea(Path) 37 | case textArea(Vec2d, Vec2d, alignment: Aligment, text: String, size: Double) 38 | } 39 | 40 | public enum Background { 41 | case fill(Color) 42 | case none 43 | } 44 | 45 | public enum Stroke { 46 | case solid(width: Double, color: Color) 47 | case none 48 | } 49 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Picture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Picture.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformExpression 10 | 11 | public struct PictureIdentifier : Hashable { 12 | public let value : Int 13 | 14 | public init(_ id : Int) { 15 | self.value = id 16 | } 17 | 18 | public var hashValue : Int { return value } 19 | } 20 | 21 | public func ==(lhs: PictureIdentifier, rhs: PictureIdentifier) -> Bool { 22 | return lhs.value == rhs.value 23 | } 24 | 25 | final public class Picture { 26 | 27 | public let identifier : PictureIdentifier 28 | public var name : String 29 | public var size : (Double, Double) 30 | public let procedure : Procedure 31 | public let data : Sheet 32 | 33 | 34 | public init(identifier : PictureIdentifier, name: String, size: (Double, Double), data: Sheet, procedure : Procedure) { 35 | self.identifier = identifier 36 | self.name = name 37 | self.procedure = procedure 38 | self.size = size 39 | self.data = data 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /ReformStage/ReformStage/IntersectionSnapPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IntersectionSnapPoint.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformMath 11 | 12 | public struct IntersectionSnapPoint : SnapPoint, Equatable { 13 | public let position : Vec2d 14 | public let label : String 15 | public let point : RuntimeIntersectionPoint 16 | 17 | public var runtimePoint : LabeledPoint { 18 | return point 19 | } 20 | 21 | public func belongsTo(_ formId: FormIdentifier) -> Bool { 22 | return formId == self.point.formA 23 | || formId == self.point.formB 24 | } 25 | } 26 | 27 | public func ==(lhs: IntersectionSnapPoint, rhs: IntersectionSnapPoint) -> Bool { 28 | return lhs.position == rhs.position && lhs.label == rhs.label && lhs.point == rhs.point 29 | } 30 | 31 | extension IntersectionSnapPoint { 32 | public var formIdA : FormIdentifier { 33 | return point.formA 34 | } 35 | 36 | public var formIdB : FormIdentifier { 37 | return point.formB 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/PreviewTool.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PreviewTool.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformGraphics 11 | import ReformStage 12 | 13 | public final class PreviewTool : Tool { 14 | 15 | private let maskUI : MaskUI 16 | private let stage : Stage 17 | 18 | public init(stage: Stage, maskUI: MaskUI) { 19 | self.stage = stage 20 | self.maskUI = maskUI 21 | } 22 | 23 | public func setUp() { 24 | let size = stage.size 25 | maskUI.state = .clip(x:0, y:0,width: size.x, height: size.y) 26 | } 27 | 28 | public func tearDown() { 29 | maskUI.state = .disabled 30 | } 31 | 32 | public func refresh() { 33 | let size = stage.size 34 | maskUI.state = .clip(x:0, y:0,width: size.x, height: size.y) 35 | } 36 | 37 | public func focusChange() { 38 | } 39 | 40 | public func cancel() { 41 | } 42 | 43 | public func process(_ input: Input, atPosition: Vec2d, withModifier: Modifier) { 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ReformCore/ReformCoreTests/ReformCoreTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReformCoreTests.swift 3 | // ReformCoreTests 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ReformCore 11 | 12 | class ReformCoreTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ReformStage/ReformStageTests/ReformStageTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReformStageTests.swift 3 | // ReformStageTests 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ReformStage 11 | 12 | final class ReformStageTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/Input.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Input.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | 12 | public struct Modifier : OptionSet { 13 | public let rawValue : Int 14 | 15 | public init(rawValue: Int) { 16 | self.rawValue = rawValue 17 | } 18 | 19 | public static let Streight = Modifier(rawValue: 1) 20 | public static let AlternativeAlignment = Modifier(rawValue: 2) 21 | public static let Glomp = Modifier(rawValue: 4) 22 | public static let Free = Modifier(rawValue: 8) 23 | } 24 | 25 | public func ==(lhs: Modifier, rhs: Modifier) -> Bool { 26 | return lhs.rawValue == rhs.rawValue 27 | } 28 | 29 | extension Modifier { 30 | 31 | var isStreight : Bool { 32 | return contains(Modifier.Streight) 33 | } 34 | 35 | var isAlignOption : Bool { 36 | return contains(Modifier.AlternativeAlignment) 37 | } 38 | } 39 | 40 | public enum Input { 41 | case move 42 | case press 43 | case release 44 | case cycle 45 | case toggle 46 | case modifierChange 47 | } 48 | -------------------------------------------------------------------------------- /ReformTools/ReformToolsTests/ReformToolsTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReformToolsTests.swift 3 | // ReformToolsTests 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ReformTools 11 | 12 | final class ReformToolsTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ReformGraphics/ReformGraphicsTests/ReformGraphicsTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReformGraphicsTests.swift 3 | // ReformGraphicsTests 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ReformGraphics 11 | 12 | final class ReformGraphicsTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/GridPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GridPoint.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 01.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct GridPoint : RuntimePoint, Labeled, Equatable { 12 | public let percent : Vec2d 13 | 14 | public init(percent: Vec2d) { 15 | self.percent = percent 16 | } 17 | 18 | public func getPositionFor(_ runtime: R) -> Vec2d? { 19 | guard let canvas = runtime.get(FormIdentifier(0)) as? Paper else { 20 | return nil 21 | } 22 | 23 | guard let 24 | width = canvas.width.getLengthFor(runtime), 25 | let height = canvas.height.getLengthFor(runtime) else { 26 | return nil 27 | } 28 | 29 | return Vec2d(x: width, y: height) * percent 30 | } 31 | 32 | public func getDescription(_ stringifier: Stringifier) -> String { 33 | return String(format: "%.1f%% Horizontally, %.1f%% Vertically", percent.x * 100, percent.y * 100) 34 | } 35 | } 36 | 37 | public func ==(lhs: GridPoint, rhs: GridPoint) -> Bool { 38 | return lhs.percent == rhs.percent 39 | } 40 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplicationTests/ReformApplicationTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReformApplicationTests.swift 3 | // ReformApplicationTests 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ReformApplication 11 | 12 | class ReformApplicationTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Axis.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Axis.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 21.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public enum RuntimeAxis : Equatable { 12 | case none 13 | case named(String, from: RuntimePoint, to: RuntimePoint) 14 | } 15 | 16 | extension RuntimeAxis { 17 | func getVectorFor(_ runtime: R) -> Vec2d? { 18 | switch self { 19 | case .none: return Vec2d() 20 | case .named(_, let from, let to): 21 | guard let 22 | start = from.getPositionFor(runtime), 23 | let end = to.getPositionFor(runtime) else { 24 | return nil 25 | } 26 | 27 | return normalize((end - start)) 28 | } 29 | } 30 | } 31 | 32 | public func ==(lhs: RuntimeAxis, rhs: RuntimeAxis) -> Bool { 33 | switch (lhs, rhs) { 34 | case (.none, .none): return true 35 | case (.named(let nameA, let fromA, let toA),.named(let nameB, let formB, let toB)): 36 | return nameA == nameB && fromA.isEqualTo(formB) && toA.isEqualTo(toB) 37 | default: return false 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpressionTests/ReformExpressionTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReformExpressionTests.swift 3 | // ReformExpressionTests 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ReformExpression 11 | 12 | final class ReformExpressionTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ReformSerializer/ReformSerializerTests/ReformSerializerTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReformSerializerTests.swift 3 | // ReformSerializerTests 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ReformSerializer 11 | 12 | final class ReformSerializerTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/StaticAngle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StaticAngle.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | import ReformMath 9 | 10 | struct StaticAngle : WriteableRuntimeRotationAngle { 11 | fileprivate let formId : FormIdentifier 12 | fileprivate let offset : Int 13 | 14 | init(formId: FormIdentifier, offset: Int) { 15 | self.formId = formId 16 | self.offset = offset 17 | } 18 | 19 | func getAngleFor(_ runtime: R) -> Angle? { 20 | guard let l = runtime.read(formId, offset: offset) else { 21 | return nil 22 | } 23 | 24 | return normalize360(Angle(radians: Double(bitPattern: l))) 25 | } 26 | 27 | func setAngleFor(_ runtime: R, angle: Angle) { 28 | runtime.write(formId, offset: offset, value: normalize360(angle).radians.bitPattern) 29 | } 30 | 31 | var isDegenerated : Bool { 32 | return false 33 | } 34 | } 35 | 36 | extension StaticAngle : Equatable { 37 | } 38 | 39 | func ==(lhs: StaticAngle, rhs: StaticAngle) -> Bool { 40 | return lhs.formId == rhs.formId && lhs.offset == rhs.offset 41 | } 42 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Describable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Labeled.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformExpression 10 | import ReformMath 11 | 12 | public protocol Labeled { 13 | func getDescription(_ stringifier: Stringifier) -> String 14 | } 15 | 16 | public protocol Stringifier { 17 | func labelFor(_ formId: FormIdentifier) -> String? 18 | func labelFor(_ formId: FormIdentifier, pointId: ExposedPointIdentifier) -> String? 19 | 20 | func labelFor(_ formId: FormIdentifier, anchorId: AnchorIdentifier) -> String? 21 | 22 | func stringFor(_ expression: ReformExpression.Expression) -> String? 23 | 24 | } 25 | 26 | extension Vec2d { 27 | var label : String { 28 | get { 29 | let fx = String(format: "%.2f", x) 30 | let fy = String(format: "%.2f", y) 31 | let z = -0.001...0.001 32 | 33 | if z.contains(x) == z.contains(y) { 34 | return "\(fx) horizontally, \(fy) vertically" 35 | } else if z.contains(y) { 36 | return "\(fx) horizontally" 37 | } else { 38 | return "\(fy) vertically" 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplicationUITests/ReformApplicationUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReformApplicationUITests.swift 3 | // ReformApplicationUITests 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class ReformApplicationUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | //XCUIApplication().launch() 22 | } 23 | 24 | override func tearDown() { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | super.tearDown() 27 | } 28 | 29 | func testExample() { 30 | // Use recording to get started writing UI tests. 31 | // Use XCTAssert and related functions to verify your tests produce the correct results. 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Operators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Operators.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | // Vector-Scalar 10 | 11 | 12 | 13 | // Angle-Angle 14 | 15 | 16 | // Angle-Scalar 17 | 18 | 19 | 20 | // Mat3x2-Mat3x2 21 | 22 | public func *(lhs: Mat3x2, rhs: Mat3x2) -> Mat3x2 { 23 | let col1 = Vec2d( 24 | x: lhs.col1.x * rhs.col1.x + lhs.col2.x * rhs.col1.y, 25 | y: lhs.col1.y * rhs.col1.x + lhs.col2.y * rhs.col1.y 26 | ) 27 | 28 | let col2 = Vec2d( 29 | x: lhs.col1.x * rhs.col2.x + lhs.col2.x * rhs.col2.y, 30 | y: lhs.col1.y * rhs.col2.x + lhs.col2.y * rhs.col2.y 31 | ) 32 | 33 | let col3 = Vec2d( 34 | x: lhs.col1.x * rhs.col3.x + lhs.col2.x * rhs.col3.y 35 | + lhs.col3.x, 36 | y: lhs.col1.y * rhs.col3.x + lhs.col2.y * rhs.col3.y 37 | + lhs.col3.y 38 | ) 39 | 40 | return Mat3x2(col1: col1, col2: col2, col3: col3) 41 | } 42 | 43 | 44 | // Mat3x2-Vec2d 45 | 46 | public func *(lhs: Mat3x2, rhs: Vec2d) -> Vec2d { 47 | return Vec2d( 48 | x: lhs.col1.x * rhs.x + lhs.col2.x * rhs.y + lhs.col3.x, 49 | y: lhs.col1.y * rhs.x + lhs.col2.y * rhs.y + lhs.col3.y 50 | ) 51 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/BasicLengthScaler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BasicLengthScaler.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct BasicLengthScaler : Scaler { 12 | private let length : WriteableRuntimeLength 13 | private let angle : RuntimeRotationAngle 14 | private let offset : Angle 15 | 16 | init(length: WriteableRuntimeLength, angle: RuntimeRotationAngle, offset: Angle = Angle(degree: 0)) { 17 | self.length = length 18 | self.angle = angle 19 | self.offset = offset 20 | } 21 | 22 | 23 | func scale(_ runtime : R, factor: Double, fix: Vec2d, axis: Vec2d) { 24 | guard let 25 | oldLength = length.getLengthFor(runtime), 26 | let angleValue = angle.getAngleFor(runtime) else { 27 | return 28 | } 29 | 30 | let p = rotate(Vec2d(x:oldLength, y:0), angle: angleValue + offset) 31 | 32 | let projected = project(p, onto: axis) 33 | 34 | let scaled = oldLength + projected.length * (factor - 1) * signum(oldLength) 35 | 36 | length.setLengthFor(runtime, length: scaled) 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/VectorScalarOperators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VectorScalarOperators.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 12.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public func +(lhs: Vec2d, rhs: Double) -> Vec2d { 11 | return Vec2d(x: lhs.x + rhs, y: lhs.y + rhs) 12 | } 13 | 14 | public func -(lhs: Vec2d, rhs: Double) -> Vec2d { 15 | return Vec2d(x: lhs.x - rhs, y: lhs.y - rhs) 16 | } 17 | 18 | 19 | public func +(lhs: Double, rhs: Vec2d) -> Vec2d { 20 | return Vec2d(x: lhs + rhs.x, y: lhs + rhs.y) 21 | } 22 | public func -(lhs: Double, rhs: Vec2d) -> Vec2d { 23 | return Vec2d(x: lhs - rhs.x, y: lhs - rhs.y) 24 | } 25 | 26 | public func *(lhs: Vec2d, rhs: Double) -> Vec2d { 27 | return Vec2d(x: lhs.x * rhs, y: lhs.y * rhs) 28 | } 29 | 30 | public func *(lhs: Double, rhs: Vec2d) -> Vec2d { 31 | return Vec2d(x: lhs * rhs.x, y: lhs * rhs.y) 32 | } 33 | 34 | public func *(lhs: Vec2d, rhs: Vec2d) -> Vec2d { 35 | return Vec2d(x: lhs.x * rhs.x, y: lhs.y * rhs.y) 36 | } 37 | 38 | public func /(lhs: Vec2d, rhs: Double) -> Vec2d { 39 | return Vec2d(x: lhs.x / rhs, y: lhs.y / rhs) 40 | } 41 | 42 | public func /(lhs: Double, rhs: Vec2d) -> Vec2d { 43 | return Vec2d(x: lhs / rhs.x, y: lhs / rhs.y) 44 | } 45 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/Stage.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Stage.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformCore 11 | import ReformGraphics 12 | 13 | final public class Stage { 14 | public internal(set) var entities : [Entity] = [] 15 | public internal(set) var size : Vec2d = Vec2d() 16 | 17 | public internal(set) var currentShapes : [IdentifiedShape] = [] 18 | public internal(set) var finalShapes : [IdentifiedShape] = [] 19 | 20 | public internal(set) var intersections : [IntersectionSnapPoint] = [] 21 | 22 | public internal(set) var error : RuntimeError? = nil 23 | 24 | public init() {} 25 | } 26 | 27 | 28 | public struct IdentifiedShape { 29 | public let id : FormIdentifier 30 | public let shape : Shape 31 | } 32 | 33 | extension Stage { 34 | private static let allSides : [CropSide] = [ 35 | .top, .right, .bottom, .left, 36 | .topLeft, .topRight, .bottomLeft, .bottomRight 37 | ] 38 | 39 | public var cropPoints : [CropPoint] { 40 | return Stage.allSides.map { side in 41 | return CropPoint(position: size * side.vector / 2 + size/2, offset: side) 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "size" : "256x256", 40 | "idiom" : "mac", 41 | "filename" : "reform-icon-3.png", 42 | "scale" : "2x" 43 | }, 44 | { 45 | "size" : "512x512", 46 | "idiom" : "mac", 47 | "filename" : "reform-icon-2.png", 48 | "scale" : "1x" 49 | }, 50 | { 51 | "idiom" : "mac", 52 | "size" : "512x512", 53 | "scale" : "2x" 54 | } 55 | ], 56 | "info" : { 57 | "version" : 1, 58 | "author" : "xcode" 59 | } 60 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/RuntimeError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RuntimeError.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public enum RuntimeError { 10 | case invalidDestination 11 | case unknownForm 12 | case unknownAnchor 13 | case invalidDistance 14 | case invalidFixPoint 15 | case invalidAngle 16 | case invalidFactor 17 | case invalidExpression 18 | case invalidAxis 19 | } 20 | 21 | extension RuntimeError : CustomStringConvertible { 22 | public var description : String { 23 | switch self { 24 | case .invalidDestination: 25 | return "Invalid Destination" 26 | case .unknownForm: 27 | return "Unknown Form" 28 | case .unknownAnchor: 29 | return "Unknown Anchor" 30 | case .invalidDistance: 31 | return "Invalid Distance" 32 | case .invalidFixPoint: 33 | return "Invalid Fix Point" 34 | case .invalidAngle: 35 | return "Invalid Angle" 36 | case .invalidFactor: 37 | return "Invalid Scale Factor" 38 | case .invalidExpression: 39 | return "Invalid Expression" 40 | case .invalidAxis: 41 | return "Invalid Axis" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/StaticPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StaticPoint.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct StaticPoint : WriteableRuntimePoint { 12 | fileprivate let formId : FormIdentifier 13 | fileprivate let offset : Int 14 | 15 | init(formId: FormIdentifier, offset: Int) { 16 | self.formId = formId 17 | self.offset = offset 18 | } 19 | 20 | func getPositionFor(_ runtime: R) -> Vec2d? { 21 | guard let 22 | x = runtime.read(formId, offset: offset), 23 | let y = runtime.read(formId, offset: offset+1) else { 24 | return nil 25 | } 26 | return Vec2d(x: Double(bitPattern: x), y:Double(bitPattern: y)) 27 | } 28 | 29 | func setPositionFor(_ runtime: R, position: Vec2d) { 30 | runtime.write(formId, offset: offset, value: position.x.bitPattern) 31 | 32 | runtime.write(formId, offset: offset+1, value: position.y.bitPattern) 33 | } 34 | } 35 | 36 | 37 | extension StaticPoint : Equatable { 38 | 39 | } 40 | 41 | 42 | func ==(lhs: StaticPoint, rhs: StaticPoint) -> Bool { 43 | return lhs.formId == rhs.formId && lhs.offset == rhs.offset 44 | } 45 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Vec2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Vec2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public struct Vec2d :Equatable { 11 | public static let Zero = Vec2d(x:0, y:0) 12 | public static let XAxis = Vec2d(x:1, y:0) 13 | public static let YAxis = Vec2d(x:0, y:1) 14 | 15 | public let x : Double 16 | public let y : Double 17 | 18 | public init() { 19 | self.x = 0 20 | self.y = 0 21 | } 22 | 23 | public init(x : Double, y : Double) { 24 | self.x = x 25 | self.y = y 26 | } 27 | 28 | 29 | public init(radius : Double, angle : Angle) { 30 | self = rotate(Vec2d.XAxis * radius, angle: angle) 31 | } 32 | } 33 | 34 | public func ==(lhs: Vec2d, rhs: Vec2d) -> Bool { 35 | return lhs.x == rhs.x && lhs.y == rhs.y 36 | } 37 | 38 | extension Vec2d { 39 | public var length : Double { 40 | return sqrt(x*x + y*y) 41 | } 42 | } 43 | 44 | extension Vec2d { 45 | public var angle : Angle { 46 | return ReformMath.angle(self) 47 | } 48 | } 49 | 50 | extension Vec2d { 51 | public var length2 : Double { 52 | return x*x + y*y 53 | } 54 | 55 | public var length² : Double { 56 | return length2 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /ReformCore/ReformCore/Form.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Form.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformGraphics 11 | 12 | public protocol Rotatable { 13 | var rotator : Rotator { get } 14 | } 15 | 16 | public protocol Scalable { 17 | var scaler : Scaler { get } 18 | } 19 | 20 | public protocol Translatable { 21 | var translator : Translator { get } 22 | } 23 | 24 | public protocol Morphable { 25 | func getAnchors() -> [AnchorIdentifier:Anchor] 26 | } 27 | 28 | public protocol Drawable { 29 | func getPathFor(_ runtime: R) -> Path? 30 | 31 | func getShapeFor(_ runtime: R) -> Shape? 32 | 33 | var drawingMode : DrawingMode { get set } 34 | } 35 | 36 | public typealias LabeledPoint = RuntimePoint & Labeled 37 | 38 | public protocol Creatable { 39 | init(id: FormIdentifier, name: String) 40 | 41 | 42 | func initWithRuntime(_ runtime: R, min: Vec2d, max: Vec2d) 43 | } 44 | 45 | public protocol Form { 46 | static var stackSize : Int { get } 47 | 48 | var identifier : FormIdentifier { get } 49 | 50 | func getPoints() -> [ExposedPointIdentifier:LabeledPoint] 51 | 52 | var name : String { get set } 53 | 54 | var outline : Outline { get } 55 | } 56 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/FormIteratorDetailController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FormIteratorDetailController.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 06.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import Cocoa 11 | import ReformCore 12 | import ReformExpression 13 | 14 | class FormIteratorInstructionDetailController : NSViewController, InstructionDetailController { 15 | 16 | @IBOutlet var errorLabel : NSTextField? 17 | 18 | var stringifier : Stringifier? 19 | var parser : ((String) -> Result)? 20 | var intend : (() -> ())? 21 | 22 | var error : String? { 23 | didSet { 24 | updateError() 25 | } 26 | } 27 | 28 | override var representedObject : Any? { 29 | didSet { 30 | updateLabel() 31 | } 32 | } 33 | 34 | override func viewDidLoad() { 35 | updateLabel() 36 | updateError() 37 | } 38 | 39 | func updateError() { 40 | if let error = error { 41 | errorLabel?.stringValue = error 42 | if let errorLabel = errorLabel { 43 | self.view.addSubview(errorLabel) 44 | } 45 | } else { 46 | errorLabel?.removeFromSuperview() 47 | } 48 | } 49 | 50 | func updateLabel() { 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/MorphInstructionDetailController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MorphInstructionDetailController.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 06.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import Cocoa 11 | import ReformCore 12 | import ReformExpression 13 | 14 | class MorphInstructionDetailController : NSViewController, InstructionDetailController { 15 | 16 | @IBOutlet var errorLabel : NSTextField? 17 | 18 | var stringifier : Stringifier? 19 | var parser : ((String) -> Result)? 20 | var intend : (() -> ())? 21 | 22 | var error : String? { 23 | didSet { 24 | updateError() 25 | } 26 | } 27 | 28 | override var representedObject : Any? { 29 | didSet { 30 | updateLabel() 31 | } 32 | } 33 | 34 | override func viewDidLoad() { 35 | updateLabel() 36 | updateError() 37 | } 38 | 39 | func updateError() { 40 | if let error = error { 41 | errorLabel?.stringValue = error 42 | if let errorLabel = errorLabel { 43 | self.view.addSubview(errorLabel) 44 | } 45 | } else { 46 | errorLabel?.removeFromSuperview() 47 | } 48 | } 49 | 50 | func updateLabel() { 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/EntityFinder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EntityFinder.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 19.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import ReformMath 11 | import ReformCore 12 | import ReformStage 13 | import ReformExpression 14 | 15 | 16 | struct EntityQuery { 17 | let filter: FormFilter 18 | let location: LocationFilter 19 | } 20 | 21 | struct EntityFinder { 22 | let stage : Stage 23 | 24 | func getEntity(_ id: FormIdentifier) -> Entity? { 25 | for entity in stage.entities { 26 | if entity.id.runtimeId == id { 27 | return entity 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func getEntities(_ query: EntityQuery) -> [Entity] { 35 | var result = [Entity]() 36 | 37 | for entity in stage.entities { 38 | if case .except(entity.id) = query.filter { 39 | continue 40 | } 41 | if case .only(let id) = query.filter, id != entity.id { 42 | continue 43 | } 44 | 45 | 46 | guard query.location.matches(entity.hitArea) else { 47 | continue 48 | } 49 | 50 | result.append(entity) 51 | } 52 | 53 | return result 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/CreateFormInstructionDetailController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CreateFormInstructionDetailController.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 06.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import ReformCore 11 | import ReformExpression 12 | 13 | class CreateFormInstructionDetailController : NSViewController, InstructionDetailController { 14 | 15 | @IBOutlet var errorLabel : NSTextField? 16 | 17 | var stringifier : Stringifier? 18 | var parser : ((String) -> Result)? 19 | var intend : (() -> ())? 20 | 21 | var error : String? { 22 | didSet { 23 | updateError() 24 | } 25 | } 26 | 27 | override var representedObject : Any? { 28 | didSet { 29 | updateLabel() 30 | } 31 | } 32 | 33 | override func viewDidLoad() { 34 | updateLabel() 35 | updateError() 36 | } 37 | 38 | func updateError() { 39 | if let error = error { 40 | errorLabel?.stringValue = error 41 | if let errorLabel = errorLabel { 42 | self.view.addSubview(errorLabel) 43 | } 44 | } else { 45 | errorLabel?.removeFromSuperview() 46 | } 47 | } 48 | 49 | func updateLabel() { 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/RotateInstructionDetailController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RotateInstructionDetailController.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 06.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import Cocoa 11 | import ReformCore 12 | import ReformExpression 13 | 14 | class RotateInstructionDetailController : NSViewController, InstructionDetailController { 15 | 16 | @IBOutlet var errorLabel : NSTextField? 17 | 18 | var stringifier : Stringifier? 19 | var parser : ((String) -> Result)? 20 | var intend : (() -> ())? 21 | 22 | var error : String? { 23 | didSet { 24 | updateError() 25 | } 26 | } 27 | 28 | override var representedObject : Any? { 29 | didSet { 30 | updateLabel() 31 | } 32 | } 33 | 34 | override func viewDidLoad() { 35 | updateLabel() 36 | updateError() 37 | } 38 | 39 | func updateError() { 40 | if let error = error { 41 | errorLabel?.stringValue = error 42 | if let errorLabel = errorLabel { 43 | self.view.addSubview(errorLabel) 44 | } 45 | } else { 46 | errorLabel?.removeFromSuperview() 47 | } 48 | } 49 | 50 | func updateLabel() { 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/ScaleInstructionDetailController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScaleInstructionDetailController.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 06.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import Cocoa 11 | import ReformCore 12 | import ReformExpression 13 | 14 | class ScaleInstructionDetailController : NSViewController, InstructionDetailController { 15 | 16 | @IBOutlet var errorLabel : NSTextField? 17 | 18 | var stringifier : Stringifier? 19 | var parser : ((String) -> Result)? 20 | var intend : (() -> ())? 21 | 22 | var error : String? { 23 | didSet { 24 | updateError() 25 | } 26 | } 27 | 28 | 29 | override var representedObject : Any? { 30 | didSet { 31 | updateLabel() 32 | } 33 | } 34 | 35 | override func viewDidLoad() { 36 | updateLabel() 37 | updateError() 38 | } 39 | 40 | func updateError() { 41 | if let error = error { 42 | errorLabel?.stringValue = error 43 | if let errorLabel = errorLabel { 44 | self.view.addSubview(errorLabel) 45 | } 46 | } else { 47 | errorLabel?.removeFromSuperview() 48 | } 49 | } 50 | 51 | func updateLabel() { 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Reform.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | 24 | 25 | 27 | 28 | 30 | 31 | 33 | 34 | 36 | 37 | 39 | 40 | 42 | 43 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Renderer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Renderer.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 18.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ReformMath 11 | 12 | protocol Renderer { 13 | func renderInContext(_ context: CGContext) 14 | } 15 | 16 | func drawDotAt(_ context: CGContext, position: Vec2d, size: Double) { 17 | let rect = CGRect(x:position.x-size/2, y:position.y-size/2, width: size, height: size) 18 | context.addEllipse(in: rect) 19 | } 20 | 21 | 22 | func drawSegmentPath(_ context: CGContext, path: SegmentPath) { 23 | for segment in path { 24 | switch segment { 25 | case .line(let line): 26 | context.move(to: CGPoint(x: CGFloat(line.from.x), y: CGFloat(line.from.y))) 27 | context.addLine(to: CGPoint(x: CGFloat(line.to.x), y: CGFloat(line.to.y))) 28 | case .arc(let arc): 29 | let startPoint = arc.center + Vec2d(radius: arc.radius, angle: arc.range.start) 30 | context.move(to: CGPoint(x: CGFloat(startPoint.x), y: CGFloat(startPoint.y))) 31 | context.addArc(center: CGPoint(x: CGFloat(arc.center.x), y: CGFloat(arc.center.y)), radius: CGFloat(arc.radius), startAngle: CGFloat(arc.range.start.radians), endAngle: CGFloat(arc.range.end.radians), clockwise: false) 32 | } 33 | 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Glomp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Glomp.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | import ReformExpression 11 | 12 | public struct GlompPoint : RuntimePoint, Labeled, Equatable { 13 | public let lerp : ReformExpression.Expression 14 | public let formId : FormIdentifier 15 | 16 | public init(formId: FormIdentifier, lerp: ReformExpression.Expression) { 17 | self.formId = formId 18 | self.lerp = lerp 19 | } 20 | 21 | public func getDescription(_ stringifier: Stringifier) -> String { 22 | let formName = stringifier.labelFor(formId) ?? "???" 23 | let value = stringifier.stringFor(lerp) ?? "??" 24 | 25 | return "\(value) along \(formName)" 26 | } 27 | 28 | public func getPositionFor(_ runtime: R) -> Vec2d? { 29 | guard let formOutline = runtime.get(formId)?.outline else { 30 | return nil 31 | } 32 | 33 | guard case .success(.doubleValue(let l)) = lerp.eval(runtime.getDataSet()) else { 34 | return nil 35 | } 36 | 37 | return formOutline.getPositionFor(runtime, t: l) 38 | } 39 | } 40 | 41 | 42 | public func ==(lhs: GlompPoint, rhs: GlompPoint) -> Bool { 43 | return lhs.formId == rhs.formId && lhs.lerp == rhs.lerp 44 | } 45 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Containment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Containment.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 22.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public func inside(_ point: Vec2d, circle: Circle2d, epsilon: Double = 0) -> Bool 10 | { 11 | return distance(point: point, point: circle.center) < circle.radius + epsilon 12 | } 13 | 14 | public func inside(_ point: Vec2d, arc: Arc2d, epsilon: Double = 0) -> Bool 15 | { 16 | return distance(point: point, point: arc.center) < arc.radius + epsilon && inside(angle(point-arc.center), range: arc.range) 17 | } 18 | 19 | public func inside(_ point : Vec2d, triangle: Triangle2d, epsilon : Double = 0) -> Bool 20 | { 21 | let b1 = sign(point, a:triangle.a, b:triangle.b) < epsilon 22 | let b2 = sign(point, a:triangle.b, b:triangle.c) < epsilon 23 | let b3 = sign(point, a:triangle.c, b:triangle.a) < epsilon 24 | 25 | return b1 == b2 && b2 == b3 26 | } 27 | 28 | 29 | public func inside(_ point: Vec2d, aabb: AABB2d, epsilon: Double = 0) -> Bool { 30 | return aabb.outCode(point, epsilon: epsilon) == .Inside 31 | } 32 | 33 | 34 | public func inside(_ angle: Angle, range: AngleRange) -> Bool { 35 | let a = normalize360(angle) 36 | 37 | if range.start < range.end { 38 | return range.start <= a && a <= range.end 39 | } else { 40 | return range.start <= a || a <= range.end 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/TopologicalSort.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TopologicalSort.swift 3 | // ExpressionEngine 4 | // 5 | // Created by Laszlo Korte on 10.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | final class Node : Hashable where I : Hashable { 10 | let id : I 11 | let data : T 12 | var outgoing = Set>() 13 | var incomingCount = 0 14 | 15 | init(id: I, data: T) { 16 | self.data = data 17 | self.id = id 18 | } 19 | 20 | var hashValue: Int { return id.hashValue } 21 | } 22 | 23 | func ==(left: Node, right: Node) -> Bool { 24 | return left.id == right.id 25 | } 26 | 27 | func topologicallySorted(_ nodes: [Node]) -> [Node] { 28 | 29 | var result = [Node]() 30 | var rootNodes = Set>() 31 | 32 | 33 | for node in nodes { 34 | for dep in node.outgoing { 35 | dep.incomingCount += 1 36 | } 37 | } 38 | 39 | rootNodes.formUnion(nodes.filter({ $0.incomingCount == 0 })) 40 | 41 | while let n = rootNodes.first { 42 | rootNodes.remove(n) 43 | result.append(n) 44 | 45 | for m in n.outgoing { 46 | n.outgoing.remove(m) 47 | m.incomingCount -= 1 48 | if m.incomingCount == 0 { 49 | rootNodes.insert(m) 50 | } 51 | } 52 | } 53 | 54 | return result 55 | } 56 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Angle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Angle.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Angle { 10 | public static let PI = Angle(radians: Double.pi) 11 | 12 | public let radians : Double 13 | 14 | public var degree : Double { get { return radians * 360 / (Double.pi * 2) } } 15 | public var percent : Double { get { return radians * 100 / (Double.pi * 2) } } 16 | 17 | public init(percent: Double) { 18 | self.init(radians: Double.pi * 2 * percent / 100.0) 19 | } 20 | 21 | public init(radians: Double) { 22 | self.radians = radians 23 | } 24 | 25 | public init(degree: Double) { 26 | self.init(radians: Double.pi * 2 * degree / 360.0) 27 | } 28 | 29 | public init() { 30 | self.init(radians: 0) 31 | } 32 | } 33 | 34 | extension Angle : Comparable, Equatable {} 35 | 36 | public func <(lhs: Angle, rhs: Angle) -> Bool { 37 | return (lhs.radians < rhs.radians) 38 | } 39 | public func ==(lhs: Angle, rhs: Angle) -> Bool { 40 | return lhs.radians == rhs.radians 41 | } 42 | 43 | extension Angle { 44 | public var cos : Double { 45 | return Darwin.cos(radians) 46 | } 47 | public var sin : Double { 48 | return Darwin.sin(radians) 49 | } 50 | public var tan : Double { 51 | return Darwin.tan(radians) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/GrabUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GrabUI.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 18.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ReformTools 11 | import ReformStage 12 | 13 | struct GrabUIRenderer : Renderer { 14 | let grabUI : GrabUI 15 | let camera: Camera 16 | 17 | func renderInContext(_ context: CGContext) { 18 | let inverse = CGFloat(1 / camera.zoom) 19 | 20 | context.setFillColor(red: 0.2, green: 0.7, blue: 1, alpha: 1) 21 | context.setStrokeColor(red: 0.2, green: 0.6, blue: 0.9, alpha: 1) 22 | context.setLineWidth(1 * inverse) 23 | let dotSize : Double = 7 / camera.zoom 24 | 25 | 26 | switch grabUI.state { 27 | case .hide: 28 | return 29 | case .show(let points): 30 | for p in points { 31 | drawDotAt(context, position: p.position, size: dotSize) 32 | } 33 | context.drawPath(using: .fillStroke) 34 | case .active(let active, let points): 35 | for p in points { 36 | drawDotAt(context, position: p.position, size: dotSize) 37 | } 38 | context.drawPath(using: .fillStroke) 39 | 40 | drawDotAt(context, position: active.position, size: dotSize*1.5) 41 | 42 | context.drawPath(using: .fillStroke) 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/AffineHandleFinder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AffineHandleFinder.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 21.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import ReformMath 11 | import ReformCore 12 | import ReformStage 13 | import ReformExpression 14 | 15 | 16 | struct AffineHandleFinder { 17 | let stage : Stage 18 | 19 | func getUpdatedHandle(_ oldHandle: AffineHandle) -> AffineHandle? { 20 | for entity in stage.entities 21 | where entity.id == oldHandle.formId { 22 | for handle in entity.affineHandles 23 | where handle == oldHandle { 24 | return handle 25 | } 26 | } 27 | 28 | return nil 29 | } 30 | 31 | 32 | func getHandles(_ query: HandleQuery) -> [AffineHandle] { 33 | var result = [AffineHandle]() 34 | 35 | if case FormFilter.none = query.filter { 36 | return result 37 | } 38 | 39 | 40 | for entity in stage.entities { 41 | if query.filter.excludes(entity.id) { 42 | continue 43 | } 44 | 45 | for handle in entity.affineHandles { 46 | guard query.location.matches(handle.position) else { 47 | continue 48 | } 49 | result.append(handle) 50 | } 51 | 52 | } 53 | 54 | 55 | return result 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Anchor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Anchor.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public protocol Anchor { 12 | func getPositionFor(_ runtime: R) -> Vec2d? 13 | 14 | func translate(_ runtime: R, delta: Vec2d) 15 | 16 | var name : String { get } 17 | 18 | func isEqualTo(_ other: Anchor) -> Bool 19 | } 20 | 21 | extension Anchor where Self : Equatable { 22 | public func isEqualTo(_ other: Anchor) -> Bool { 23 | guard let other = other as? Self else { 24 | return false 25 | } 26 | 27 | return self == other 28 | } 29 | } 30 | 31 | public struct AnchorIdentifier : Hashable { 32 | public let value : Int 33 | 34 | public init(_ value : Int) { 35 | self.value = value 36 | } 37 | 38 | public var hashValue : Int { return value } 39 | } 40 | 41 | public func ==(lhs: AnchorIdentifier, rhs: AnchorIdentifier) -> Bool { 42 | return lhs.value == rhs.value 43 | } 44 | 45 | extension AnchorIdentifier : ExpressibleByIntegerLiteral, RawRepresentable { 46 | 47 | public init?(rawValue: Int) { 48 | self.value = rawValue 49 | } 50 | 51 | public var rawValue: Int { 52 | return value 53 | } 54 | 55 | public init(integerLiteral value: Int8) { 56 | self.value = Int(value) 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/FixSizeDestination.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FixSizeDestination.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct FixSizeDestination : RuntimeInitialDestination, Labeled { 12 | public typealias PointType = RuntimePoint & Labeled 13 | 14 | public let from: PointType 15 | public let delta: Vec2d 16 | public let alignment: RuntimeAlignment 17 | 18 | public init(from: PointType, delta: Vec2d, alignment: RuntimeAlignment = .leading) { 19 | self.from = from 20 | self.delta = delta 21 | self.alignment = alignment 22 | } 23 | 24 | public func getMinMaxFor(_ runtime: R) -> (Vec2d,Vec2d)? { 25 | guard let min = from.getPositionFor(runtime) else { 26 | return nil 27 | } 28 | 29 | return alignment.getMinMax(from: min, to: min + delta) 30 | } 31 | 32 | public func getDescription(_ stringifier: Stringifier) -> String { 33 | let fromLabel = from.getDescription(stringifier) 34 | 35 | switch alignment { 36 | case .centered: 37 | return "Around \(fromLabel) \(delta.label)" 38 | case .leading: 39 | return "From \(fromLabel) \(delta.label)" 40 | } 41 | } 42 | 43 | public var isDegenerated : Bool { 44 | return delta.x == 0 && delta.y == 0 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/AffineHandleUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AffineHandleUI.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 25.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import Foundation 11 | import ReformTools 12 | import ReformStage 13 | 14 | struct AffineHandleUIRenderer : Renderer { 15 | let affineHandleUI : AffineHandleUI 16 | let camera: Camera 17 | 18 | func renderInContext(_ context: CGContext) { 19 | let inverse = CGFloat(1 / camera.zoom) 20 | 21 | context.setFillColor(red: 0.1, green: 0.9, blue: 0.6, alpha: 1) 22 | context.setStrokeColor(red: 0, green: 0.6, blue: 0.4, alpha: 1) 23 | context.setLineWidth(1 * inverse) 24 | let dotSize : Double = 8 / camera.zoom 25 | 26 | 27 | switch affineHandleUI.state { 28 | case .hide: 29 | return 30 | case .show(let points): 31 | for p in points { 32 | drawDotAt(context, position: p.position, size: dotSize) 33 | } 34 | 35 | context.drawPath(using: .fillStroke) 36 | case .active(let active, let points): 37 | for p in points { 38 | drawDotAt(context, position: p.position, size: dotSize) 39 | } 40 | context.drawPath(using: .fillStroke) 41 | 42 | 43 | drawDotAt(context, position: active.position, size: dotSize*1.5) 44 | 45 | context.drawPath(using: .fillStroke) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/HandleUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HandleUI.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 18.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ReformTools 11 | import ReformStage 12 | 13 | struct HandleUIRenderer : Renderer { 14 | let handleUI : HandleUI 15 | let camera: Camera 16 | 17 | func renderInContext(_ context: CGContext) { 18 | let inverse = CGFloat(1 / camera.zoom) 19 | 20 | context.setFillColor(red: 0.1, green: 0.9, blue: 0.6, alpha: 1) 21 | context.setStrokeColor(red: 0, green: 0.6, blue: 0.4, alpha: 1) 22 | context.setLineWidth(1 * inverse) 23 | let dotSize : Double = 8 / camera.zoom 24 | 25 | 26 | switch handleUI.state { 27 | case .hide: 28 | return 29 | case .show(let points): 30 | for p in points { 31 | drawDotAt(context, position: p.position, size: dotSize) 32 | } 33 | 34 | context.drawPath(using: .fillStroke) 35 | case .active(let active, let points): 36 | for p in points { 37 | drawDotAt(context, position: p.position, size: dotSize) 38 | } 39 | context.drawPath(using: .fillStroke) 40 | 41 | 42 | drawDotAt(context, position: active.position, size: dotSize*1.5) 43 | 44 | context.drawPath(using: .fillStroke) 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/IfConditionInstruction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IfConditionInstruction.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformExpression 10 | 11 | public struct IfConditionInstruction : GroupInstruction { 12 | public let expression : ReformExpression.Expression 13 | 14 | public var target : FormIdentifier? { return nil } 15 | 16 | public init(expression : ReformExpression.Expression) { 17 | self.expression = expression 18 | } 19 | 20 | public func evaluate(_ runtime: T, withChildren children: [InstructionNode]) where T.Ev==InstructionNode { 21 | guard case .success(.boolValue(let bool)) = expression.eval(runtime.getDataSet()) else { 22 | runtime.reportError(.invalidExpression) 23 | return 24 | } 25 | 26 | if bool { 27 | runtime.scoped() { runtime in 28 | for c in children where !runtime.shouldStop { 29 | c.evaluate(runtime) 30 | } 31 | } 32 | } 33 | } 34 | 35 | 36 | public func getDescription(_ stringifier: Stringifier) -> String { let expressionString = stringifier.stringFor(expression) ?? "???" 37 | 38 | return "if \(expressionString):" 39 | } 40 | 41 | public func analyze(_ analyzer: T) { 42 | } 43 | 44 | public var isDegenerated : Bool { 45 | return false 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ForLoopInstruction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ForLoopInstruction.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 14.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformExpression 10 | 11 | public struct ForLoopInstruction : GroupInstruction { 12 | public let expression : ReformExpression.Expression 13 | 14 | public var target : FormIdentifier? { return nil } 15 | 16 | public init(expression : ReformExpression.Expression) { 17 | self.expression = expression 18 | } 19 | 20 | public func evaluate(_ runtime: T, withChildren children: [InstructionNode]) where T.Ev==InstructionNode { 21 | guard case .success(.intValue(let count)) = expression.eval(runtime.getDataSet()) else { 22 | runtime.reportError(.invalidExpression) 23 | return 24 | } 25 | 26 | for _ in 0.. String { 36 | let expressionString = stringifier.stringFor(expression) ?? "???" 37 | 38 | return "Repeat \(expressionString) times:" 39 | } 40 | 41 | public func analyze(_ analyzer: T) { 42 | } 43 | 44 | public var isDegenerated : Bool { 45 | return false 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ReformStage/ReformStage/CropPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CropPoint.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct CropPoint { 12 | public let position : Vec2d 13 | public let offset : CropSide 14 | 15 | public init(position: Vec2d, offset: CropSide) { 16 | self.position = position 17 | self.offset = offset 18 | } 19 | } 20 | 21 | extension CropPoint { 22 | public var isCorner : Bool { 23 | return offset.vector.x != 0 && offset.vector.y != 0 24 | } 25 | } 26 | 27 | public enum CropSide : Hashable { 28 | case top 29 | case left 30 | case right 31 | case bottom 32 | case topLeft 33 | case topRight 34 | case bottomLeft 35 | case bottomRight 36 | 37 | public var vector : Vec2d { 38 | switch self { 39 | case .top: return Vec2d(x: 0,y: 1) 40 | case .left: return Vec2d(x: -1,y: 0) 41 | case .right: return Vec2d(x: 1,y: 0) 42 | case .bottom: return Vec2d(x: 0,y: -1) 43 | case .topLeft: return Vec2d(x: -1,y: 1) 44 | case .topRight: return Vec2d(x: 1,y: 1) 45 | case .bottomLeft: return Vec2d(x: -1,y: -1) 46 | case .bottomRight: return Vec2d(x: 1,y: -1) 47 | } 48 | } 49 | } 50 | 51 | extension CropPoint : Hashable { 52 | public var hashValue : Int { return offset.hashValue } 53 | } 54 | 55 | public func ==(lhs: CropPoint, rhs: CropPoint) -> Bool { 56 | return lhs.offset == rhs.offset 57 | } 58 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Arc2d.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Arc2d.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 21.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Arc2d : Equatable { 10 | public let center : Vec2d 11 | public let radius: Double 12 | public let range: AngleRange 13 | 14 | public init(center: Vec2d, radius:Double, range: AngleRange) { 15 | self.center = center 16 | self.radius = radius 17 | self.range = range 18 | } 19 | } 20 | 21 | public func ==(lhs: Arc2d, rhs: Arc2d) -> Bool { 22 | return lhs.center == rhs.center && lhs.radius == rhs.radius && lhs.range == rhs.range 23 | } 24 | 25 | extension Arc2d { 26 | public var length : Double { 27 | return Double.TAU * radius * range.delta.percent/100 28 | } 29 | } 30 | 31 | extension Arc2d { 32 | public var circle : Circle2d { 33 | return Circle2d(center: center, radius: radius) 34 | } 35 | 36 | public var quadrants : [Arc2d] { 37 | return [ 38 | AngleRange(start: Angle(percent: 0), end: Angle(percent: 25)), 39 | AngleRange(start: Angle(percent: 25), end: Angle(percent: 50)), 40 | AngleRange(start: Angle(percent: 50), end: Angle(percent: 75)), 41 | AngleRange(start: Angle(percent: 75), end: Angle(percent: 100)), 42 | ].lazy.flatMap { (r:AngleRange) in 43 | intersection(range: self.range, range: self.range) 44 | }.flatMap { (r:AngleRange) in 45 | Arc2d(center: center, radius: radius, range: r) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/ExpressionLexer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExpressionLexer.swift 3 | // Reform 4 | // 5 | // Created by Laszlo Korte on 10.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformExpression 10 | 11 | var lexerGenerator = LexerGenerator() { (conf : inout LexerGenerator) in 12 | 13 | conf.ignore("\\s+") 14 | conf.ignore("\\u00A0+") 15 | 16 | conf.add(.parenthesisLeft, pattern: "\\(") 17 | conf.add(.parenthesisRight, pattern: "\\)") 18 | 19 | 20 | conf.add(.operator, pattern: "\\-") 21 | conf.add(.operator, pattern: "\\+") 22 | conf.add(.operator, pattern: "\\/") 23 | conf.add(.operator, pattern: "\\*") 24 | conf.add(.operator, pattern: "\\%") 25 | conf.add(.operator, pattern: "\\^") 26 | 27 | 28 | conf.add(.operator, pattern: "~") 29 | conf.add(.operator, pattern: "\\&\\&") 30 | conf.add(.operator, pattern: "\\|\\|") 31 | 32 | 33 | conf.add(.operator, pattern: "<") 34 | conf.add(.operator, pattern: "<=") 35 | conf.add(.operator, pattern: ">") 36 | conf.add(.operator, pattern: ">=") 37 | 38 | conf.add(.operator, pattern: "==") 39 | 40 | conf.add(.argumentSeparator, pattern: ",") 41 | conf.add(.literalValue, pattern: "(0|([1-9][0-9]*))(\\.[0-9]*)?") 42 | conf.add(.literalValue, pattern: "#[0-9a-fA-F]{6,8}") 43 | conf.add(.literalValue, pattern: "\"[^\"]+\"") 44 | conf.add(.literalValue, pattern: "(true|false)") 45 | conf.add(.identifier, pattern: "[a-zA-Z_][_a-zA-Z0-9]*") 46 | conf.add(.literalValue, pattern: "\"[^\"]*\"") 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/ProcedureCellView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProcedureCellView.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 26.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ReformCore 11 | 12 | protocol ProcedureCellView { 13 | func configure(_ row: InstructionOutlineRow, procedureViewModel: ProcedureViewModel) 14 | } 15 | 16 | 17 | final class ProcedureSingleCellView : NSTableCellView, ProcedureCellView { 18 | @IBOutlet var indentConstraint : NSLayoutConstraint? 19 | 20 | func configure(_ row: InstructionOutlineRow, procedureViewModel: ProcedureViewModel) { 21 | indentConstraint?.constant = CGFloat(15 * row.depth) 22 | textField?.stringValue = row.label 23 | imageView?.image = procedureViewModel.snapshotCollector.imageFor(InstructionNodeKey(row.node)) 24 | 25 | 26 | let error = procedureViewModel.snapshotCollector.errors.keys.contains(InstructionNodeKey(row.node)) 27 | textField?.textColor = error ? NSColor.red : nil 28 | 29 | } 30 | } 31 | 32 | final class ProcedureGroupCellView : NSTableCellView, ProcedureCellView { 33 | @IBOutlet var indentConstraint : NSLayoutConstraint? 34 | 35 | 36 | func configure(_ row: InstructionOutlineRow, procedureViewModel: ProcedureViewModel) { 37 | indentConstraint?.constant = CGFloat(15 * row.depth) 38 | textField?.stringValue = row.node.isEmpty ? "" : row.label 39 | 40 | let error = procedureViewModel.snapshotCollector.errors.keys.contains(InstructionNodeKey(row.node)) 41 | textField?.textColor = error ? NSColor.red : nil 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/Runtime.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Runtime.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformExpression 10 | 11 | public protocol RuntimeListener { 12 | func runtimeBeginEvaluation(_ runtime: R, withSize: (Double, Double)) 13 | func runtimeFinishEvaluation(_ runtime: R) 14 | func runtime(_ runtime: R, didEval: Evaluatable) 15 | func runtime(_ runtime: R, exitScopeWithForms: [FormIdentifier]) 16 | func runtime(_ runtime: R, triggeredError: RuntimeError, on: Evaluatable) 17 | } 18 | 19 | public protocol Runtime { 20 | static var maxDepth : Int { get } 21 | associatedtype Ev : Evaluatable 22 | 23 | var listeners : [RuntimeListener] { get set } 24 | 25 | func subCall(_ id: PictureIdentifier, width: Double, height: Double, makeFit: Bool, dataSet: DataSet, callback: (_ runtime: Self, _ picture: Picture) -> ()) 26 | 27 | func run(width: Double, height: Double, block: (Self) -> ()) 28 | 29 | func eval(_ instruction : Ev, block: (Self) -> ()) 30 | 31 | func scoped( _ block: (Self) -> ()) 32 | 33 | func declare(_ form : Form) 34 | 35 | func get(_ id: FormIdentifier) -> Form? 36 | 37 | func read(_ id: FormIdentifier, offset: Int) -> UInt64? 38 | 39 | func write(_ id: FormIdentifier, offset: Int, value: UInt64) 40 | 41 | func getForms() ->[FormIdentifier] 42 | 43 | func reportError(_ error : RuntimeError) 44 | 45 | var shouldStop : Bool { get } 46 | 47 | func getDataSet() -> DataSet 48 | 49 | } 50 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/IntersectionPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IntersectionPoint.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct RuntimeIntersectionPoint : RuntimePoint, Labeled { 12 | public let index : Int 13 | public let formA : FormIdentifier 14 | public let formB : FormIdentifier 15 | 16 | public init(formA: FormIdentifier, formB: FormIdentifier, index: Int) { 17 | self.index = index 18 | self.formA = formA 19 | self.formB = formB 20 | } 21 | 22 | public func getDescription(_ stringifier: Stringifier) -> String { 23 | let formAName = stringifier.labelFor(formA) ?? "???" 24 | let formBName = stringifier.labelFor(formB) ?? "???" 25 | 26 | return "Intersection #\(index) of \(formAName) and \(formBName)" 27 | } 28 | 29 | public func getPositionFor(_ runtime: R) -> Vec2d? { 30 | guard let 31 | formAOutline = runtime.get(formA)?.outline, 32 | let formBOutline = runtime.get(formB)?.outline else { 33 | return nil 34 | } 35 | 36 | let intersections = intersectionsForRuntime(runtime, a: formAOutline, b: formBOutline) 37 | 38 | return intersections.count > index ? intersections[index] : nil 39 | } 40 | } 41 | 42 | extension RuntimeIntersectionPoint : Equatable { 43 | } 44 | 45 | public func ==(lhs: RuntimeIntersectionPoint, rhs: RuntimeIntersectionPoint) -> Bool { 46 | return lhs.formA == rhs.formA && lhs.formB == rhs.formB && lhs.index == rhs.index 47 | } 48 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/ExposedPoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExposedPoint.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct ExposedPointIdentifier : Hashable { 12 | public typealias IntegerLiteralType = Int8 13 | 14 | public let value : Int 15 | 16 | public init(_ value : Int) { 17 | self.value = value 18 | } 19 | public var hashValue : Int { return Int(value) } 20 | } 21 | 22 | extension ExposedPointIdentifier : ExpressibleByIntegerLiteral, RawRepresentable { 23 | 24 | public init?(rawValue: Int) { 25 | self.value = rawValue 26 | } 27 | 28 | public var rawValue: Int { 29 | return value 30 | } 31 | 32 | public init(integerLiteral value: Int8) { 33 | self.value = Int(value) 34 | } 35 | 36 | } 37 | 38 | public func ==(lhs: ExposedPointIdentifier, rhs: ExposedPointIdentifier) -> Bool { 39 | return lhs.value == rhs.value 40 | } 41 | 42 | struct ExposedPoint : RuntimePoint, Labeled { 43 | fileprivate let point : RuntimePoint 44 | fileprivate let name : String 45 | 46 | init(point:RuntimePoint, name: String) { 47 | self.point = point 48 | self.name = name 49 | } 50 | 51 | func getPositionFor(_ runtime: R) -> Vec2d? { 52 | return point.getPositionFor(runtime) 53 | } 54 | 55 | func getDescription(_ stringifier: Stringifier) -> String { 56 | return name 57 | } 58 | } 59 | 60 | extension ExposedPoint : Equatable { 61 | 62 | } 63 | 64 | func ==(lhs: ExposedPoint, rhs: ExposedPoint) -> Bool { 65 | return lhs.point.isEqualTo(rhs.point) 66 | } 67 | -------------------------------------------------------------------------------- /ReformExpression/ReformExpression/Value.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Value.swift 3 | // ExpressionEngine 4 | // 5 | // Created by Laszlo Korte on 07.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public enum Value : Equatable { 10 | case stringValue(value: String) 11 | case intValue(value: Int) 12 | case doubleValue(value: Double) 13 | case colorValue(r: UInt8, g:UInt8, b:UInt8, a:UInt8) 14 | case boolValue(value: Bool) 15 | 16 | public init(string: String) { 17 | self = .stringValue(value: string) 18 | } 19 | 20 | public init(int: Int) { 21 | self = .intValue(value: int) 22 | } 23 | 24 | public init(double: Double) { 25 | self = .doubleValue(value: double) 26 | } 27 | 28 | public init(r: UInt8,g: UInt8,b: UInt8,a: UInt8) { 29 | self = .colorValue(r:r, g:g, b:b, a:a) 30 | } 31 | 32 | public init(bool: Bool) { 33 | self = .boolValue(value: bool) 34 | } 35 | } 36 | 37 | public func ==(lhs: Value, rhs: Value) -> Bool { 38 | switch (lhs, rhs) { 39 | case (.stringValue(let left), .stringValue(let right)) where left == right: return true 40 | case (.intValue(let left), .intValue(let right)) where left == right: return true 41 | case (.doubleValue(let left), .doubleValue(let right)) where left == right: return true 42 | case (.colorValue(let lr, let lg, let lb, let la), .colorValue(let rr, let rg, let rb, let ra)) where lr==rr && lg == rg && lb == rb && la == ra: return true 43 | case (.boolValue(let left), .boolValue(let right)) where left == right: return true 44 | 45 | default: 46 | return false 47 | } 48 | } 49 | 50 | struct ValueList { 51 | let values : [Value] 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /ReformTools/ReformTools/HandleFinder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HandleFinder.swift 3 | // ReformTools 4 | // 5 | // Created by Laszlo Korte on 21.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | import ReformMath 11 | import ReformCore 12 | import ReformStage 13 | import ReformExpression 14 | 15 | 16 | struct HandleQuery : Equatable { 17 | let filter: FormFilter 18 | let location : LocationFilter 19 | } 20 | 21 | func ==(lhs: HandleQuery, rhs: HandleQuery) -> Bool { 22 | return lhs.filter == rhs.filter && lhs.location == rhs.location 23 | } 24 | 25 | struct HandleFinder { 26 | let stage : Stage 27 | 28 | func getUpdatedHandle(_ oldHandle: Handle) -> Handle? { 29 | for entity in stage.entities 30 | where entity.id == oldHandle.formId { 31 | for handle in entity.handles 32 | where handle.anchorId == oldHandle.anchorId { 33 | return handle 34 | } 35 | } 36 | 37 | return nil 38 | } 39 | 40 | 41 | func getHandles(_ query: HandleQuery) -> [Handle] { 42 | var result = [Handle]() 43 | 44 | if case FormFilter.none = query.filter { 45 | return result 46 | } 47 | 48 | 49 | for entity in stage.entities { 50 | if query.filter.excludes(entity.id) { 51 | continue 52 | } 53 | 54 | for handle in entity.handles { 55 | guard query.location.matches(handle.position) else { 56 | continue 57 | } 58 | result.append(handle) 59 | } 60 | 61 | } 62 | 63 | 64 | return result 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/ProcedureViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProcedureViewModel.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 26.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformExpression 11 | import ReformTools 12 | 13 | final class ProcedureViewModel { 14 | let analyzer : DefaultAnalyzer 15 | let instructionFocus : InstructionFocus 16 | let snapshotCollector : SnapshotCollector 17 | let instructionFocusChanger : InstructionFocusChanger 18 | let instructionChanger : () -> () 19 | let formSelection : FormSelection 20 | let formIdSequence : IdentifierSequence 21 | let nameAllocator : NameAllocator 22 | let lexer : Lexer 23 | let parser : ShuntingYardParser 24 | 25 | init(analyzer: DefaultAnalyzer, instructionFocus : InstructionFocus, snapshotCollector : SnapshotCollector, instructionFocusChanger : InstructionFocusChanger, formSelection: FormSelection, formIdSequence: IdentifierSequence, nameAllocator: NameAllocator, 26 | lexer : Lexer, 27 | parser: ShuntingYardParser, 28 | instructionChanger : @escaping () -> ()) { 29 | self.analyzer = analyzer 30 | self.instructionFocus = instructionFocus 31 | self.snapshotCollector = snapshotCollector 32 | self.instructionFocusChanger = instructionFocusChanger 33 | self.instructionChanger = instructionChanger 34 | self.formSelection = formSelection 35 | self.nameAllocator = nameAllocator 36 | self.formIdSequence = formIdSequence 37 | self.lexer = lexer 38 | self.parser = parser 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/LineOutline.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LineOutline.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 13.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | struct LineOutline : Outline { 12 | private let start : RuntimePoint 13 | private let end : RuntimePoint 14 | 15 | init(start: RuntimePoint, end:RuntimePoint) { 16 | self.start = start 17 | self.end = end 18 | } 19 | 20 | func getPositionFor(_ runtime: R, t: Double) -> Vec2d? { 21 | guard let 22 | a = start.getPositionFor(runtime), 23 | let b = end.getPositionFor(runtime) else { 24 | return nil 25 | } 26 | 27 | return lerp(t, a: a, b:b) 28 | } 29 | 30 | func getLengthFor(_ runtime: R) -> Double? { 31 | guard let 32 | a = start.getPositionFor(runtime), 33 | let b = end.getPositionFor(runtime) else { 34 | return nil 35 | } 36 | 37 | return (b-a).length 38 | } 39 | 40 | func getSegmentsFor(_ runtime: R) -> SegmentPath { 41 | guard let 42 | from = start.getPositionFor(runtime), 43 | let to = end.getPositionFor(runtime) else { 44 | return [] 45 | } 46 | 47 | return [.line(LineSegment2d(from: from, to: to))] 48 | } 49 | 50 | func getAABBFor(_ runtime: R) -> AABB2d? { 51 | guard let 52 | from = start.getPositionFor(runtime), 53 | let to = end.getPositionFor(runtime) else { 54 | return nil 55 | } 56 | 57 | return AABB2d(min: min(from, to), max: max(from, to)) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ReformMath/ReformMath/Mat3x2.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Mat3x2.swift 3 | // ReformMath 4 | // 5 | // Created by Laszlo Korte on 03.10.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | public struct Mat3x2 : Equatable { 10 | public static let Identity = Mat3x2() 11 | public static let Zero = Mat3x2(col1: Vec2d.Zero, col2: Vec2d.Zero, col3: Vec2d.Zero) 12 | 13 | public let col1 : Vec2d 14 | public let col2 : Vec2d 15 | public let col3 : Vec2d 16 | 17 | public init() { 18 | col1 = Vec2d.XAxis 19 | col2 = Vec2d.YAxis 20 | col3 = Vec2d.Zero 21 | } 22 | 23 | public init(scale factor: Double) { 24 | col1 = factor * Vec2d.XAxis 25 | col2 = factor * Vec2d.YAxis 26 | col3 = Vec2d.Zero 27 | } 28 | 29 | public init(translate delta: Vec2d) { 30 | col1 = Vec2d.XAxis 31 | col2 = Vec2d.YAxis 32 | col3 = delta 33 | } 34 | 35 | public init(rotate angle: Angle) { 36 | col1 = Vec2d(x: angle.sin, y: angle.cos) 37 | col2 = Vec2d(x: -angle.sin, y: angle.cos) 38 | col3 = Vec2d.Zero 39 | } 40 | 41 | public init(col1: Vec2d, col2: Vec2d, col3: Vec2d) { 42 | self.col1 = col1 43 | self.col2 = col2 44 | self.col3 = col3 45 | } 46 | } 47 | 48 | public func ==(lhs: Mat3x2, rhs: Mat3x2) -> Bool { 49 | return lhs.col1 == rhs.col1 && lhs.col2 == rhs.col2 && lhs.col3 == rhs.col3 50 | } 51 | 52 | extension Mat3x2 { 53 | public init(rotate angle: Angle, fix: Vec2d) { 54 | self = Mat3x2(translate: fix) * Mat3x2(rotate: angle) * Mat3x2(translate: -fix) 55 | } 56 | 57 | public init(scale factor: Double, fix: Vec2d) { 58 | self = Mat3x2(translate: fix) * Mat3x2(scale: factor) * Mat3x2(translate: -fix) 59 | } 60 | } -------------------------------------------------------------------------------- /ReformStage/ReformStage/Handle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Handle.swift 3 | // ReformStage 4 | // 5 | // Created by Laszlo Korte on 15.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformCore 10 | import ReformMath 11 | 12 | public typealias PivotPair = (EntityPoint, EntityPoint) 13 | 14 | public struct Handle { 15 | public let formId : SourceIdentifier 16 | public let anchorId : AnchorIdentifier 17 | public let pointId : ExposedPointIdentifier 18 | 19 | public let label : String 20 | public let position : Vec2d 21 | } 22 | 23 | public struct AffineHandle { 24 | public let formId : SourceIdentifier 25 | public let pointId : ExposedPointIdentifier 26 | 27 | public let label : String 28 | public let position : Vec2d 29 | 30 | public let defaultPivot : PivotPair 31 | public let scaleAxis : ScaleAxis 32 | } 33 | 34 | extension Handle { 35 | public var runtimePoint : LabeledPoint { 36 | return ForeignFormPoint(formId: formId.runtimeId, pointId: pointId) 37 | } 38 | } 39 | 40 | 41 | extension Handle : Hashable { 42 | public var hashValue : Int { return formId.runtimeId.hashValue * 13 + anchorId.hashValue } 43 | } 44 | 45 | public func ==(lhs: Handle, rhs: Handle) -> Bool { 46 | return lhs.formId == rhs.formId && lhs.anchorId == rhs.anchorId 47 | } 48 | 49 | extension AffineHandle { 50 | public var runtimePoint : LabeledPoint { 51 | return ForeignFormPoint(formId: formId.runtimeId, pointId: pointId) 52 | } 53 | } 54 | 55 | 56 | extension AffineHandle : Hashable { 57 | public var hashValue : Int { 58 | return formId.hashValue * 13 + pointId.hashValue 59 | } 60 | } 61 | 62 | public func ==(lhs: AffineHandle, rhs: AffineHandle) -> Bool { 63 | return lhs.formId == rhs.formId && lhs.pointId == rhs.pointId 64 | } 65 | 66 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDocumentTypes 6 | 7 | 8 | CFBundleTypeExtensions 9 | 10 | mydoc 11 | 12 | CFBundleTypeIconFile 13 | 14 | CFBundleTypeName 15 | DocumentType 16 | CFBundleTypeOSTypes 17 | 18 | ???? 19 | 20 | CFBundleTypeRole 21 | Editor 22 | NSDocumentClass 23 | $(PRODUCT_MODULE_NAME).Document 24 | 25 | 26 | CFBundleDevelopmentRegion 27 | en 28 | CFBundleExecutable 29 | $(EXECUTABLE_NAME) 30 | CFBundleIconFile 31 | 32 | CFBundleIdentifier 33 | $(PRODUCT_BUNDLE_IDENTIFIER) 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | $(PRODUCT_NAME) 38 | CFBundlePackageType 39 | APPL 40 | CFBundleShortVersionString 41 | 1.0 42 | CFBundleSignature 43 | ???? 44 | CFBundleVersion 45 | 1 46 | LSMinimumSystemVersion 47 | $(MACOSX_DEPLOYMENT_TARGET) 48 | NSHumanReadableCopyright 49 | Copyright © 2015 Laszlo Korte. All rights reserved. 50 | NSMainStoryboardFile 51 | Main 52 | NSPrincipalClass 53 | NSApplication 54 | 55 | 56 | -------------------------------------------------------------------------------- /SETUP.md: -------------------------------------------------------------------------------- 1 | Reform - Setup 2 | ============== 3 | 4 | Building the app 5 | ---------------- 6 | 7 | The project repository contains an Xcode7-Workspace(Reform.xcworkspace) with 8 Xcode projects. 8 | 9 | The application can be built by opening the workspace in Xcode and selecting the "ReformApplication" Scheme. 10 | 11 | 12 | Project structure 13 | ----------------- 14 | 15 | The Project is split into multiple Xcode projects which partially depend on each other. 16 | 17 | This separation in projects is made to emphasize a layer architecture. 18 | 19 | As reform is an drawing application it would be easy to mix up the model and the ui layer. This mixup shall be prevented. 20 | 21 | NSColor and NSBeszierPath structs must not be used in the model layer 22 | 23 | - ReformGraphics: Defines the privitimes used to compose a vector graphics. It belongs to the model layer and allows constructing (colored) shapes without relaying on the NSBesizrPath api/AppKit/Cocoa 24 | 25 | - ReformExpression: The library for parsing and evaluating mathematical expressions 26 | 27 | - ReformSerializer: Provides functions to serialize and deserialize a project 28 | 29 | - ReformTools: Defines the tools available to the user for manipulating the picture 30 | 31 | - ReformStage: Defines the presentation of the picture on the canvas for editing. Does not include the tools for editing. Does not depend on Appkit/Cocoa 32 | 33 | - ReformMath: Contains functions and types to support 2D vector math. May be replaced with some other vector library in the future. 34 | 35 | - ReformCore: The core project defining all types required to define a dynamic picture and the runtime needed to evaluate it. 36 | 37 | - ReformApplication: The only project/component relying on AppKit. It contains all the controllers and adapters to present the picture, stage and editing tools through a Cocoa interface 38 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/FormInteratorInstruction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FormInteratorInstruction.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 25.09.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | 10 | public struct FormIteratorInstruction : GroupInstruction { 11 | public let proxyForm: ProxyForm 12 | public let formIds : [FormIdentifier] 13 | 14 | public var target : FormIdentifier? { return proxyForm.identifier } 15 | 16 | public init(proxyForm: ProxyForm, formIds : [FormIdentifier]) { 17 | self.proxyForm = proxyForm 18 | self.formIds = formIds 19 | } 20 | 21 | public func evaluate(_ runtime: T, withChildren children: [InstructionNode]) where T.Ev==InstructionNode { 22 | 23 | let forms = formIds.flatMap { 24 | runtime.get($0) 25 | } 26 | 27 | guard forms.count == formIds.count else { 28 | runtime.reportError(.unknownForm) 29 | return 30 | } 31 | 32 | for form in forms { 33 | runtime.scoped() { runtime in 34 | runtime.declare(proxyForm) 35 | proxyForm.initWithRuntime(runtime, form: form) 36 | for c in children where !runtime.shouldStop { 37 | c.evaluate(runtime) 38 | } 39 | } 40 | } 41 | } 42 | 43 | public func getDescription(_ stringifier: Stringifier) -> String { 44 | let names = formIds.map({ 45 | stringifier.labelFor($0) ?? "???" 46 | }).joined(separator: ", ") 47 | 48 | return "With each [\(names)] as \(proxyForm.name) do:" 49 | } 50 | 51 | 52 | 53 | public func analyze(_ analyzer: T) { 54 | analyzer.announceForm(proxyForm) 55 | } 56 | 57 | public var isDegenerated : Bool { 58 | return false 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ReformCore/ReformCore/RelativeDestination.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RelativeDestination.swift 3 | // ReformCore 4 | // 5 | // Created by Laszlo Korte on 17.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import ReformMath 10 | 11 | public struct RelativeDestination : RuntimeInitialDestination, Labeled { 12 | public typealias PointType = RuntimePoint & Labeled 13 | public typealias DirectionType = RuntimeDirection & Labeled 14 | 15 | public let from: PointType 16 | public let to: PointType 17 | public let direction : DirectionType 18 | public let alignment : RuntimeAlignment 19 | 20 | public init(from: PointType, to: PointType, direction : DirectionType = FreeDirection(), alignment: RuntimeAlignment = .leading) { 21 | self.from = from 22 | self.to = to 23 | self.direction = direction 24 | self.alignment = alignment 25 | } 26 | 27 | public func getMinMaxFor(_ runtime: R) -> (Vec2d,Vec2d)? { 28 | guard let 29 | fromPos = from.getPositionFor(runtime), 30 | let toPos = to.getPositionFor(runtime) else { 31 | return nil 32 | } 33 | 34 | return alignment.getMinMax(from: fromPos, to: direction.getAdjustedFor(runtime, anchor: fromPos, position: toPos)) 35 | } 36 | 37 | public func getDescription(_ stringifier: Stringifier) -> String { 38 | let fromLabel = from.getDescription(stringifier) 39 | let toLabel = to.getDescription(stringifier) 40 | 41 | switch alignment { 42 | case .centered: 43 | return "\(direction.getDescription(stringifier)) around \(fromLabel) to \(toLabel)" 44 | case .leading: 45 | return "\(direction.getDescription(stringifier)) from \(fromLabel) to \(toLabel)" 46 | } 47 | } 48 | 49 | public var isDegenerated : Bool { 50 | return from.isEqualTo(to) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ReformApplication/ReformApplication/CropUI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CropUI.swift 3 | // ReformApplication 4 | // 5 | // Created by Laszlo Korte on 18.08.15. 6 | // Copyright © 2015 Laszlo Korte. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ReformTools 11 | import ReformStage 12 | 13 | struct CropUIRenderer : Renderer { 14 | let stage : Stage 15 | let cropUI : CropUI 16 | let camera: Camera 17 | 18 | func renderInContext(_ context: CGContext) { 19 | let inverse = CGFloat(1 / camera.zoom) 20 | 21 | context.setFillColor(red: 0.23, green: 0.85, blue: 0.3, alpha: 1) 22 | context.setStrokeColor(red: 0.18, green: 0.5, blue: 0.24, alpha: 1) 23 | context.setLineWidth(2 * inverse) 24 | let dotSize : Double = 9 / camera.zoom 25 | 26 | 27 | switch cropUI.state { 28 | case .hide: 29 | return 30 | case .show(let points): 31 | for p in points { 32 | drawDotAt(context, position: p.position, size: dotSize) 33 | } 34 | context.drawPath(using: .fillStroke) 35 | case .active(let active, let points): 36 | 37 | context.setStrokeColor(red: 0.23, green: 0.85, blue: 0.3, alpha: 1) 38 | context.setLineWidth(3 * inverse) 39 | context.stroke(CGRect(x:0,y:0, width: stage.size.x, height: stage.size.y)) 40 | 41 | context.setFillColor(red: 0.23, green: 0.85, blue: 0.3, alpha: 1) 42 | context.setStrokeColor(red: 0.18, green: 0.5, blue: 0.24, alpha: 1) 43 | context.setLineWidth(2 * inverse) 44 | 45 | for p in points { 46 | drawDotAt(context, position: p.position, size: dotSize) 47 | } 48 | context.drawPath(using: .fillStroke) 49 | 50 | drawDotAt(context, position: active.position, size: dotSize*1.5) 51 | context.drawPath(using: .fillStroke) 52 | } 53 | } 54 | } 55 | --------------------------------------------------------------------------------