Difference between revisions of "Render Part D Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 6: Line 6:
  
 
=Background=
 
=Background=
Investigate [https://www.tutorialspoint.com/ruby/ruby_modules.htm Ruby Modules], specifically the <code>module</code> and <code>include</code> keywords.
+
Investigate [https://ruby-doc.org/core-2.5.0/Module.html Ruby Modules], specifically the <code>module</code> and <code>include</code> keywords.
  
 
=Warning=
 
=Warning=

Revision as of 21:18, 8 December 2022

In this studio we will evolve our code from Render_Part_C_Assignment to leverage mixins.

Diagram part d.png

Continue editing files in the render/assignment directory.

Background

Investigate Ruby Modules, specifically the module and include keywords.

Warning

caption

Do NOT use the include keyword in Ruby as you would typically in C or C++.
Be sure to include within the intended class or module definition.
If you include at the top-level, it will mixin to Object!
This may or may not rip a hole in the universe.

Code to Implement

Composite

file: src/main/ruby/drawings/composite.rb Ruby logo.svg
module: Composite
methods: initialize_components()
push_component(component)
each_component()
untransformed_bounds()

module Composite should define methods initialize_components, push_component, each_component, and untransformed_bounds as well as mixin the Enumerable module.

initialize_components

add an instance variable with a suitable name to store an array of components

NOTE: initialize_components() must be private.

push_component

push a component onto your array instance variable.

each_component

if a block is given, yield for each component in your array instance variable.

otherwise use to_enum to return a new Enumerator of the components.

Note: be sure to invoke to_enum with the symbol of the method :each_component and not invoke the method by mistake.

untransformed_bounds

Similar to the untransformed bounds calculations on CompositeTransform and Scene from Part C.

Mixin Enumerable

to add a number of useful methods, include the Enumerable module and

Alias each

use alias_method to alias an :each method to the :each_component method.

CompositeTransform

Be sure to add:

require_relative 'composite' Ruby logo.svg

Mixin your Composite module to the CompositeTransform class.

include Composite

Be sure to invoke initialize_components from the constructor and clean up existing code. For example bounds calculation can now use map.

Scene

Be sure to add:

require_relative 'composite' Ruby logo.svg

Mixin your Composite module to the Scene class.

include Composite

Be sure to invoke initialize_components from the constructor and clean up existing code. For example bounds calculation can now use map.

Testing Your Solution

Unit Test

Part D

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

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

Backwards Compatibility

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/preliminary/part_b/*.rb Ruby logo.svg UnitTest

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

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

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

Somewhat Outdated Testing Demo