# PenSize Placement around line

I am drawing some precision vector graphics on a canvas and am attempting to use PenSize to dictate the thickness of various lines. The trouble I have is large number PenSize values distort the end points of the lines. I could adjust the endpoints of my line if I knew the method XOJO uses to thicken lines when PenSize is not equal to 1. Anybody have information on this?

Below is sample code that shows my question. I draw PenSize =1 crosses at the end points, then a line between the two points with a PenSize of 20. The line is not on the end points and the delta seems to vary depending on the slope of the line.

``````Var x1 As Double
Var x2 As Double
Var y1 As Double
Var y2 As Double

g.DrawingColor = Color.TextColor

x1 = g.width  * .1
x2 = g.width * .9
y1 = g.height * .5
y2 = g.height * .9

Var xSize As Double = 30

'draw cross at pts 1 and 2 with pensize of 1
g.PenSize =1
g.DrawLine(x1-xSize/2, y1, x1+ xSize/2, y1)
g.DrawLine(x1, y1-xSize/2, x1, y1 + xSize/2)

g.DrawLine(x2-xSize/2, y2, x2+ xSize/2, y2)
g.DrawLine(x2, y2-xSize/2, x2, y2 + xSize/2)

'draw line with large PenSize
g.PenSize = 20
g.LineCap = graphics.LineCapTypes.Square 'make end of line square
g.DrawLine(x1, y1, x2, y2)``````

/Sigh We’re 12 now can someone remove b u t t from the “swear filter”?

Technically the center of Graphics.LineCapTypes.■■■■ should end on the coordinates of the line.

Looking quickly at the output of the above code and only changing the LineCapType to ■■■■ shows there is a negative Half Pen Size offset required which, without my replicating the code in VS looks like a bug. So you’d need the following code to have ■■■■ land on the correct coordinates.

As for landing a Round or Square in the right place, someone with better maths than mine would need to help there.

``````Var x1 As Double
Var x2 As Double
Var y1 As Double
Var y2 As Double

g.DrawingColor = Color.TextColor

x1 = g.width * .1
x2 = g.width * .9
y1 = g.height * .5
y2 = g.height * .9

Var xSize As Double = 30

'draw cross at pts 1 and 2 with pensize of 1
g.PenSize = 1
g.DrawLine(x1 - xSize / 2, y1, x1 + xSize / 2, y1)
g.DrawLine(x1, y1 - xSize / 2, x1, y1 + xSize / 2)

g.DrawLine(x2 - xSize / 2, y2, x2 + xSize / 2, y2)
g.DrawLine(x2, y2 - xSize / 2, x2, y2 + xSize / 2)

'draw line with large PenSize
g.PenSize = 20
Var halfPenSize As Double = g.PenSize / 2
g.LineCap = Graphics.LineCapTypes.■■■■ 'make end of line square
g.DrawLine(x1 - halfPenSize, y1 - halfPenSize, x2 - halfPenSize, y2 - halfPenSize)
``````

Thanks. That workaround succeeds. And I agree, this seems like a bug.

I was also able to get what I was after with the RectShape class. That seems to work more as I would expect.