feat: add line and arrow annotations
This commit is contained in:
@@ -75,6 +75,10 @@ func ApplyAnnotationsWithScale(pngBytes []byte, annotations []Annotation, scaleX
|
||||
switch ann.Tool {
|
||||
case "pen":
|
||||
drawPolyline(dst, ann.Points, scaleX, scaleY, width, c)
|
||||
case "line":
|
||||
drawStraightLine(dst, ann.Points, scaleX, scaleY, width, c)
|
||||
case "arrow":
|
||||
drawArrow(dst, ann.Points, scaleX, scaleY, width, c)
|
||||
case "rect":
|
||||
drawRectOutline(dst, ann.Points, scaleX, scaleY, width, c)
|
||||
case "ellipse":
|
||||
@@ -95,6 +99,34 @@ func ApplyAnnotationsWithScale(pngBytes []byte, annotations []Annotation, scaleX
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func drawStraightLine(img *image.RGBA, points []Point, scaleX, scaleY float64, width int, c color.RGBA) {
|
||||
if len(points) < 2 {
|
||||
return
|
||||
}
|
||||
drawLine(img, scalePoint(points[0], scaleX, scaleY), scalePoint(points[len(points)-1], scaleX, scaleY), width, c)
|
||||
}
|
||||
|
||||
func drawArrow(img *image.RGBA, points []Point, scaleX, scaleY float64, width int, c color.RGBA) {
|
||||
if len(points) < 2 {
|
||||
return
|
||||
}
|
||||
start := scalePoint(points[0], scaleX, scaleY)
|
||||
end := scalePoint(points[len(points)-1], scaleX, scaleY)
|
||||
dx, dy := end.X-start.X, end.Y-start.Y
|
||||
length := math.Hypot(dx, dy)
|
||||
if length < 1 {
|
||||
return
|
||||
}
|
||||
drawLine(img, start, end, width, c)
|
||||
headLength := math.Min(length*0.45, math.Max(10*math.Max(scaleX, scaleY), float64(width)*4))
|
||||
angle := math.Atan2(dy, dx)
|
||||
spread := math.Pi / 6
|
||||
left := Point{X: end.X - headLength*math.Cos(angle-spread), Y: end.Y - headLength*math.Sin(angle-spread)}
|
||||
right := Point{X: end.X - headLength*math.Cos(angle+spread), Y: end.Y - headLength*math.Sin(angle+spread)}
|
||||
drawLine(img, end, left, width, c)
|
||||
drawLine(img, end, right, width, c)
|
||||
}
|
||||
|
||||
const mosaicBlockSize = 10
|
||||
|
||||
func applyMosaicBrush(img *image.RGBA, points []Point, scaleX, scaleY float64, width int) {
|
||||
|
||||
Reference in New Issue
Block a user