Sudha247 / ocaml-joy

MIT License
22 stars 14 forks source link

Rotate transformation for lines #48

Closed nikochiko closed 7 months ago

nikochiko commented 1 year ago

Rotation was added in this PR - https://github.com/Sudha247/ocaml-joy/pull/39

But, not for lines.

I think the same method that worked with other shapes should work for lines too.

As part of this issue, also come up with a couple of tests and make sure that the transformation works correctly.

joanita-51 commented 1 year ago

@nikochiko , can i work on this issue?

nikochiko commented 1 year ago

@joanita-51 sure!

joanita-51 commented 1 year ago

Hello, @nikochiko, I'm inquiring about how to check if the transformation works correctly. I have modified the shape.ml file and the test_scale_shape.ml file. However when I run the command dune exec -- test/test_all.exe I always get the same output as the one shown below. Is there a different way I'm supposed to work on the issue? image

nikochiko commented 1 year ago

This is intentional -- on the terminal, you are supposed to hit enter, and then that would move to the next shape.

Ideally, this would happen automatically after showing each "test" shape for a short period of time (say, a couple of seconds). But then, for our normal executions we want the shapes to show until we hit enter in the terminal or close the box.

I'm not sure how we can allow both in different environments though. Maybe there is an elegant way to do it with effect handlers, but I haven't used them enough before to know definitively.

joanita-51 commented 12 months ago

This is intentional -- on the terminal, you are supposed to hit enter, and then that would move to the next shape.

Ideally, this would happen automatically after showing each "test" shape for a short period of time (say, a couple of seconds). But then, for our normal executions we want the shapes to show until we hit enter in the terminal or close the box.

I'm not sure how we can allow both in different environments though. Maybe there is an elegant way to do it with effect handlers, but I haven't used them enough before to know definitively.

Thanks, @nikochiko I followed your advice and managed to view the next shape. However, I'm still unable to see the line. when i run the command .

This is the code modified in the file shape.ml

let rotate degrees shape =
  match shape with
  | Circle circle -> Circle { c = rot circle.c degrees; radius = circle.radius }
  | Rectangle rectangle ->
      Rectangle
        {
          c = rot rectangle.c degrees;
          length = rectangle.length;
          width = rectangle.width;
        }
  | Ellipse ellipse ->
      Ellipse { c = rot ellipse.c degrees; rx = ellipse.rx; ry = ellipse.ry }
  | Line line -> 
      Line { a= rot line.a degrees; b = rot line.b degrees }

and in the file test_scale_shape.ml

open Joy.Shape

let run () =
  init ();
  let c1 = circle 50 in
  let c2 = scale 2. c1 in
  let c3 = scale 0.5 c1 in
  let r1 = rectangle 100 100 |> translate 10 500 in
  let r2 = scale 2. r1 in
  let r3 = scale 0.02 r1 in
  let e1 = ellipse 30 50 |> translate 500 500 in
  let e2 = scale 2. e1 in
  let e3 = scale 0.7 e1 in
  let line1 = line 100 100 in
  let rotatedLine = rotate 45 line1 in
  show [ c1; c2; c3; r1; r2; r3; e1; e2; e3; rotatedLine ];