Lots of documents from my clients have negative SubPath lengths, causing all sorts of trouble. Seems the problem can quite easily be reproduced (see below).
Any ideas around this? Known bug? Any fix?
[TestMethod] public void SubPath_length_becomes_negative() { Module.CorelApp.ActiveDocument.Unit = Corel.Interop.VGCore.cdrUnit.cdrInch; var c1 = Module.CorelApp.ActiveDocument.CreateCurve(); var sp1 = c1.CreateSubPath(0, 0); sp1.AppendLineSegment(10000, 0); // This fails. Length is not 10000 but -8454.6600314960633. sp1.Length.Should().Be(10000); }
I can not really follow your problem:
Your'e complaining about something in a customer document and demonstrate it with a strange 'Example':
You are creating in a (I assume normal sized) document where you set the unit to Inch a line which is more than 800 times longer than the normal document width. I don't wonder, if this fails.
Have you ever tried to get the length of the curve in question in the unit stored with the document?
Sorry if I'm unclear. True, my test case draws a single long line outside the document boundaries. But the same problem occurs if I create I long line consisting of multiple SubPaths within the document boundaries. It is the length of the line that's the problem, not whether or not it crosses the document boundaries.
I attach a real world example from my client. It's a single line curled up like this (showing only the lower left part of the document):
Corel reports line info correctly:
But the API gets the length wrong, both on Curve and SubPath level. (Though, summing up the individual Segment lengths produces correct length 88 375 inches is 2 244 750mm)
Or the same (more or less) view from VBA if you're more familiar there:
Couldn't attach the file to my last post, but here it is:
https://we.tl/t-A8Aa2TLY8w
Fredrik,
I enjoyed figuring this one out. :-) It's a bug as you can tell.
It is breaking if the curve length is greater than 2147483647 micrometers or as CorelDRAW refers to them cdrTenthMicron.
If you convert 2147483648 micrometers to inches you get 84546.600314961 inches which is the number you are seeing.The number goes negative because it knows something is wrong. :-)
Now, why would it break at that number, because 2147483647 is the max value you can have for an Integer and if you go over it, things go wrong.
You have found a good workaround to total the value yourself. I was not able to come up with anything better.
-Shelby
Welcome, API 18, Point interface limit - CorelDRAW and Corel DESIGNER API - Developer Area - CorelDRAW Community