GDL
About building parametric objects with GDL.
SOLVED!

Clip Polyline behaviour in multiple cuts

Pertti Paasky
Expert
Hi GS
I found that the GDL ClipPolyline operation returns the right amount of cut polylines, but they are all the same ones. Have I missed something or is it a bug? I certainly wish this operation returned all cut polylines.
-You can move the polyline hotspots and see the results as offset lines compared to the original polyline,

My clip Polyline object
- AC-24 FIN - WIN 10 - HP Zbook -
“A winner is just a loser who tried one more time.”
George M. Moore, Jr.
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Peter Baksa
Graphisoft
Graphisoft
Ok, let's talk about code.

This works in AC24. I didn't code regularization, but the input is as it should be. I tried it with another walkaround and the result was the same, so probably it isn't the cause. Maybe you forgot to increment the index in the result ID array when getting the results?

poChannel = initaddonscope ("PolyOperations", "", "")
preparefunction poChannel, "CreateContainer",         "inputContainer", ""
preparefunction poChannel, "SetSourceContainer",      "inputContainer", ""
preparefunction poChannel, "CreateContainer",         "resultContainer", ""
preparefunction poChannel, "SetDestinationContainer", "resultContainer", ""

dict polygon
polygon.isClosed = 1
polygon.useEdgeInfo = 0


i = 1
polygon.contour.edges.type		= 0	
polygon.contour.edges.begPoint.x	= 0.0
polygon.contour.edges.begPoint.y	= 0.0

i = i + 1
polygon.contour.edges.type		= 0	
polygon.contour.edges.begPoint.x	= 3.0
polygon.contour.edges.begPoint.y	= 0.0

i = i + 1
polygon.contour.edges.type		= 0	
polygon.contour.edges.begPoint.x	= 3.0
polygon.contour.edges.begPoint.y	= 3.0

i = i + 1
polygon.contour.edges.type		= 0	
polygon.contour.edges.begPoint.x	= 0.0
polygon.contour.edges.begPoint.y	= 3.0

i = 1
polygon.holes[1].edges.type		= 0	
polygon.holes[1].edges.begPoint.x	= 1.0
polygon.holes[1].edges.begPoint.y	= 1.0

i = i + 1
polygon.holes[1].edges.type		= 0	
polygon.holes[1].edges.begPoint.x	= 1.0
polygon.holes[1].edges.begPoint.y	= 2.0

i = i + 1
polygon.holes[1].edges.type		= 0	
polygon.holes[1].edges.begPoint.x	= 2.0
polygon.holes[1].edges.begPoint.y	= 2.0

i = i + 1
polygon.holes[1].edges.type		= 0	
polygon.holes[1].edges.begPoint.x	= 2.0
polygon.holes[1].edges.begPoint.y	= 1.0

preparefunction poChannel, "StoreDictPolygon", "polygon", polygon

iPen = 1
gosub "drawPolyOpPolygon"


dict polyline
polyline.isClosed = 0
polyline.useEdgeInfo = 0

i = 1
polyline.contour.edges.type		= 0	
polyline.contour.edges.begPoint.x	= 0.0
polyline.contour.edges.begPoint.y	= -1.0

i = i + 1
polyline.contour.edges.type		= 0	
polyline.contour.edges.begPoint.x	= 2.5
polyline.contour.edges.begPoint.y	= 2.0

i = i + 1
polyline.contour.edges.type		= 0	
polyline.contour.edges.begPoint.x	= 4.0
polyline.contour.edges.begPoint.y	= 1.0

i = i + 1
polyline.contour.edges.type		= 0	
polyline.contour.edges.begPoint.x	= 6.0
polyline.contour.edges.begPoint.y	= 4.0

iPen = 3
dict polygon : polygon = polyline
gosub "drawPolyOpPolygon"

preparefunction poChannel, "StoreDictPolyline", "polyline", polyline

dim resultIDs[]
nResult = CALLFUNCTION (poChannel, "ClipPolyline", "polyline polygon", resultIDs)

add2 0, 0.01
gosub "drawResultPlines"
del 1
closeaddonscope poChannel
 
end

