fix: allow arrow to draw full circle

This commit is contained in:
efim 2023-11-22 05:39:50 +00:00
parent 077537a1e3
commit f4c331983c
1 changed files with 18 additions and 12 deletions

View File

@ -93,7 +93,12 @@ func (r *roomTableData)ArrowData() arrowData {
} }
radius := 50.0 radius := 50.0
startAngle := 90 + float64(startSector) * ( 360.0 / float64(total) ) startAngle := 90 + float64(startSector) * ( 360.0 / float64(total) )
endAngle := 90 + float64(endSector) * ( 360.0 / float64(total) ) endAngle := 90 + float64(endSector) * ( 360.0 / float64(total) )
// if need to draw full circle
if startSector == endSector {
startAngle += 3 // a bit forward
endAngle += 357 // ~ a bit backward (almost full circle forward)
}
startAngleRad := startAngle * (math.Pi / float64(180)) startAngleRad := startAngle * (math.Pi / float64(180))
endAngleRad := endAngle * (math.Pi / float64(180)) endAngleRad := endAngle * (math.Pi / float64(180))
// endAngle is radius angle, so perpendicular gives direction of teh arrow // endAngle is radius angle, so perpendicular gives direction of teh arrow
@ -106,16 +111,17 @@ func (r *roomTableData)ArrowData() arrowData {
arrowAngleOffset := math.Pi / 4 // 45 degrees arrowAngleOffset := math.Pi / 4 // 45 degrees
arrowPointDirection := endAngleRad - math.Pi / 2 arrowPointDirection := endAngleRad - math.Pi / 2
arrowheadLen := 10.0 arrowheadLen := 10.0
line1Angle := arrowPointDirection - arrowAngleOffset arrowMinusAngle := arrowPointDirection - arrowAngleOffset
line2Angle := arrowPointDirection + arrowAngleOffset arrowPlusAngle := arrowPointDirection + arrowAngleOffset
line1EndX := x2 + arrowheadLen * math.Cos(line1Angle) arrowMinusEndX := x2 + arrowheadLen * math.Cos(arrowMinusAngle)
line1EndY := y2 + arrowheadLen * math.Sin(line1Angle) arrowMinusEndY := y2 + arrowheadLen * math.Sin(arrowMinusAngle)
line2EndX := x2 + arrowheadLen * math.Cos(line2Angle) arrowPlusEndX := x2 + arrowheadLen * math.Cos(arrowPlusAngle)
line2EndY := y2 + arrowheadLen * math.Sin(line2Angle) arrowPlusEndY := y2 + arrowheadLen * math.Sin(arrowPlusAngle)
// indicates that the shorter of the two possible arcs should be used. // indicates that the shorter of the two possible arcs should be used.
largeArcFlag := 0 largeArcFlag := 0
if math.Abs(float64(endSector) - float64(startSector)) > float64(total)/2.0 { //
if endAngleRad - startAngleRad > (math.Pi) {
// specifies that the longer arc should be chosen. // specifies that the longer arc should be chosen.
largeArcFlag = 1 largeArcFlag = 1
} }
@ -129,10 +135,10 @@ func (r *roomTableData)ArrowData() arrowData {
EndX: int(x2), EndX: int(x2),
EndY: int(y2), EndY: int(y2),
LargeArcFlag: largeArcFlag, LargeArcFlag: largeArcFlag,
Angle1X: int(line1EndX), Angle1X: int(arrowMinusEndX),
Angle1Y: int(line1EndY), Angle1Y: int(arrowMinusEndY),
Angle2X: int(line2EndX), Angle2X: int(arrowPlusEndX),
Angle2Y: int(line2EndY), Angle2Y: int(arrowPlusEndY),
} }
} }