diff --git a/ReferenceTests/Retro68/CMakeLists.txt b/ReferenceTests/Retro68/CMakeLists.txt index 332dd7a..9b5eaa2 100644 --- a/ReferenceTests/Retro68/CMakeLists.txt +++ b/ReferenceTests/Retro68/CMakeLists.txt @@ -8,3 +8,4 @@ add_application(CatalogOrderCapture CatalogOrderCapture.c) add_application(HighLevelEventCapture HighLevelEventCapture.c HighLevelEventCapture.r) add_application(MemoryManagerCapture MemoryManagerCapture.c) add_application(MixedModeCapture MixedModeCapture.c) +add_application(RegionRecordingCapture RegionRecordingCapture.c) diff --git a/ReferenceTests/Retro68/README.md b/ReferenceTests/Retro68/README.md index 6b33abc..111e88e 100644 --- a/ReferenceTests/Retro68/README.md +++ b/ReferenceTests/Retro68/README.md @@ -229,3 +229,36 @@ The capture doesn't cover 68k callers, which reach a descriptor through its trap word, or PowerPC fragments that need preparing. `MixedModeTests` checks `GraphiteMixedMode` against the capture; Graphite throws for the cases that crashed or weren't run. + +## Region recording + +`RegionRecordingCapture.c` draws in a port over a bitmap in memory, between +`OpenRgn` and `CloseRgn`, and writes the region each case gives: its record's +bytes, the pen's location and how many pixels were inked. Its output on Mac OS +9.2.2 is `RegionRecording-macos-9.2.2-ppc.txt` (CR line endings), from the +UTM setup above. + +- Nothing was drawn while a region was open, whatever the verb: no pixel was + inked by paint, erase, invert or fill either. +- Only framed shapes were recorded: FrameRect, FrameOval, FrameRoundRect, + FrameRgn and FramePoly gave the shape's region, whatever the pen's size, + and with the pen hidden. PaintRect, EraseRect, InvertRect, FillRect and + PaintOval gave nothing, so did FrameRect on an empty rectangle, and + FrameArc, whose edge alone encloses nothing. +- Shapes combined by the even-odd rule: two overlapping rectangles left the + overlap out. +- Lines added a region only as a path that came back to where it began. A + triangle of three `LineTo`s gave the same region as `FramePoly`; one line, + or two lines that didn't close, gave an empty one. (A single diagonal + `Line(4,4)` gave a staircase of pixels, which Graphite doesn't reproduce.) + `LineTo` moved the pen as usual, and `FramePoly` left it at the polygon's + last point. +- A polygon's region covers, in each row, the columns right of the left + edge's crossing and left of the right edge's, the crossings taken at the + row's top: a triangle with its left edge at column 2 starts at column 3. + Only one triangle was measured. +- A second `OpenRgn` started the region over, and `CloseRgn` with none open + gave an empty region, with no error. + +`RegionRecordingTests` checks `Port.beginRegion` and `endRegion` against the +capture. diff --git a/ReferenceTests/Retro68/RegionRecording-macos-9.2.2-ppc.txt b/ReferenceTests/Retro68/RegionRecording-macos-9.2.2-ppc.txt new file mode 100644 index 0000000..6255a79 --- /dev/null +++ b/ReferenceTests/Retro68/RegionRecording-macos-9.2.2-ppc.txt @@ -0,0 +1 @@ +# Nothing recorded OpenRgn, CloseRgn -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 # Framed shapes FrameRect -> size 10, pen (0,0), inked 0, bytes: 000A 0002 0002 0006 0006 FrameRect, FrameRect overlapping -> size 44, pen (0,0), inked 0, bytes: 002C 0002 0002 000A 000A 0002 0002 0006 7FFF 0004 0004 000A 7FFF 0006 0002 0006 7FFF 000A 0004 000A 7FFF 7FFF FrameOval -> size 52, pen (0,0), inked 0, bytes: 0034 0004 0004 000A 000A 0004 0005 0009 7FFF 0005 0004 0005 0009 000A 7FFF 0009 0004 0005 0009 000A 7FFF 000A 0005 0009 7FFF 7FFF FrameRoundRect 4,4 -> size 52, pen (0,0), inked 0, bytes: 0034 0004 0004 000A 000A 0004 0005 0009 7FFF 0005 0004 0005 0009 000A 7FFF 0009 0004 0005 0009 000A 7FFF 000A 0005 0009 7FFF 7FFF FrameArc 0,90 -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 FrameRect of an empty rectangle -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 FrameRect, pen 2x2 -> size 10, pen (0,0), inked 0, bytes: 000A 0002 0002 0006 0006 FrameRgn -> size 10, pen (0,0), inked 0, bytes: 000A 0002 0002 0006 0006 FramePoly of a triangle -> size 60, pen (2,2), inked 0, bytes: 003C 0002 0003 0007 0008 0002 0003 0008 7FFF 0003 0007 0008 7FFF 0004 0003 0004 7FFF 0005 0006 0007 7FFF 0006 0004 0005 7FFF 0007 0005 0006 7FFF 7FFF # Lines MoveTo, LineTo: one line -> size 10, pen (9,1), inked 0, bytes: 000A 0000 0000 0000 0000 open path of two lines -> size 10, pen (9,7), inked 0, bytes: 000A 0000 0000 0000 0000 closed triangle of lines -> size 60, pen (2,2), inked 0, bytes: 003C 0002 0003 0007 0008 0002 0003 0008 7FFF 0003 0007 0008 7FFF 0004 0003 0004 7FFF 0005 0006 0007 7FFF 0006 0004 0005 7FFF 0007 0005 0006 7FFF 7FFF Line(4,4) -> size 44, pen (5,5), inked 0, bytes: 002C 0001 0001 0004 0005 0001 0001 0002 7FFF 0002 0002 0003 7FFF 0003 0003 0004 7FFF 0004 0004 0005 7FFF 7FFF one line, pen 2x2 -> size 10, pen (9,1), inked 0, bytes: 000A 0000 0000 0000 0000 FrameRect with the pen hidden -> size 10, pen (0,0), inked 0, bytes: 000A 0002 0002 0006 0006 # Other verbs while open PaintRect -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 EraseRect -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 InvertRect -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 FillRect black -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 PaintOval -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 FrameRect then PaintRect -> size 10, pen (0,0), inked 0, bytes: 000A 0002 0002 0006 0006 # Open twice second OpenRgn after FrameRect, then FrameRect, one CloseRgn -> size 10, pen (0,0), inked 0, bytes: 000A 0004 0004 000A 000A # Without OpenRgn FrameRect, nothing open -> nil, QDError 0 (inked count above is the framed rectangle drawn) # CloseRgn with none open CloseRgn without OpenRgn -> size 10, pen (0,0), inked 0, bytes: 000A 0000 0000 0000 0000 # Done \ No newline at end of file diff --git a/ReferenceTests/Retro68/RegionRecordingCapture.c b/ReferenceTests/Retro68/RegionRecordingCapture.c new file mode 100644 index 0000000..b71fe94 --- /dev/null +++ b/ReferenceTests/Retro68/RegionRecordingCapture.c @@ -0,0 +1,148 @@ +/* + * Captures what OpenRgn and CloseRgn record, writing "RegionRecording.txt" + * next to itself. It refuses to run if that file is already there. The file + * is flushed after every line, so a call that crashes leaves the lines + * before it; the calls most likely to crash come last. + * + * It draws in a port of its own over a 32 by 16 pixel bitmap in memory, not + * on the screen. For each case it records the region CloseRgn gives: its + * handle's size and bytes (rgnSize, rgnBBox, then scanline inversion + * points), the pen's location afterward, and how many bitmap pixels were + * set, which says whether anything was drawn while the region was open. + */ +#include +#include +#include +#include +#include + +static short out; +static GrafPort port; +static BitMap bits; +static char pixels[4 * 16]; + +static void line(const char *text) +{ + long count = strlen(text); + FSWrite(out, &count, text); + count = 1; + FSWrite(out, &count, "\r"); + FlushVol(0, 0); +} + +static long inked(void) +{ + long count = 0; + int i, bit; + for (i = 0; i < (int)sizeof pixels; i++) + for (bit = 0; bit < 8; bit++) + if (((unsigned char)pixels[i] >> bit) & 1) count++; + return count; +} + +static void clear(void) +{ + memset(pixels, 0, sizeof pixels); + PenNormal(); + MoveTo(0, 0); +} + +/* The region CloseRgn gave: size, bytes, pen and ink, then disposed. */ +static void report(const char *label, RgnHandle rgn) +{ + char text[400]; + Point pen; + long size, i; + int used; + GetPen(&pen); + if (!rgn) { + snprintf(text, sizeof text, "%s -> nil, QDError %d", label, QDError()); + line(text); + return; + } + size = GetHandleSize((Handle)rgn); + used = snprintf(text, sizeof text, "%s -> size %ld, pen (%d,%d), inked %ld, bytes:", + label, size, pen.h, pen.v, inked()); + for (i = 0; i < size && used < (int)sizeof text - 4; i++) + used += snprintf(text + used, sizeof text - used, "%s%02X", i % 2 ? "" : " ", ((unsigned char *)*rgn)[i]); + line(text); + DisposeRgn(rgn); +} + +/* CloseRgn into a new region, then report it. */ +static void finish(const char *label) +{ + RgnHandle rgn = NewRgn(); + CloseRgn(rgn); + report(label, rgn); +} + +int main(void) +{ + static const unsigned char name[] = { 19, 'R','e','g','i','o','n','R','e','c','o','r','d','i','n','g','.','t','x','t' }; + Rect box = { 0, 0, 16, 32 }; + Rect a = { 2, 2, 6, 6 }, b = { 4, 4, 10, 10 }, flat = { 5, 5, 5, 9 }; + RgnHandle rgn; + PolyHandle poly; + + if (Create(name, 0, 'Grph', 'TEXT') != noErr) return 1; + if (FSOpen(name, 0, &out) != noErr) return 2; + + OpenPort(&port); + bits.baseAddr = pixels; + bits.rowBytes = 4; + bits.bounds = box; + SetPortBits(&bits); + port.portRect = box; + RectRgn(port.visRgn, &box); + RectRgn(port.clipRgn, &box); + + line("# Nothing recorded"); + clear(); OpenRgn(); finish("OpenRgn, CloseRgn"); + + line("# Framed shapes"); + clear(); OpenRgn(); FrameRect(&a); finish("FrameRect"); + clear(); OpenRgn(); FrameRect(&a); FrameRect(&b); finish("FrameRect, FrameRect overlapping"); + clear(); OpenRgn(); FrameOval(&b); finish("FrameOval"); + clear(); OpenRgn(); FrameRoundRect(&b, 4, 4); finish("FrameRoundRect 4,4"); + clear(); OpenRgn(); FrameArc(&b, 0, 90); finish("FrameArc 0,90"); + clear(); OpenRgn(); FrameRect(&flat); finish("FrameRect of an empty rectangle"); + clear(); PenSize(2, 2); OpenRgn(); FrameRect(&a); finish("FrameRect, pen 2x2"); + clear(); rgn = NewRgn(); RectRgn(rgn, &a); OpenRgn(); FrameRgn(rgn); finish("FrameRgn"); + DisposeRgn(rgn); + clear(); poly = OpenPoly(); MoveTo(2, 2); LineTo(8, 2); LineTo(5, 8); LineTo(2, 2); ClosePoly(); + clear(); OpenRgn(); FramePoly(poly); finish("FramePoly of a triangle"); + KillPoly(poly); + + line("# Lines"); + clear(); OpenRgn(); MoveTo(1, 1); LineTo(9, 1); finish("MoveTo, LineTo: one line"); + clear(); OpenRgn(); MoveTo(1, 1); LineTo(9, 1); LineTo(9, 7); finish("open path of two lines"); + clear(); OpenRgn(); MoveTo(2, 2); LineTo(8, 2); LineTo(5, 8); LineTo(2, 2); finish("closed triangle of lines"); + clear(); OpenRgn(); MoveTo(1, 1); Line(4, 4); finish("Line(4,4)"); + clear(); PenSize(2, 2); OpenRgn(); MoveTo(1, 1); LineTo(9, 1); finish("one line, pen 2x2"); + clear(); HidePen(); OpenRgn(); FrameRect(&a); finish("FrameRect with the pen hidden"); ShowPen(); + + line("# Other verbs while open"); + clear(); OpenRgn(); PaintRect(&a); finish("PaintRect"); + clear(); OpenRgn(); EraseRect(&a); finish("EraseRect"); + clear(); OpenRgn(); InvertRect(&a); finish("InvertRect"); + clear(); OpenRgn(); FillRect(&a, &qd.black); finish("FillRect black"); + clear(); OpenRgn(); PaintOval(&a); finish("PaintOval"); + clear(); OpenRgn(); FrameRect(&a); PaintRect(&b); finish("FrameRect then PaintRect"); + + line("# Open twice"); + clear(); OpenRgn(); FrameRect(&a); OpenRgn(); FrameRect(&b); finish("second OpenRgn after FrameRect, then FrameRect, one CloseRgn"); + + line("# Without OpenRgn"); + clear(); FrameRect(&a); report("FrameRect, nothing open", (RgnHandle)0); + line(" (inked count above is the framed rectangle drawn)"); + + /* Last: a CloseRgn with no region open may crash. */ + line("# CloseRgn with none open"); + clear(); rgn = NewRgn(); CloseRgn(rgn); report("CloseRgn without OpenRgn", rgn); + + line("# Done"); + FSClose(out); + FlushVol(0, 0); + return 0; +} diff --git a/Sources/Graphite2D/Drawing.swift b/Sources/Graphite2D/Drawing.swift index ccf12b0..ce1819c 100644 --- a/Sources/Graphite2D/Drawing.swift +++ b/Sources/Graphite2D/Drawing.swift @@ -61,6 +61,11 @@ public extension Port { /// Does one of QuickDraw's shape operations on a region. func perform(_ operation: ShapeOperation, on region: Region, outline: () -> Region) { + // A region being recorded takes a framed shape, and nothing is drawn. + if openRegion != nil { + if case .frame = operation { record(region) } + return + } switch operation { case .frame: guard isPenVisible else { return } @@ -102,6 +107,8 @@ public extension Port { /// FrameArc and the rest: FrameArc draws the oval's edge alone, not the /// wedge's sides. func perform(_ operation: ShapeOperation, arc rect: Rect, startAngle: Int16, arcAngle: Int16) { + // The arc's edge alone isn't closed, so it encloses nothing to record. + guard openRegion == nil else { return } let region = Region.arc(in: rect, startAngle: startAngle, arcAngle: arcAngle) perform(operation, on: region) { region.subtracting(.oval(in: rect.insetBy(dh: pen.size.h, dv: pen.size.v))) @@ -111,6 +118,14 @@ public extension Port { /// FramePoly and the rest: FramePoly draws lines between the points, as /// LineTo does. func perform(_ operation: ShapeOperation, polygon: Polygon) { + if openRegion != nil { + // Mac OS 9.2.2 left the pen at the polygon's last point. + if case .frame = operation, let last = polygon.points.last { + record(.outlinedPolygon(polygon)) + pen.location = last + } + return + } let region = Region.polygon(polygon) perform(operation, on: region) { var outline = Region() @@ -129,7 +144,9 @@ public extension Port { /// LineTo: a line from the pen's location to a point, which becomes the /// pen's location. func line(to point: Point) { - if isPenVisible { + if openRegion != nil { + recordLine(from: pen.location, to: point) + } else if isPenVisible { draw(.line(from: pen.location, to: point, pen: pen.size), pattern: pen.pattern, mode: pen.mode) } pen.location = point diff --git a/Sources/Graphite2D/Port.swift b/Sources/Graphite2D/Port.swift index d7252d7..ecca7a8 100644 --- a/Sources/Graphite2D/Port.swift +++ b/Sources/Graphite2D/Port.swift @@ -91,9 +91,55 @@ public final class Port { /// others don't cover; a world's, all of it. public var visibleRegion: Region + /// The region OpenRgn has begun and CloseRgn hasn't ended, or nil. While + /// there is one, nothing is drawn: framed shapes add to it, and so does + /// a path of lines that comes back to where it began. Mac OS 9.2.2 + /// (ReferenceTests/Retro68/RegionRecording-macos-9.2.2-ppc.txt) recorded + /// nothing for paint, erase, invert and fill, for FrameArc, or for a + /// path left open. + public private(set) var openRegion: Region? + + /// The points of the path of lines being recorded. + private var recordedPath: [Point] = [] + /// The device the port's pixels are on, for its global coordinates. public weak var device: GraphicsDevice? + /// OpenRgn: starts recording a region, as an empty one. One already + /// being recorded is lost. + public func beginRegion() { + openRegion = Region() + recordedPath = [] + } + + /// CloseRgn: the region recorded since OpenRgn. Mac OS 9.2.2 gave an + /// empty region, and no error, when none was open; this gives nil. + public func endRegion() -> Region? { + defer { + openRegion = nil + recordedPath = [] + } + return openRegion + } + + /// Adds to the region being recorded; nothing if none is open. Where + /// recorded shapes overlap, Mac OS 9.2.2 left a hole: outlines record by + /// the even-odd rule. + func record(_ region: Region) { + openRegion = openRegion?.symmetricDifference(region) + } + + /// A line of a path being recorded. A path that returns to its start, + /// after at least three lines, adds the polygon it makes. + func recordLine(from start: Point, to end: Point) { + if recordedPath.last != start { recordedPath = [start] } + recordedPath.append(end) + if recordedPath.count >= 4, end == recordedPath[0] { + record(.outlinedPolygon(Polygon(points: Array(recordedPath.dropLast())))) + recordedPath = [] + } + } + /// A port over pixels, showing all of them. public init(pixels: PixelBuffer) { self.pixels = pixels diff --git a/Sources/Graphite2D/Shapes.swift b/Sources/Graphite2D/Shapes.swift index f6058cb..3b69307 100644 --- a/Sources/Graphite2D/Shapes.swift +++ b/Sources/Graphite2D/Shapes.swift @@ -156,6 +156,37 @@ public extension Region { return Region(bands: bands) } + /// The region Mac OS 9.2.2 recorded for a framed polygon, or a path of + /// lines that came back to its start (ReferenceTests/Retro68/ + /// RegionRecording-macos-9.2.2-ppc.txt): by the even-odd rule, in each + /// row a pair of crossings, taken where the edges meet the row's top, + /// covers the columns right of the first and left of the second's whole + /// column. Measured on one triangle; PaintPoly is not known to agree. + static func outlinedPolygon(_ polygon: Polygon) -> Region { + let points = polygon.points + guard points.count >= 3 else { return Region() } + let box = polygon.bounds + var bands: [Band] = [] + for row in Int(box.top) ..< Int(box.bottom) { + let y = Double(row) + var crossings: [Double] = [] + for (index, a) in points.enumerated() { + let b = points[(index + 1) % points.count] + let ay = Double(a.v), by = Double(b.v) + guard (ay <= y && y < by) || (by <= y && y < ay) else { continue } + crossings.append(Double(a.h) + (y - ay) / (by - ay) * Double(Int(b.h) - Int(a.h))) + } + crossings.sort() + var spans: [Span] = [] + for pair in stride(from: 0, to: crossings.count - 1, by: 2) { + let left = Int(crossings[pair].rounded(.down)) + 1, right = Int(crossings[pair + 1].rounded(.down)) + if left < right { spans.append(Span(left: left, right: right)) } + } + if !spans.isEmpty { bands.append(Band(top: row, bottom: row + 1, spans: spans)) } + } + return Region(bands: bands) + } + /// A line from one point to another, each point it passes through /// covered by the pen's rectangle, `pen.h` wide and `pen.v` high. static func line(from start: Point, to end: Point, pen: Point) -> Region { diff --git a/Tests/Graphite2DTests/RegionRecordingTests.swift b/Tests/Graphite2DTests/RegionRecordingTests.swift new file mode 100644 index 0000000..80c249c --- /dev/null +++ b/Tests/Graphite2DTests/RegionRecordingTests.swift @@ -0,0 +1,111 @@ +import Foundation +import Testing +import GraphiteCore +import Graphite2D + +/// Lines of the Mac OS 9.2.2 capture (ReferenceTests/Retro68, +/// RegionRecording-macos-9.2.2-ppc.txt). +private let capture: [String] = { + let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent() + .deletingLastPathComponent().deletingLastPathComponent() + let data = try! Data(contentsOf: root.appendingPathComponent("ReferenceTests/Retro68/RegionRecording-macos-9.2.2-ppc.txt")) + return String(decoding: data, as: UTF8.self).split(separator: "\r").map(String.init) +}() + +/// The region record the capture shows for a case, and the pen it left. +private func captured(_ label: String) -> (record: [UInt8], pen: Point)? { + guard let line = capture.first(where: { $0.hasPrefix(label + " -> size") }), + let bytes = line.range(of: "bytes:"), let pen = line.range(of: "pen (") else { return nil } + let hex = line[bytes.upperBound...].filter { !$0.isWhitespace } + let record = stride(from: 0, to: hex.count, by: 2).map { offset -> UInt8 in + let start = hex.index(hex.startIndex, offsetBy: offset) + return UInt8(hex[start ..< hex.index(start, offsetBy: 2)], radix: 16)! + } + let numbers = line[pen.upperBound...].prefix { $0 != ")" }.split(separator: ",").map { Int16($0)! } + return (record, Point(v: numbers[1], h: numbers[0])) +} + +@Suite struct RegionRecordingTests { + + private func port() throws -> Graphite2D.Port { + let world = try GraphicsWorld(bounds: Rect(top: 0, left: 0, bottom: 16, right: 32), depth: 1) + world.port.eraseAll() + return world.port + } + + private let a = Rect(top: 2, left: 2, bottom: 6, right: 6) + private let b = Rect(top: 4, left: 4, bottom: 10, right: 10) + + /// Records what `draw` does between OpenRgn and CloseRgn, then checks it against the capture. + private func check(_ label: String, draw: (Graphite2D.Port) -> Void) throws { + let port = try port() + port.beginRegion() + draw(port) + let region = try #require(port.endRegion()) + let expected = try #require(captured(label), "\(label)") + #expect(region.record == expected.record, "\(label)") + #expect(port.pen.location == expected.pen, "\(label)") + #expect(port.openRegion == nil) + // Nothing is drawn while a region is open. + #expect(port.pixels?.color(at: Point(v: 3, h: 3)) == .white, "\(label)") + } + + @Test func nothingRecorded() throws { + try check("OpenRgn, CloseRgn") { _ in } + } + + @Test func framedShapesRecordTheirRegions() throws { + try check("FrameRect") { $0.perform(.frame, rect: a) } + try check("FrameRect, FrameRect overlapping") { $0.perform(.frame, rect: a); $0.perform(.frame, rect: b) } + try check("FrameRect of an empty rectangle") { $0.perform(.frame, rect: Rect(top: 5, left: 5, bottom: 5, right: 9)) } + try check("FrameRect, pen 2x2") { $0.pen.size = Point(v: 2, h: 2); $0.perform(.frame, rect: a) } + try check("FrameRect with the pen hidden") { $0.hidePen(); $0.perform(.frame, rect: a) } + try check("FrameRgn") { $0.perform(.frame, region: Region(rect: a)) } + } + + @Test func curvedShapes() throws { + try check("FrameOval") { $0.perform(.frame, oval: b) } + try check("FrameRoundRect 4,4") { $0.perform(.frame, roundRect: b, ovalWidth: 4, ovalHeight: 4) } + } + + @Test func framedPolygon() throws { + let triangle = Polygon(points: [Point(v: 2, h: 2), Point(v: 2, h: 8), Point(v: 8, h: 5), Point(v: 2, h: 2)]) + try check("FramePoly of a triangle") { $0.perform(.frame, polygon: triangle) } + } + + @Test func anArcEnclosesNothing() throws { + try check("FrameArc 0,90") { $0.perform(.frame, arc: b, startAngle: 0, arcAngle: 90) } + } + + @Test func otherVerbsNeitherDrawNorRecord() throws { + try check("PaintRect") { $0.perform(.paint, rect: a) } + try check("EraseRect") { $0.perform(.erase, rect: a) } + try check("InvertRect") { $0.perform(.invert, rect: a) } + try check("FillRect black") { $0.perform(.fill(.black), rect: a) } + try check("PaintOval") { $0.perform(.paint, oval: a) } + try check("FrameRect then PaintRect") { $0.perform(.frame, rect: a); $0.perform(.paint, rect: b) } + } + + @Test func aSecondOpenRgnStartsOver() throws { + try check("second OpenRgn after FrameRect, then FrameRect, one CloseRgn") { + $0.perform(.frame, rect: a) + $0.beginRegion() + $0.perform(.frame, rect: b) + } + } + + @Test func pathsOfLines() throws { + try check("MoveTo, LineTo: one line") { $0.move(to: Point(v: 1, h: 1)); $0.line(to: Point(v: 1, h: 9)) } + try check("open path of two lines") { + $0.move(to: Point(v: 1, h: 1)); $0.line(to: Point(v: 1, h: 9)); $0.line(to: Point(v: 7, h: 9)) + } + try check("closed triangle of lines") { + $0.move(to: Point(v: 2, h: 2)); $0.line(to: Point(v: 2, h: 8)) + $0.line(to: Point(v: 8, h: 5)); $0.line(to: Point(v: 2, h: 2)) + } + } + + @Test func closingWithNoneOpenIsNil() throws { + #expect(try port().endRegion() == nil) + } +}