"drawResultPlines":
	for iResult = 1 to nResult
	 
		dict polygon
		nVertices = callfunction(poChannel, "GetDestinationDictPolyline", resultIDs[iResult], polygon)
		iPen = iPen + 1
		gosub "drawPolyOpPolygon"
	 
	next iResult
return
 
"drawPolyOpPolygon":
	! conversion to status-coded polygon 
	dim outflat[]                   ! declare returned array
	polygon.hasClosingPoint = 0     ! always given without repeating the first point 
	call "ProfileConverter" parameters  bProfileToPolyOp 	   = 0,
						bPolyOpDict        = 1,
						PolyOpPolygon      = polygon,
						returned_parameters	nOut,
									outflat
	
	! put results
	for i = 1 to nOut	           ! without closing point
	
		k = (i - 1) * 3
		put	outflat[k + 1],         ! x
			outflat[k + 2],         ! y
			outflat[k + 3] + 1      ! status
	
	next i
	
	! draw polygon
	pen iPen
	poly2_b NSP / 3, 1 + 2,
		iPen, 0,
		get(NSP)
	
return
Péter Baksa
Software Engineer, Library
Graphisoft SE, Budapest

View solution in original post

7 REPLIES 7
Peter Baksa
Graphisoft
Graphisoft
Hi Pertti,

I didn't check your code, but the image shows that the hole walkaround is also counterclockwise.
Correct results are only guaranteed for regular polygons. Regular polygons should have each hole in a clockwise order.
Do you have the same issue when it is reversed?
Best practice is to regularize polygons before any operation if they depend on parameters.
Péter Baksa
Software Engineer, Library
Graphisoft SE, Budapest
Pertti Paasky
Expert
Ok, Peter. I have never noticed this clockwise rule. What I have seen is that the regularization takes place in some example pbjects.
Well, i'll try turning the clocks.
Thanks for the answer.
- AC-24 FIN - WIN 10 - HP Zbook -
“A winner is just a loser who tried one more time.”
George M. Moore, Jr.
Pertti Paasky
Expert
Hi, I just drew the polylines clockwise, but the result is the same.
- AC-24 FIN - WIN 10 - HP Zbook -
“A winner is just a loser who tried one more time.”
George M. Moore, Jr.
Pertti Paasky
Expert
Hi Peter!
You wrote:
"Regular polygons should have each hole in a clockwise order."
Ok, I tried to regularize the polygon with the dict.option output. It gave me only the outline, not the holes. Should it not do that?
As a result, the regularized outlines returned counterclockwise ( the red one) in both directions
I also changed the direction of the hole with no change in results.
So please check this function, or is there something I should knowhave not noticed?
BR Pertti
- AC-24 FIN - WIN 10 - HP Zbook -
“A winner is just a loser who tried one more time.”
George M. Moore, Jr.
Solution
Peter Baksa
Graphisoft
Graphisoft
Ok, let's talk about code.

This works in AC24. I didn't code regularization, but the input is as it should be. I tried it with another walkaround and the result was the same, so probably it isn't the cause. Maybe you forgot to increment the index in the result ID array when getting the results?

poChannel = initaddonscope ("PolyOperations", "", "")
preparefunction poChannel, "CreateContainer",         "inputContainer", ""
preparefunction poChannel, "SetSourceContainer",      "inputContainer", ""
preparefunction poChannel, "CreateContainer",         "resultContainer", ""
preparefunction poChannel, "SetDestinationContainer", "resultContainer", ""

dict polygon
polygon.isClosed = 1
polygon.useEdgeInfo = 0


i = 1
polygon.contour.edges.type		= 0	
polygon.contour.edges.begPoint.x	= 0.0
polygon.contour.edges.begPoint.y	= 0.0

i = i + 1
polygon.contour.edges.type		= 0	
polygon.contour.edges.begPoint.x	= 3.0
polygon.contour.edges.begPoint.y	= 0.0

i = i + 1
polygon.contour.edges.type		= 0	
polygon.contour.edges.begPoint.x	= 3.0
polygon.contour.edges.begPoint.y	= 3.0

i = i + 1
polygon.contour.edges.type		= 0	
polygon.contour.edges.begPoint.x	= 0.0
polygon.contour.edges.begPoint.y	= 3.0

