reduce number of points with distance_threshold parameter deduce from flattening_threshold
This commit is contained in:
parent
65e5e944d4
commit
b88f2dc3a3
5 changed files with 1100 additions and 1081 deletions
|
@ -6,4 +6,6 @@ GOFILES=\
|
||||||
quad_float64.go\
|
quad_float64.go\
|
||||||
cubic_float64_others.go\
|
cubic_float64_others.go\
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
include $(GOROOT)/src/Make.pkg
|
include $(GOROOT)/src/Make.pkg
|
||||||
|
|
|
@ -45,7 +45,12 @@ func (curve *CubicCurveFloat64) Segment(t LineTracer, flattening_threshold float
|
||||||
i := 0
|
i := 0
|
||||||
// current curve
|
// current curve
|
||||||
var c *CubicCurveFloat64
|
var c *CubicCurveFloat64
|
||||||
|
|
||||||
var dx, dy, d2, d3 float64
|
var dx, dy, d2, d3 float64
|
||||||
|
var lx, ly float64
|
||||||
|
distance_threshold := flattening_threshold * 5
|
||||||
|
lx, ly = curve.X1, curve.Y1
|
||||||
|
|
||||||
for i >= 0 {
|
for i >= 0 {
|
||||||
c = &curves[i]
|
c = &curves[i]
|
||||||
dx = c.X4 - c.X1
|
dx = c.X4 - c.X1
|
||||||
|
@ -55,7 +60,11 @@ func (curve *CubicCurveFloat64) Segment(t LineTracer, flattening_threshold float
|
||||||
d3 = math.Fabs(((c.X3-c.X4)*dy - (c.Y3-c.Y4)*dx))
|
d3 = math.Fabs(((c.X3-c.X4)*dy - (c.Y3-c.Y4)*dx))
|
||||||
|
|
||||||
if (d2+d3)*(d2+d3) < flattening_threshold*(dx*dx+dy*dy) || i == len(curves)-1 {
|
if (d2+d3)*(d2+d3) < flattening_threshold*(dx*dx+dy*dy) || i == len(curves)-1 {
|
||||||
|
if !(math.Fabs(lx - c.X4) < distance_threshold && math.Fabs(ly - c.Y4)< distance_threshold ) {
|
||||||
t.LineTo(c.X4, c.Y4)
|
t.LineTo(c.X4, c.Y4)
|
||||||
|
lx, ly = c.X4, c.Y4
|
||||||
|
}
|
||||||
|
|
||||||
i--
|
i--
|
||||||
} else {
|
} else {
|
||||||
// second half of bezier go lower onto the stack
|
// second half of bezier go lower onto the stack
|
||||||
|
|
|
@ -89,7 +89,7 @@ func savepng(filePath string, m image.Image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawPoints(img draw.Image, c image.Color, s ...float64) image.Image {
|
func drawPoints(img draw.Image, c image.Color, s ...float64) image.Image {
|
||||||
for i := 0; i < len(s); i += 2 {
|
/*for i := 0; i < len(s); i += 2 {
|
||||||
x, y := int(s[i]+0.5), int(s[i+1]+0.5)
|
x, y := int(s[i]+0.5), int(s[i+1]+0.5)
|
||||||
img.Set(x, y, c)
|
img.Set(x, y, c)
|
||||||
img.Set(x, y+1, c)
|
img.Set(x, y+1, c)
|
||||||
|
@ -101,7 +101,7 @@ func drawPoints(img draw.Image, c image.Color, s ...float64) image.Image {
|
||||||
img.Set(x-1, y+1, c)
|
img.Set(x-1, y+1, c)
|
||||||
img.Set(x-1, y-1, c)
|
img.Set(x-1, y-1, c)
|
||||||
|
|
||||||
}
|
}*/
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,10 @@ func (curve *QuadCurveFloat64) Segment(t LineTracer, flattening_threshold float6
|
||||||
// current curve
|
// current curve
|
||||||
var c *QuadCurveFloat64
|
var c *QuadCurveFloat64
|
||||||
var dx, dy, d float64
|
var dx, dy, d float64
|
||||||
|
var lx, ly float64
|
||||||
|
distance_threshold := flattening_threshold * 5
|
||||||
|
lx, ly = curve.X1, curve.Y1
|
||||||
|
|
||||||
for i >= 0 {
|
for i >= 0 {
|
||||||
c = &curves[i]
|
c = &curves[i]
|
||||||
dx = c.X3 - c.X1
|
dx = c.X3 - c.X1
|
||||||
|
@ -42,7 +46,11 @@ func (curve *QuadCurveFloat64) Segment(t LineTracer, flattening_threshold float6
|
||||||
d = math.Fabs(((c.X2-c.X3)*dy - (c.Y2-c.Y3)*dx))
|
d = math.Fabs(((c.X2-c.X3)*dy - (c.Y2-c.Y3)*dx))
|
||||||
|
|
||||||
if (d*d) < flattening_threshold*(dx*dx+dy*dy) || i == len(curves)-1 {
|
if (d*d) < flattening_threshold*(dx*dx+dy*dy) || i == len(curves)-1 {
|
||||||
|
if !(math.Fabs(lx - c.X3) <= distance_threshold && math.Fabs(ly - c.Y3)<= distance_threshold ) {
|
||||||
t.LineTo(c.X3, c.Y3)
|
t.LineTo(c.X3, c.Y3)
|
||||||
|
lx, ly = c.X3, c.Y3
|
||||||
|
}
|
||||||
|
|
||||||
i--
|
i--
|
||||||
} else {
|
} else {
|
||||||
// second half of bezier go lower onto the stack
|
// second half of bezier go lower onto the stack
|
||||||
|
|
Loading…
Reference in a new issue