sicp-lang / sicp

A SICP language for Racket.
GNU Lesser General Public License v3.0
190 stars 24 forks source link

vector-ref: contract violation for transforming images of certain sizes #14

Closed pmaddams closed 5 years ago

pmaddams commented 7 years ago

Hi Jens,

The following code works as expected until the last line.

#lang sicp

(#%require sicp-pict)

(paint einstein)
(paint (flip-horiz einstein))
(paint (flip-vert einstein))

(define wave (load-painter "wave.gif"))

(paint wave)
(paint (flip-horiz wave))
(paint (flip-vert wave))

At this point it throws the error:

vector-ref: contract violation
expected: vector?
given: 0
argument position: 1st
other arguments...:

The image in question is this one: wave.

Only some transformations cause errors. These include flip-vert, rotate90, and rotate180. Others such as flip-horiz and rotate270 did not fail.

But if you increase the height of the image by one pixel, that is, change the size from 182x182 to 182x183, all of these transformations work as expected.

Based on this information, I tried several other things.

I encourage you to try using the image in question, which is part of the online SICP book, and see for yourself if you get the same error.

soegaard commented 7 years ago

Hi @pmaddams

There is a new implementation of the sicp picture language available:

https://github.com/sicp-lang/sicp/tree/master/sicp-pict2

Download the rkt-file and the image and save them in the same folder. Open the rkt-file in DrRacket and run it. The einstein painter is available as einstein.

Skim though the rkt-file to see the available. For one there are other colors than black and white. Also images are larger.

/Jens Axel

pmaddams commented 7 years ago

Thanks. I already had this package installed on my system from running raco pkg install sicp. To use it, I renamed the file to "main.rkt."

I think there are two reasonable paths forward:

  1. Make sicp-pict2 available by default with (#%require sicp-pict2). Fix the bug in the older package and retain it for backwards compatibility.
  2. Replace the old code with the new code, so that (#%require sicp-pict) uses the new implementation. For backwards compatibility, provide the old interfaces as wrappers around the new ones. For example, (define load-painter bitmap->painter).

Do you have another solution in mind?

Additional comments:

Thanks for your work.

soegaard commented 7 years ago

I think 2. is the way to go. Maybe even expect people to use

#lang racket
(require sicp-pict)

The old code was ported from the original mit-scheme (very old) and was made to run with as few changes as possible. Finding bugs in that code is not fun.

Would you be interested in making the changes? And perhaps find a bigger, higher resolution image?

pmaddams commented 7 years ago

I might be interested in making the necessary changes. However, my previous pull requests were not accepted. I do not want to put the time into understanding and modifying the software, only to eventually find out you want to do it your own way and ignore those changes.

With that in mind, I think it is best if you continue to maintain the software according to your own expectations.

soegaard commented 7 years ago

Hi,

Just checked and found the random and docs pull request. Something must have gone wrong. I was sure I clicked commit+close. I see now that they weren't committed. I'll take a look again.

/Jens Axel

2017-08-10 22:33 GMT+02:00 Pavan Maddamsetti notifications@github.com:

I might be interested in making the necessary changes. However, my previous pull requests were not accepted. I do not want to put the time into understanding and modifying the software, only to eventually find out you want to do it your own way and ignore those changes.

With that in mind, I think it is best if you continue to maintain the software according to your own expectations.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sicp-lang/sicp/issues/14#issuecomment-321665428, or mute the thread https://github.com/notifications/unsubscribe-auth/AAcLxTf3dEvhp_D-hEO_NuI4ZBbD2Cylks5sW2kYgaJpZM4OzcGG .

-- -- Jens Axel Søgaard

soegaard commented 7 years ago

It seems I have hit the wrong button. I can't fix though - Github won't let me reopen the pull request because your repository was deleted.

/Jens Axel

sorawee commented 5 years ago

Hi @pmaddams, I'm sorry that the technical difficulties prevented you from contributing to the repo. In any case, since our current random function is based on yours, I added you as a contributor here.

Regarding the vector-ref: contract violation for transforming images of certain sizes error, because we now use the new sicp-pict collection, I believe the bug is fixed, so I will close this issue. Please feel free to reopen the issue if that's not the case.