i = 1
polygon.holes[1].edges.type		= 0	
polygon.holes[1].edges.begPoint.x	= 1.0
polygon.holes[1].edges.begPoint.y	= 1.0

i = i + 1
polygon.holes[1].edges.type		= 0	
polygon.holes[1].edges.begPoint.x	= 1.0
polygon.holes[1].edges.begPoint.y	= 2.0

i = i + 1
polygon.holes[1].edges.type		= 0	
polygon.holes[1].edges.begPoint.x	= 2.0
polygon.holes[1].edges.begPoint.y	= 2.0

i = i + 1
polygon.holes[1].edges.type		= 0	
polygon.holes[1].edges.begPoint.x	= 2.0
polygon.holes[1].edges.begPoint.y	= 1.0

preparefunction poChannel, "StoreDictPolygon", "polygon", polygon

iPen = 1
gosub "drawPolyOpPolygon"


dict polyline
polyline.isClosed = 0
polyline.useEdgeInfo = 0

i = 1
polyline.contour.edges.type		= 0	
polyline.contour.edges.begPoint.x	= 0.0
polyline.contour.edges.begPoint.y	= -1.0

i = i + 1
polyline.contour.edges.type		= 0	
polyline.contour.edges.begPoint.x	= 2.5
polyline.contour.edges.begPoint.y	= 2.0

i = i + 1
polyline.contour.edges.type		= 0	
polyline.contour.edges.begPoint.x	= 4.0
polyline.contour.edges.begPoint.y	= 1.0

i = i + 1
polyline.contour.edges.type		= 0	
polyline.contour.edges.begPoint.x	= 6.0
polyline.contour.edges.begPoint.y	= 4.0

iPen = 3
dict polygon : polygon = polyline
gosub "drawPolyOpPolygon"

preparefunction poChannel, "StoreDictPolyline", "polyline", polyline

dim resultIDs[]
nResult = CALLFUNCTION (poChannel, "ClipPolyline", "polyline polygon", resultIDs)

add2 0, 0.01
gosub "drawResultPlines"
del 1
closeaddonscope poChannel
 
end

"drawResultPlines":
	for iResult = 1 to nResult
	 
		dict polygon
		nVertices = callfunction(poChannel, "GetDestinationDictPolyline", resultIDs[iResult], polygon)
		iPen = iPen + 1
		gosub "drawPolyOpPolygon"
	 
	next iResult
return
 
"drawPolyOpPolygon":
	! conversion to status-coded polygon 
	dim outflat[]                   ! declare returned array
	polygon.hasClosingPoint = 0     ! always given without repeating the first point 
	call "ProfileConverter" parameters  bProfileToPolyOp 	   = 0,
						bPolyOpDict        = 1,
						PolyOpPolygon      = polygon,
						returned_parameters	nOut,
									outflat
	
	! put results
	for i = 1 to nOut	           ! without closing point
	
		k = (i - 1) * 3
		put	outflat[k + 1],         ! x
			outflat[k + 2],         ! y
			outflat[k + 3] + 1      ! status
	
	next i
	
	! draw polygon
	pen iPen
	poly2_b NSP / 3, 1 + 2,
		iPen, 0,
		get(NSP)
	
return
Péter Baksa
Software Engineer, Library
Graphisoft SE, Budapest
Pertti Paasky
Expert
Peter, thanks for solving the problem. The index in the result ID array was the reason as You mentioned.
I will carefully study Your code. These operations are not a peace of cake but I hope to master them.
- AC-24 FIN - WIN 10 - HP Zbook -
“A winner is just a loser who tried one more time.”
George M. Moore, Jr.
Pertti Paasky
Expert
I noticed that in Peter´s code there were defined 4 outline points and 4 hole points in the "StoreDictPolygon" -definition while in the older "Store" definition it is supposed to give 5 points, the first and the last are the same.
It seems to work when You add the first point as the last point in the "StoreDictPolygon" -definition as well. Of course it is more convenient not to add the first point.
- AC-24 FIN - WIN 10 - HP Zbook -
“A winner is just a loser who tried one more time.”
George M. Moore, Jr.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!