2011-05-19 21:54:22 +00:00
|
|
|
// Copyright 2010 The draw2d Authors. All rights reserved.
|
|
|
|
// created: 21/11/2010 by Laurent Le Goff
|
2015-04-22 17:07:03 +00:00
|
|
|
|
2015-01-07 14:35:09 +00:00
|
|
|
package curve
|
2011-05-19 21:54:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
2015-04-29 08:28:05 +00:00
|
|
|
|
|
|
|
"code.google.com/p/freetype-go/freetype/raster"
|
2011-05-19 21:54:22 +00:00
|
|
|
)
|
|
|
|
|
2015-04-23 13:36:56 +00:00
|
|
|
// TraceArc trace an arc using a LineBuilder
|
2015-04-29 08:28:05 +00:00
|
|
|
func TraceArc(t LineBuilder, x, y, rx, ry, start, angle, scale float64) (lastX, lastY float64) {
|
2011-05-19 21:54:22 +00:00
|
|
|
end := start + angle
|
|
|
|
clockWise := true
|
|
|
|
if angle < 0 {
|
|
|
|
clockWise = false
|
|
|
|
}
|
2012-01-13 09:14:12 +00:00
|
|
|
ra := (math.Abs(rx) + math.Abs(ry)) / 2
|
2011-05-19 21:54:22 +00:00
|
|
|
da := math.Acos(ra/(ra+0.125/scale)) * 2
|
|
|
|
//normalize
|
|
|
|
if !clockWise {
|
|
|
|
da = -da
|
|
|
|
}
|
|
|
|
angle = start + da
|
|
|
|
var curX, curY float64
|
|
|
|
for {
|
|
|
|
if (angle < end-da/4) != clockWise {
|
|
|
|
curX = x + math.Cos(end)*rx
|
|
|
|
curY = y + math.Sin(end)*ry
|
2015-04-29 08:28:05 +00:00
|
|
|
return curX, curY
|
2011-05-19 21:54:22 +00:00
|
|
|
}
|
|
|
|
curX = x + math.Cos(angle)*rx
|
|
|
|
curY = y + math.Sin(angle)*ry
|
|
|
|
|
|
|
|
angle += da
|
2015-04-23 13:36:56 +00:00
|
|
|
t.LineTo(curX, curY)
|
2011-05-19 21:54:22 +00:00
|
|
|
}
|
2015-04-29 08:28:05 +00:00
|
|
|
return curX, curY
|
|
|
|
}
|
|
|
|
|
|
|
|
// TraceArc trace an arc using a Freetype
|
|
|
|
func TraceArcFt(adder raster.Adder, x, y, rx, ry, start, angle, scale float64) raster.Point {
|
|
|
|
end := start + angle
|
|
|
|
clockWise := true
|
|
|
|
if angle < 0 {
|
|
|
|
clockWise = false
|
|
|
|
}
|
|
|
|
ra := (math.Abs(rx) + math.Abs(ry)) / 2
|
|
|
|
da := math.Acos(ra/(ra+0.125/scale)) * 2
|
|
|
|
//normalize
|
|
|
|
if !clockWise {
|
|
|
|
da = -da
|
|
|
|
}
|
|
|
|
angle = start + da
|
|
|
|
var curX, curY float64
|
|
|
|
for {
|
|
|
|
if (angle < end-da/4) != clockWise {
|
|
|
|
curX = x + math.Cos(end)*rx
|
|
|
|
curY = y + math.Sin(end)*ry
|
|
|
|
return raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)}
|
|
|
|
}
|
|
|
|
curX = x + math.Cos(angle)*rx
|
|
|
|
curY = y + math.Sin(angle)*ry
|
|
|
|
|
|
|
|
angle += da
|
|
|
|
adder.Add1(raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)})
|
|
|
|
}
|
|
|
|
return raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)}
|
2011-05-19 21:54:22 +00:00
|
|
|
}
|