Skip to content

Commit

Permalink
png/graphics/filled-rectangle: Add class printers
Browse files Browse the repository at this point in the history
* modules/png/graphics/filled-rectangle.scm: Add class printers.
* tests/graphics.scm ("<filled-rectangle>: display"): New test.
  • Loading branch information
artyom-poptsov committed Aug 20, 2023
1 parent 5e1422e commit bb72caf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion modules/png/graphics/filled-rectangle.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; filled-rectangle.scm -- Filled rectangle implementation.

;; Copyright (C) 2022 Artyom V. Poptsov <[email protected]>
;; Copyright (C) 2022-2023 Artyom V. Poptsov <[email protected]>
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -26,6 +26,7 @@
(define-module (png graphics filled-rectangle)
#:use-module (oop goops)
#:use-module (png image)
#:use-module (png core common)
#:use-module (png graphics graphic)
#:use-module (png graphics pixel)
#:use-module (png graphics point)
Expand All @@ -42,6 +43,20 @@
(define filled-rectangle-height rectangle-height)
(define filled-rectangle-width rectangle-width)


(define-method (%display (filled-rectangle <filled-rectangle>) (port <port>))
(format port "#<filled-rectangle position: ~a width: ~a height: ~a ~a>"
(filled-rectangle-position filled-rectangle)
(filled-rectangle-width filled-rectangle)
(filled-rectangle-height filled-rectangle)
(object-address/hex-string filled-rectangle)))

(define-method (display (filled-rectangle <filled-rectangle>) (port <port>))
(%display filled-rectangle port))

(define-method (write (filled-rectangle <filled-rectangle>) (port <port>))
(%display filled-rectangle port))


(define-method (draw! (image <png-image>) (rectangle <filled-rectangle>))
(let* ((position (rectangle-position rectangle))
Expand Down
12 changes: 12 additions & 0 deletions tests/graphics.scm
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@
#:width 50
#:height 100)))))


;; Filled rectangle.

(test-assert "<filled-rectangle>: display"
(with-output-to-string
(lambda ()
(display
(make <filled-rectangle>
#:position (make <point> #:x 100 #:y 200)
#:width 50
#:height 100)))))


;; Multiline.

Expand Down

0 comments on commit bb72caf

Please sign in to comment.