From a2f437d4ad7570f0d5c6ac1fdd0a3cef9eeedd0f Mon Sep 17 00:00:00 2001 From: Elias Batek Date: Mon, 7 Oct 2024 03:43:44 +0200 Subject: [PATCH] Make PixmapScanner types bidirectional ranges --- pixmappaint.d | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/pixmappaint.d b/pixmappaint.d index adff89c..3c9165a 100644 --- a/pixmappaint.d +++ b/pixmappaint.d @@ -919,6 +919,11 @@ struct PixmapScanner { _width = pixmap.width; } + /// + typeof(this) save() { + return this; + } + /// bool empty() const { return (_data.length == 0); @@ -933,6 +938,16 @@ struct PixmapScanner { void popFront() { _data = _data[_width .. $]; } + + /// + const(Pixel)[] back() const { + return _data[($ - _width) .. $]; + } + + /// + void popBack() { + _data = _data[0 .. ($ - _width)]; + } } /++ @@ -957,6 +972,11 @@ struct PixmapScannerRW { _width = pixmap.width; } + /// + typeof(this) save() { + return this; + } + /// bool empty() const { return (_data.length == 0); @@ -971,6 +991,16 @@ struct PixmapScannerRW { void popFront() { _data = _data[_width .. $]; } + + /// + Pixel[] back() { + return _data[($ - _width) .. $]; + } + + /// + void popBack() { + _data = _data[0 .. ($ - _width)]; + } } /++ @@ -994,6 +1024,11 @@ struct SubPixmapScanner { _feed = subPixmap.source.width; } + /// + typeof(this) save() { + return this; + } + /// bool empty() const { return (_data.length == 0); @@ -1013,6 +1048,16 @@ struct SubPixmapScanner { _data = _data[_feed .. $]; } + + /// + const(Pixel)[] back() const { + return _data[($ - _width) .. $]; + } + + /// + void popBack() { + _data = _data[0 .. ($ - _width)]; + } } /++ @@ -1039,6 +1084,11 @@ struct SubPixmapScannerRW { _feed = subPixmap.source.width; } + /// + typeof(this) save() { + return this; + } + /// bool empty() const { return (_data.length == 0); @@ -1058,6 +1108,16 @@ struct SubPixmapScannerRW { _data = _data[_feed .. $]; } + + /// + Pixel[] back() { + return _data[($ - _width) .. $]; + } + + /// + void popBack() { + _data = _data[0 .. ($ - _width)]; + } } ///