Difference between revisions of "Render Part C Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 16: Line 16:
  
 
==Transform==
 
==Transform==
{{RubyToEvolve|transform|render/assignment|Transform|Object|Ø|move(direction,amount)<br/>calculate_bounds()|Ø}}
+
{{RubyToEvolve|transform|drawings|Transform|Object|Ø|move(direction,amount)<br/>calculate_bounds()|Ø}}
 
===move===
 
===move===
 
the move method will accept two parameters: direction and amount.
 
the move method will accept two parameters: direction and amount.
Line 42: Line 42:
  
 
==Rectangle==
 
==Rectangle==
{{RubyToEvolve|rectangle|render/assignment|Rectangle|ColorTransform|Ø|calculate_local_bounds|Ø}}
+
{{RubyToEvolve|rectangle|drawings|Rectangle|ColorTransform|Ø|calculate_local_bounds|Ø}}
 
===calculate_local_bounds===
 
===calculate_local_bounds===
 
Returns an instance of Bounds specified by min and max instances of <code>Point2</code>.
 
Returns an instance of Bounds specified by min and max instances of <code>Point2</code>.
Line 50: Line 50:
 
[[File:Rectangle_bounds.png]]
 
[[File:Rectangle_bounds.png]]
 
==Ellipse==
 
==Ellipse==
{{RubyToEvolve|ellipse|render/assignment|Ellipse|ColorTransform|Ø|calculate_local_bounds|Ø}}
+
{{RubyToEvolve|ellipse|drawings|Ellipse|ColorTransform|Ø|calculate_local_bounds|Ø}}
  
 
===calculate_local_bounds===
 
===calculate_local_bounds===
Line 60: Line 60:
  
 
==EquilateralTriangle==
 
==EquilateralTriangle==
{{RubyToEvolve|equilateral_triangle|render/assignment|EquilateralTriangle|ColorTransform|Ø|calculate_local_bounds|Ø}}
+
{{RubyToEvolve|equilateral_triangle|drawings|EquilateralTriangle|ColorTransform|Ø|calculate_local_bounds|Ø}}
  
 
===calculate_local_bounds===
 
===calculate_local_bounds===
Line 70: Line 70:
  
 
==BezierCurve==
 
==BezierCurve==
{{RubyToEvolve|bezier_curve|render/assignment|BezierCurve|ColorTransform|Ø|calculate_local_bounds|Ø}}
+
{{RubyToEvolve|bezier_curve|drawings|BezierCurve|ColorTransform|Ø|calculate_local_bounds|Ø}}
  
 
===calculate_local_bounds===
 
===calculate_local_bounds===
Line 82: Line 82:
  
 
==Text==
 
==Text==
{{RubyToEvolve|text|render/assignment|Text|ColorTransform|Ø|calculate_local_bounds|Ø}}
+
{{RubyToEvolve|text|drawings|Text|ColorTransform|Ø|calculate_local_bounds|Ø}}
  
 
===calculate_local_bounds===
 
===calculate_local_bounds===
Line 94: Line 94:
  
 
==CircularSegment==
 
==CircularSegment==
{{RubyToEvolve|circular_segment|render/assignment|CircularSegment|ColorTransform|Ø|calculate_local_bounds|Ø}}
+
{{RubyToEvolve|circular_segment|drawings|CircularSegment|ColorTransform|Ø|calculate_local_bounds|Ø}}
  
 
===calculate_local_bounds===
 
===calculate_local_bounds===
Line 118: Line 118:
  
 
==CompositeTransform==
 
==CompositeTransform==
{{RubyToEvolve|composite_transform|render/assignment|CompositeTransform|Transform|Ø|calculate_local_bounds|Ø}}
+
{{RubyToEvolve|composite_transform|drawings|CompositeTransform|Transform|Ø|calculate_local_bounds|Ø}}
  
 
===calculate_local_bounds===
 
===calculate_local_bounds===
Line 128: Line 128:
  
 
==Scene==
 
==Scene==
{{RubyToEvolve|scene|render/assignment|Scene|Object|calculate_bounds()|Ø|Ø}}
+
{{RubyToEvolve|scene|drawings|Scene|Object|calculate_bounds()|Ø|Ø}}
 
===calculate_bounds===
 
===calculate_bounds===
 
NOTE: this method must be public.
 
NOTE: this method must be public.
Line 135: Line 135:
  
 
==ConvexPolygon==
 
