Skip to content

Commit

Permalink
png/graphics/ellipse: Add class printers
Browse files Browse the repository at this point in the history
* modules/png/graphics/ellipse.scm: Add class printers.
* tests/graphics.scm ("<ellipse>: display"): New test.
  • Loading branch information
artyom-poptsov committed Aug 20, 2023
1 parent 1a84303 commit a70aeb3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions modules/png/graphics/ellipse.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(define-module (png graphics ellipse)
#:use-module (oop goops)
#:use-module (png image)
#:use-module (png core common)
#:use-module (png graphics pixel)
#:use-module (png graphics graphic)
#:use-module (png graphics point)
Expand Down Expand Up @@ -29,6 +30,21 @@
#:init-value 0
#:getter ellipse-height))


(define-method (%display (ellipse <ellipse>) (port <port>))
(format port "#<ellipse center: ~a,~a size: ~ax~a ~a>"
(point-x (ellipse-center ellipse))
(point-y (ellipse-center ellipse))
(ellipse-width ellipse)
(ellipse-height ellipse)
(object-address/hex-string ellipse)))

(define-method (display (ellipse <ellipse>) (port <port>))
(%display ellipse port))

(define-method (write (ellipse <ellipse>) (port <port>))
(%display ellipse port))



(define-method (draw! (image <png-image>) (ellipse <ellipse>))
Expand Down
14 changes: 13 additions & 1 deletion tests/graphics.scm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
#:height 100)))))


;; Rectangle.
;; Multiline.

(test-assert "<multiline>: display"
(with-output-to-string
Expand All @@ -246,6 +246,18 @@
(make <point> #:x 30 #:y 40)
(make <point> #:x 50 #:y 60)))))))


;; Ellipse.

(test-assert "<ellipse>: display"
(with-output-to-string
(lambda ()
(display
(make <ellipse>
#:center (make <point> #:x 10 #:y 20)
#:width 10
#:height 20)))))


(define exit-status (test-runner-fail-count (test-runner-current)))

Expand Down

0 comments on commit a70aeb3

Please sign in to comment.