From: Adam Shelly Date: 2008-08-14T03:34:37+09:00 Subject: Re: How to do this? On 8/13/08, Casimir wrote: > Dear sirs, > > I am planning a simple geometry generation library. XYZ points, primitive > geometry such as triangles and guides that can generate more geometry. I'll offer my opinions in reverse order: > 2. How to achieve the '+' operation for symbols? For example symbol4 + > somesymbol would join the geometry of the latter into the former. Or > perhaps return a new symbol with combined geometry. How is that handled > for adding number-objects? > Most (maybe even all) built-in + operators return a new object, so I'd do the same for your Symbols. Assuming a Symbol is just a collection of primitives (lines and points), then it should probably be something like: class Symbol def initialize prims=[] @primitives = prims end def + other Symbol.new(@primitives +other.primitives ) end end > So, suppose I would want to use the following syntax ... > > starcircle = Symbol.with_polygon(astar.polygon).along(Symbol.circle (n_int, radius_int))) > > 1. How would one manage the generation of starcircle? Store the star > ("astar") passed as argument in with_polygon in a Guide-instance and > refer to it once "along"-method is called. That could work, but is awkward. What happens if you call #along without #with first? What if you call #with twice? > Am I doing this wrong? Is this just artistic nonsens? Should it read, in > a boring CS major style: > starcircle = Symbol.generate_with_guide(astar, Symbol.circle) How about a more ruby style: tri =Symbol.triangle(side) astar = tri + tri.rotate(180) circle = Symbol.circle(pts,radius) starcircle = circle.map_points{|point| astar.at(point).primitives } where Symbol#at creates a new instance of itself centered on point, and Symbol#map_points creates a new symbol based on the block results: def map_points &block new_primitives = [] @points.each{|pt| new_primitives<< block.call(pt)} Symbol.new(newpoints) end -Adam