==ConvexPolygon==
{{RubyToImplement|convex_polygon|render/assignment|ConvexPolygon|ColorTransform|initialize(points, x: 0, y: 0, color: nil)<br/>render_transformed()<br/>calculate_local_bounds()}}
+
{{RubyToImplement|convex_polygon|drawings|ConvexPolygon|ColorTransform|initialize(points, x: 0, y: 0, color: nil)<br/>render_transformed()<br/>calculate_local_bounds()}}
  
 
'''Note: You will need to add this file.  Starter code:'''
 
'''Note: You will need to add this file.  Starter code:'''
Line 177: Line 177:
 
[[File:Convex polygon bounds.png]]
 
[[File:Convex polygon bounds.png]]
  
{{RubyToRun|convex_polygon|render/assignment|main}}
+
{{RubyToRun|convex_polygon|drawings|main}}
  
 
[[File:Render convex polygon.png]]
 
[[File:Render convex polygon.png]]
Line 183: Line 183:
 
=Testing Your Solution=
 
=Testing Your Solution=
 
==Unit Test==
 
==Unit Test==
===Complete===
 
{{RubyUnitTest|part_c_test_suite|render/part_c}}
 
 
===Bare Bones===
 
===Bare Bones===
{{RubyUnitTest|part_c_bare_bones_test_suite|render/part_c_bare_bones}}
+
{{RubyUnitTest|<br/>|drawings/preliminary/part_c}}
 +
 
 +
{{RubyUnitTest|<br/>|drawings/more_comprehensive/part_c}}
  
 
==Visual Comparison==
 
==Visual Comparison==
{{RubyToRun|part_c_snapshots_web_page_generator|render/part_c_snapshots|test}}
+
{{RubyToRun|part_c_snapshots_web_page_generator|drawings_snapshots|main}}
  
 
==Somewhat Outdated Testing Demo==
 
==Somewhat Outdated Testing Demo==
 
<youtube>utK0TewIRjc</youtube>
 
<youtube>utK0TewIRjc</youtube>

Revision as of 01:14, 14 November 2022

In this studio we will evolve our code from Render_Part_B_Assignment to add new methods and a new class.

Render part c class hierarchy.svg

Continue editing files in the render/assignment directory.

Code to Implement

Bounds

file: src/main/ruby/drawings/bounding_box.rb Ruby logo.svg
class: BoundingBox
superclass: Object
methods: initialize(min,max)
min()
min=(min)
max()
max=(max)

Note: be sure to require_relative 'point2'.

Note: min and max should be instances of Point2.

Note: You may wish to use Ruby's convenient Struct construct.

Transform

file: src/main/ruby/drawings/transform.rb Ruby logo.svg
class: Transform
superclass: Object
methods to evolve: Ø
methods to add: move(direction,amount)
calculate_bounds()
methods to remove: Ø

move

the move method will accept two parameters: direction and amount.

direction can be one of four symbols

:left
:right
:up
:down
left corresponds to translating along the negative x axis
right corresponds to translating along the positive x axis
down corresponds to translating along the negative y axis
up corresponds to translating along the positive y axis

any other value for direction should raise an ArgumentError.

calculate_bounds

invoke calculate_local_bounds and transform the returned bounds by x and y.

NOTE: calculate_local_bounds is abstract. it must be defined by the subclasses.

Rectangle

file: src/main/ruby/drawings/rectangle.rb Ruby logo.svg
class: Rectangle
superclass: ColorTransform
methods to evolve: Ø
methods to add: calculate_local_bounds
methods to remove: Ø

calculate_local_bounds

Returns an instance of Bounds specified by min and max instances of Point2.

NOTE: this method must be private.

Rectangle bounds.png

Ellipse

file: src/main/ruby/drawings/ellipse.rb Ruby logo.svg
class: Ellipse
superclass: ColorTransform
methods to evolve: Ø
methods to add: calculate_local_bounds
methods to remove: Ø

calculate_local_bounds

Returns an instance of Bounds specified by min and max instances of Point2.

NOTE: this method must be private.

Ellipse bounds.png

EquilateralTriangle

file: src/main/ruby/drawings/equilateral_triangle.rb Ruby logo.svg
class: EquilateralTriangle
superclass: ColorTransform
methods to evolve: Ø
methods to add: calculate_local_bounds
methods to remove: Ø

calculate_local_bounds

Returns an instance of Bounds specified by min and max instances of Point2.

NOTE: this method must be private.

