On Wed, 5 Dec 2018 at 00:45, Roelof Wobben <r.wob...@home.nl> wrote: > so like this ? > > so first the intersect between rectangle1 and rectangle2 > store it > and then the intersection between the stored one and rectangle3 > and so on > then its time to look how I must define a rectangle when I know the > starting point and the length and width > > then it time to figure out how I can define a Rectangle with the starting > point the length and the width >
Use Spotter to bring up the System Browser on the Rectangle class. Then right-click >> Class-refs to look at how the class is used directly to create new instances. cheers -ben > > Roelof > > > > Op 4-12-2018 om 17:27 schreef p...@highoctane.be: > > Use Rectangle class and intersect: method? > > > > > On Tue, Dec 4, 2018 at 5:07 PM Roelof Wobben <r.wob...@home.nl> wrote: > >> Hello, >> >> For adventofCode I had to write some code that calculates the overlap >> that multiple rectangles have. >> >> Fo far I have it working for 1 rectangle but I do not like the code >> because of the nested loops. >> >> Can I make this more the pharo way >> >> Code so far : >> >> | item coordinates area overlap regexp line beginX endX beginY endY| >> area := OrderedCollection new. >> overlap := OrderedCollection new. >> regexp := '\#(\d+) @ (\d+),(\d+)\: (\d+)x(\d+)' asRegex. >> line := '#1 @ 1,3: 4x4'. >> (regexp matches: line) >> ifTrue: [ >> beginX := (regexp subexpression: 2) asInteger + 1. >> endX := (regexp subexpression: 5) asInteger + beginX . >> beginY := (regexp subexpression: 4) asInteger + 1. >> endY := (regexp subexpression: 6) asInteger + beginY. >> beginX to: (endX - 1) do: [:a | >> beginY to: (endY -1) do: [:b | >> item := a asString , '*' , b asString . >> (area includes: item) >> ifTrue: [ overlap add: item ] >> ifFalse: [ area add: item ]]]] . >> ^ area. >> >> Thanks, >> >> Roelof >> >> >> >