# How to do this?

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 feel somehow retarted, as usual, so I hope to hear some wise words of

So, suppose I would want to use the following syntax to command the
little XYZ -points into geometric arrangements of beauty and elegance,
especially the ‘along’ -bit, where starcircle is defined:

#generates a star by combining two triangles
astar = Guide.polygon((Symbol.triangle(99) + Symbol.triangle(99).rotate
(180))

#generates a circle with stars replacing the points on the circumference
n_int = 20
starcircle = Symbol.with_polygon(astar.polygon).along(Symbol.circle
Pic = starcircle.render(“svg”)
#etc

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.

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)

1. 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

I am hoping to achieve as flexible and robust syntax as possible, suited
would think were “wrong”.

1. 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

This doesn’t completely answer your question, but you can define a +
(value) method on any class. You can write any logic you want in it.

E.g.

class TestPlus
def initialize(value=0)
@value = value
end

def +(value)
# replace this with any logic you want. +value+ can be any sort of
object, not just a number
@value += value
puts @value
end
end

x = TestPlus.new(0)
x + 2
=> 2

On 8/13/08, Casimir [email protected] 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:

1. 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

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

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)
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

On 8/13/08, Casimir [email protected] 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:

Thank you Daniel C. and Adam S… I will now build the simple
geometry classes and return here on this topic with some code once I
have implemented the Symbol and Guide classes.

Casimir P.