Equilateral triangle bounds.png

BezierCurve

file: src/main/ruby/drawings/bezier_curve.rb Ruby logo.svg
class: BezierCurve
superclass: ColorTransform
methods to evolve: Ø
methods to add: calculate_local_bounds
methods to remove: Ø

calculate_local_bounds

Contemplate for a moment how you would build this method and then raise an error and move on.

NOTE: this method must be private.

  def calculate_local_bounds
    raise StandardError.new("not yet implemented")
  end

Text

file: src/main/ruby/drawings/text.rb Ruby logo.svg
class: Text
superclass: ColorTransform
methods to evolve: Ø
methods to add: calculate_local_bounds
methods to remove: Ø

calculate_local_bounds

Contemplate for a moment how you would build this method and then raise an error and move on.

NOTE: this method must be private.

  def calculate_local_bounds
    raise StandardError.new("not yet implemented")
  end

CircularSegment

file: src/main/ruby/drawings/circular_segment.rb Ruby logo.svg
class: CircularSegment
superclass: ColorTransform
methods to evolve: Ø
methods to add: calculate_local_bounds
methods to remove: Ø

calculate_local_bounds

Contemplate for a moment how you would build this method and then raise an error and move on.

NOTE: this method must be private.

  def calculate_local_bounds
    raise StandardError.new("not yet implemented")
  end

Image

file: src/main/ruby/render/assignment/image.rb Ruby logo.svg
class: Image
superclass: Transform
methods to evolve: Ø
methods to add: calculate_local_bounds
methods to remove: Ø

calculate_local_bounds

Contemplate for a moment how you would build this method and then raise an error and move on.

NOTE: this method must be private.

  def calculate_local_bounds
    raise StandardError.new("not yet implemented")
  end

CompositeTransform

file: src/main/ruby/drawings/composite_transform.rb Ruby logo.svg
class: CompositeTransform
superclass: Transform
methods to evolve: Ø
methods to add: calculate_local_bounds
methods to remove: Ø

calculate_local_bounds

Returns an instance of Bounds specified by min and max instances of Point2.

NOTE: this method must be private.

Composite transform bounds.png

Scene

file: src/main/ruby/drawings/scene.rb Ruby logo.svg
class: Scene
superclass: Object
methods to evolve: calculate_bounds()
methods to add: Ø
methods to remove: Ø

calculate_bounds

NOTE: this method must be public.

Scene bounds.png

ConvexPolygon

file: src/main/ruby/drawings/convex_polygon.rb Ruby logo.svg
class: ConvexPolygon
superclass: ColorTransform
methods: initialize(points, x: 0, y: 0, color: nil)
render_transformed()
calculate_local_bounds()

Note: You will need to add this file. Starter code:

require_relative 'color_transform'
require_relative 'point2'

class ConvexPolygon < ColorTransform

end

if __FILE__ == $0
  require_relative '../core/render_app'
  points = [
      Point2.new(0.85, 0.0),
      Point2.new(0.1, 0.25),
      Point2.new(0.0, 0.45),
      Point2.new(0.15, 0.7),
      Point2.new(0.65, 1.0),
      Point2.new(0.95, 0.95),
      Point2.new(1.1, 0.75)
  ]
  
  app = RenderApp.new(ConvexPolygon.new(points, x: -0.5, y: -0.5, color: Color.new(1, 0, 0)))
  app.main_loop
end

initialize

Accept a required parameter points which is an array of Point2s.

Accept keyword parameters for x: 0, y: 0, and color: nil to the constructor and pass them to the superclass.

NOTE: Be sure to not override render. Implement the render_transformed method instead.

render_transformed

NOTE: this method must be private.

calculate_local_bounds

NOTE: this method must be private.

Convex polygon bounds.png

file to run: src/main/ruby/drawings/convex_polygon.rb Ruby logo.svg

Render convex polygon.png

Testing Your Solution

Unit Test

Bare Bones

file: src/test/ruby/drawings/preliminary/part_c/
.rb
Ruby logo.svg UnitTest

note: ensure that you have removed all printing to receive credit for any assignment.

file: src/test/ruby/drawings/more_comprehensive/part_c/
.rb
Ruby logo.svg UnitTest

note: ensure that you have removed all printing to receive credit for any assignment.

Visual Comparison

file to run: src/main/ruby/drawings_snapshots/part_c_snapshots_web_page_generator.rb Ruby logo.svg

Somewhat Outdated Testing Demo