Difference between revisions of "Render Part C Assignment"
Line 71: | Line 71: | ||
===calculate_local_bounds=== | ===calculate_local_bounds=== | ||
+ | Contemplate for a moment how you would build this method and then <code>raise :not_yet_implemented</code> and move on. | ||
+ | |||
NOTE: this method must be private. | NOTE: this method must be private. | ||
Line 81: | Line 83: | ||
===calculate_local_bounds=== | ===calculate_local_bounds=== | ||
+ | Contemplate for a moment how you would build this method and then <code>raise :not_yet_implemented</code> and move on. | ||
+ | |||
NOTE: this method must be private. | NOTE: this method must be private. | ||
Line 91: | Line 95: | ||
===calculate_local_bounds=== | ===calculate_local_bounds=== | ||
+ | Contemplate for a moment how you would build this method and then <code>raise :not_yet_implemented</code> and move on. | ||
+ | |||
NOTE: this method must be private. | NOTE: this method must be private. | ||
Line 101: | Line 107: | ||
===calculate_local_bounds=== | ===calculate_local_bounds=== | ||
+ | Contemplate for a moment how you would build this method and then <code>raise :not_yet_implemented</code> and move on. | ||
+ | |||
NOTE: this method must be private. | NOTE: this method must be private. | ||
Line 118: | Line 126: | ||
==Scene== | ==Scene== | ||
+ | {{RubyToEvolve|scene|render/assignment|Scene|Object|calculate_bounds()|Ø|Ø}} | ||
===calculate_bounds=== | ===calculate_bounds=== | ||
+ | NOTE: this method must be public. | ||
+ | |||
+ | [[File:Scene bounds.png]] | ||
==ConvexPolygon== | ==ConvexPolygon== | ||
+ | {{RubyToImplement|convex_polygon|render/assignment|ConvexPolygon|ColorTransform|initialize(points, x: 0, y: 0, color: nil)<br/>render_transformed()<br/>calculate_local_bounds()}} | ||
+ | |||
+ | ===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. | ||
+ | |||
+ | NOTE: render_transformed() must be private. | ||
+ | |||
===render_transformed=== | ===render_transformed=== | ||
+ | NOTE: this method must be private. | ||
+ | |||
===calculate_local_bounds=== | ===calculate_local_bounds=== | ||
+ | NOTE: this method must be private. | ||
=Testing Your Solution= | =Testing Your Solution= |
Revision as of 20:52, 2 December 2020
In this studio we will evolve our code from Render_Part_B_Assignment to add new methods and a new class.
Continue editing files in the render/assignment directory.
Contents
Code to Implement
Bounds
file: | src/main/ruby/render/assignment/bounds.rb | |
class: | Bounds | |
superclass: | Object | |
methods: | ' |
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/render/assignment/transform.rb | |
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/render/assignment/rectangle.rb | |
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.
Ellipse
file: | src/main/ruby/render/assignment/ellipse.rb | |
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.
EquilateralTriangle
file: | src/main/ruby/render/assignment/equilateral_triangle.rb | |
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.
BezierCurve
file: | src/main/ruby/render/assignment/bezier_curve.rb | |
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 :not_yet_implemented
and move on.
NOTE: this method must be private.
def calculate_local_bounds raise :not_yet_implemented end
Text
file: | src/main/ruby/render/assignment/text.rb | |
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 :not_yet_implemented
and move on.
NOTE: this method must be private.
def calculate_local_bounds raise :not_yet_implemented end
Chord
file: | src/main/ruby/render/assignment/chord.rb | |
class: | Chord | |
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 :not_yet_implemented
and move on.
NOTE: this method must be private.
def calculate_local_bounds raise :not_yet_implemented end
Image
file: | src/main/ruby/render/assignment/image.rb | |
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 :not_yet_implemented
and move on.
NOTE: this method must be private.
def calculate_local_bounds raise :not_yet_implemented end
CompositeTransform
file: | src/main/ruby/render/assignment/composite_transform.rb | |
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.
Scene
file: | src/main/ruby/render/assignment/scene.rb | |
class: | Scene | |
superclass: | Object | |
methods to evolve: | calculate_bounds() | |
methods to add: | Ø | |
methods to remove: | Ø |
calculate_bounds
NOTE: this method must be public.
ConvexPolygon
file: | src/main/ruby/render/assignment/convex_polygon.rb | |
class: | ConvexPolygon | |
superclass: | ColorTransform | |
methods: | initialize(points, x: 0, y: 0, color: nil) render_transformed() calculate_local_bounds() |
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.
NOTE: render_transformed() must be private.
render_transformed
NOTE: this method must be private.
calculate_local_bounds
NOTE: this method must be private.
Testing Your Solution
Visual Comparison
file to run: | src/test/ruby/render/part_c/part_c_test_snapshots_web_page_generator.rb |
Unit Test
file: | src/test/ruby/render/part_c/part_c_unit_test.rb | UnitTest |
note: ensure that you have removed all printing to receive credit for any assignment.
file: | src/test/ruby/render/part_c/part_c_move_unit_test.rb | UnitTest |
note: ensure that you have removed all printing to receive credit for any assignment.
file: | src/test/ruby/render/part_c/part_c_bounds_unit_test.rb | UnitTest |
note: ensure that you have removed all printing to receive credit for any assignment.