• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang fixed.Point26_6类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/c-darwin/dcoin-go/vendor/src/golang.org/x/image/math/fixed.Point26_6的典型用法代码示例。如果您正苦于以下问题:Golang Point26_6类的具体用法?Golang Point26_6怎么用?Golang Point26_6使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Point26_6类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: squareCapper

func squareCapper(p Adder, halfWidth fixed.Int26_6, pivot, n1 fixed.Point26_6) {
	e := pRot90CCW(n1)
	side := pivot.Add(e)
	p.Add1(side.Sub(n1))
	p.Add1(side.Add(n1))
	p.Add1(pivot.Add(n1))
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:7,代码来源:stroke.go


示例2: DrawString

// DrawString draws s at p and returns p advanced by the text extent. The text
// is placed so that the left edge of the em square of the first character of s
// and the baseline intersect at p. The majority of the affected pixels will be
// above and to the right of the point, but some may be below or to the left.
// For example, drawing a string that starts with a 'J' in an italic font may
// affect pixels below and left of the point.
//
// p is a fixed.Point26_6 and can therefore represent sub-pixel positions.
func (c *Context) DrawString(s string, p fixed.Point26_6) (fixed.Point26_6, error) {
	if c.f == nil {
		return fixed.Point26_6{}, errors.New("freetype: DrawText called with a nil font")
	}
	prev, hasPrev := truetype.Index(0), false
	for _, rune := range s {
		index := c.f.Index(rune)
		if hasPrev {
			kern := c.f.Kern(c.scale, prev, index)
			if c.hinting != font.HintingNone {
				kern = (kern + 32) &^ 63
			}
			p.X += kern
		}
		advanceWidth, mask, offset, err := c.glyph(index, p)
		if err != nil {
			return fixed.Point26_6{}, err
		}
		p.X += advanceWidth
		glyphRect := mask.Bounds().Add(offset)
		dr := c.clip.Intersect(glyphRect)
		if !dr.Empty() {
			mp := image.Point{0, dr.Min.Y - glyphRect.Min.Y}
			draw.DrawMask(c.dst, dr, c.src, image.ZP, mask, mp, draw.Over)
		}
		prev, hasPrev = index, true
	}
	return p, nil
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:37,代码来源:freetype.go


示例3: roundJoiner

func roundJoiner(lhs, rhs Adder, haflWidth fixed.Int26_6, pivot, n0, n1 fixed.Point26_6) {
	dot := pDot(pRot90CW(n0), n1)
	if dot >= 0 {
		addArc(lhs, pivot, n0, n1)
		rhs.Add1(pivot.Sub(n1))
	} else {
		lhs.Add1(pivot.Add(n1))
		addArc(rhs, pivot, pNeg(n0), pNeg(n1))
	}
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:10,代码来源:stroke.go


示例4: roundCapper

func roundCapper(p Adder, halfWidth fixed.Int26_6, pivot, n1 fixed.Point26_6) {
	// The cubic Bézier approximation to a circle involves the magic number
	// (√2 - 1) * 4/3, which is approximately 141/256.
	const k = 141
	e := pRot90CCW(n1)
	side := pivot.Add(e)
	start, end := pivot.Sub(n1), pivot.Add(n1)
	d, e := n1.Mul(k), e.Mul(k)
	p.Add3(start.Add(e), side.Sub(d), side)
	p.Add3(side.Add(d), end.Add(e), end)
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:11,代码来源:stroke.go


示例5: Add1

// Add1 adds a linear segment to the stroker.
func (k *stroker) Add1(b fixed.Point26_6) {
	bnorm := pRot90CCW(pNorm(b.Sub(k.a), k.u))
	if len(k.r) == 0 {
		k.p.Start(k.a.Add(bnorm))
		k.r.Start(k.a.Sub(bnorm))
	} else {
		k.jr.Join(k.p, &k.r, k.u, k.a, k.anorm, bnorm)
	}
	k.p.Add1(b.Add(bnorm))
	k.r.Add1(b.Sub(bnorm))
	k.a, k.anorm = b, bnorm
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:13,代码来源:stroke.go


示例6: bevelJoiner

func bevelJoiner(lhs, rhs Adder, haflWidth fixed.Int26_6, pivot, n0, n1 fixed.Point26_6) {
	lhs.Add1(pivot.Add(n1))
	rhs.Add1(pivot.Sub(n1))
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:4,代码来源:stroke.go


示例7: buttCapper

func buttCapper(p Adder, halfWidth fixed.Int26_6, pivot, n1 fixed.Point26_6) {
	p.Add1(pivot.Add(n1))
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:3,代码来源:stroke.go


示例8: Add2

// Add2 adds a quadratic segment to the stroker.
func (k *stroker) Add2(b, c fixed.Point26_6) {
	ab := b.Sub(k.a)
	bc := c.Sub(b)
	abnorm := pRot90CCW(pNorm(ab, k.u))
	if len(k.r) == 0 {
		k.p.Start(k.a.Add(abnorm))
		k.r.Start(k.a.Sub(abnorm))
	} else {
		k.jr.Join(k.p, &k.r, k.u, k.a, k.anorm, abnorm)
	}

	// Approximate nearly-degenerate quadratics by linear segments.
	abIsSmall := pDot(ab, ab) < epsilon
	bcIsSmall := pDot(bc, bc) < epsilon
	if abIsSmall || bcIsSmall {
		acnorm := pRot90CCW(pNorm(c.Sub(k.a), k.u))
		k.p.Add1(c.Add(acnorm))
		k.r.Add1(c.Sub(acnorm))
		k.a, k.anorm = c, acnorm
		return
	}

	// The quadratic segment (k.a, b, c) has a point of maximum curvature.
	// If this occurs at an end point, we process the segment as a whole.
	t := curviest2(k.a, b, c)
	if t <= 0 || 4096 <= t {
		k.addNonCurvy2(b, c)
		return
	}

	// Otherwise, we perform a de Casteljau decomposition at the point of
	// maximum curvature and process the two straighter parts.
	mab := interpolate(k.a, b, t)
	mbc := interpolate(b, c, t)
	mabc := interpolate(mab, mbc, t)

	// If the vectors ab and bc are close to being in opposite directions,
	// then the decomposition can become unstable, so we approximate the
	// quadratic segment by two linear segments joined by an arc.
	bcnorm := pRot90CCW(pNorm(bc, k.u))
	if pDot(abnorm, bcnorm) < -fixed.Int52_12(k.u)*fixed.Int52_12(k.u)*2047/2048 {
		pArc := pDot(abnorm, bc) < 0

		k.p.Add1(mabc.Add(abnorm))
		if pArc {
			z := pRot90CW(abnorm)
			addArc(k.p, mabc, abnorm, z)
			addArc(k.p, mabc, z, bcnorm)
		}
		k.p.Add1(mabc.Add(bcnorm))
		k.p.Add1(c.Add(bcnorm))

		k.r.Add1(mabc.Sub(abnorm))
		if !pArc {
			z := pRot90CW(abnorm)
			addArc(&k.r, mabc, pNeg(abnorm), z)
			addArc(&k.r, mabc, z, pNeg(bcnorm))
		}
		k.r.Add1(mabc.Sub(bcnorm))
		k.r.Add1(c.Sub(bcnorm))

		k.a, k.anorm = c, bcnorm
		return
	}

	// Process the decomposed parts.
	k.addNonCurvy2(mab, mabc)
	k.addNonCurvy2(mbc, c)
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:70,代码来源:stroke.go


示例9: addNonCurvy2

// addNonCurvy2 adds a quadratic segment to the stroker, where the segment
// defined by (k.a, b, c) achieves maximum curvature at either k.a or c.
func (k *stroker) addNonCurvy2(b, c fixed.Point26_6) {
	// We repeatedly divide the segment at its middle until it is straight
	// enough to approximate the stroke by just translating the control points.
	// ds and ps are stacks of depths and points. t is the top of the stack.
	const maxDepth = 5
	var (
		ds [maxDepth + 1]int
		ps [2*maxDepth + 3]fixed.Point26_6
		t  int
	)
	// Initially the ps stack has one quadratic segment of depth zero.
	ds[0] = 0
	ps[2] = k.a
	ps[1] = b
	ps[0] = c
	anorm := k.anorm
	var cnorm fixed.Point26_6

	for {
		depth := ds[t]
		a := ps[2*t+2]
		b := ps[2*t+1]
		c := ps[2*t+0]
		ab := b.Sub(a)
		bc := c.Sub(b)
		abIsSmall := pDot(ab, ab) < fixed.Int52_12(1<<12)
		bcIsSmall := pDot(bc, bc) < fixed.Int52_12(1<<12)
		if abIsSmall && bcIsSmall {
			// Approximate the segment by a circular arc.
			cnorm = pRot90CCW(pNorm(bc, k.u))
			mac := midpoint(a, c)
			addArc(k.p, mac, anorm, cnorm)
			addArc(&k.r, mac, pNeg(anorm), pNeg(cnorm))
		} else if depth < maxDepth && angleGreaterThan45(ab, bc) {
			// Divide the segment in two and push both halves on the stack.
			mab := midpoint(a, b)
			mbc := midpoint(b, c)
			t++
			ds[t+0] = depth + 1
			ds[t-1] = depth + 1
			ps[2*t+2] = a
			ps[2*t+1] = mab
			ps[2*t+0] = midpoint(mab, mbc)
			ps[2*t-1] = mbc
			continue
		} else {
			// Translate the control points.
			bnorm := pRot90CCW(pNorm(c.Sub(a), k.u))
			cnorm = pRot90CCW(pNorm(bc, k.u))
			k.p.Add2(b.Add(bnorm), c.Add(cnorm))
			k.r.Add2(b.Sub(bnorm), c.Sub(cnorm))
		}
		if t == 0 {
			k.a, k.anorm = c, cnorm
			return
		}
		t--
		anorm = cnorm
	}
	panic("unreachable")
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:63,代码来源:stroke.go


示例10: addArc

// addArc adds a circular arc from pivot+n0 to pivot+n1 to p. The shorter of
// the two possible arcs is taken, i.e. the one spanning <= 180 degrees. The
// two vectors n0 and n1 must be of equal length.
func addArc(p Adder, pivot, n0, n1 fixed.Point26_6) {
	// r2 is the square of the length of n0.
	r2 := pDot(n0, n0)
	if r2 < epsilon {
		// The arc radius is so small that we collapse to a straight line.
		p.Add1(pivot.Add(n1))
		return
	}
	// We approximate the arc by 0, 1, 2 or 3 45-degree quadratic segments plus
	// a final quadratic segment from s to n1. Each 45-degree segment has
	// control points {1, 0}, {1, tan(π/8)} and {1/√2, 1/√2} suitably scaled,
	// rotated and translated. tan(π/8) is approximately 106/256.
	const tpo8 = 106
	var s fixed.Point26_6
	// We determine which octant the angle between n0 and n1 is in via three
	// dot products. m0, m1 and m2 are n0 rotated clockwise by 45, 90 and 135
	// degrees.
	m0 := pRot45CW(n0)
	m1 := pRot90CW(n0)
	m2 := pRot90CW(m0)
	if pDot(m1, n1) >= 0 {
		if pDot(n0, n1) >= 0 {
			if pDot(m2, n1) <= 0 {
				// n1 is between 0 and 45 degrees clockwise of n0.
				s = n0
			} else {
				// n1 is between 45 and 90 degrees clockwise of n0.
				p.Add2(pivot.Add(n0).Add(m1.Mul(tpo8)), pivot.Add(m0))
				s = m0
			}
		} else {
			pm1, n0t := pivot.Add(m1), n0.Mul(tpo8)
			p.Add2(pivot.Add(n0).Add(m1.Mul(tpo8)), pivot.Add(m0))
			p.Add2(pm1.Add(n0t), pm1)
			if pDot(m0, n1) >= 0 {
				// n1 is between 90 and 135 degrees clockwise of n0.
				s = m1
			} else {
				// n1 is between 135 and 180 degrees clockwise of n0.
				p.Add2(pm1.Sub(n0t), pivot.Add(m2))
				s = m2
			}
		}
	} else {
		if pDot(n0, n1) >= 0 {
			if pDot(m0, n1) >= 0 {
				// n1 is between 0 and 45 degrees counter-clockwise of n0.
				s = n0
			} else {
				// n1 is between 45 and 90 degrees counter-clockwise of n0.
				p.Add2(pivot.Add(n0).Sub(m1.Mul(tpo8)), pivot.Sub(m2))
				s = pNeg(m2)
			}
		} else {
			pm1, n0t := pivot.Sub(m1), n0.Mul(tpo8)
			p.Add2(pivot.Add(n0).Sub(m1.Mul(tpo8)), pivot.Sub(m2))
			p.Add2(pm1.Add(n0t), pm1)
			if pDot(m2, n1) <= 0 {
				// n1 is between 90 and 135 degrees counter-clockwise of n0.
				s = pNeg(m1)
			} else {
				// n1 is between 135 and 180 degrees counter-clockwise of n0.
				p.Add2(pm1.Sub(n0t), pivot.Sub(m0))
				s = pNeg(m0)
			}
		}
	}
	// The final quadratic segment has two endpoints s and n1 and the middle
	// control point is a multiple of s.Add(n1), i.e. it is on the angle
	// bisector of those two points. The multiple ranges between 128/256 and
	// 150/256 as the angle between s and n1 ranges between 0 and 45 degrees.
	//
	// When the angle is 0 degrees (i.e. s and n1 are coincident) then
	// s.Add(n1) is twice s and so the middle control point of the degenerate
	// quadratic segment should be half s.Add(n1), and half = 128/256.
	//
	// When the angle is 45 degrees then 150/256 is the ratio of the lengths of
	// the two vectors {1, tan(π/8)} and {1 + 1/√2, 1/√2}.
	//
	// d is the normalized dot product between s and n1. Since the angle ranges
	// between 0 and 45 degrees then d ranges between 256/256 and 181/256.
	d := 256 * pDot(s, n1) / r2
	multiple := fixed.Int26_6(150-(150-128)*(d-181)/(256-181)) >> 2
	p.Add2(pivot.Add(s.Add(n1).Mul(multiple)), pivot.Add(n1))
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:88,代码来源:stroke.go


示例11: main

func main() {
	const (
		n = 17
		r = 64 * 80
	)
	s := fixed.Int26_6(r * math.Sqrt(2) / 2)
	t := fixed.Int26_6(r * math.Tan(math.Pi/8))

	m := image.NewRGBA(image.Rect(0, 0, 800, 600))
	draw.Draw(m, m.Bounds(), image.NewUniform(color.RGBA{63, 63, 63, 255}), image.ZP, draw.Src)
	mp := raster.NewRGBAPainter(m)
	mp.SetColor(image.Black)
	z := raster.NewRasterizer(800, 600)

	for i := 0; i < n; i++ {
		cx := fixed.Int26_6(6400 + 12800*(i%4))
		cy := fixed.Int26_6(640 + 8000*(i/4))
		c := fixed.Point26_6{X: cx, Y: cy}
		theta := math.Pi * (0.5 + 0.5*float64(i)/(n-1))
		dx := fixed.Int26_6(r * math.Cos(theta))
		dy := fixed.Int26_6(r * math.Sin(theta))
		d := fixed.Point26_6{X: dx, Y: dy}
		// Draw a quarter-circle approximated by two quadratic segments,
		// with each segment spanning 45 degrees.
		z.Start(c)
		z.Add1(c.Add(fixed.Point26_6{X: r, Y: 0}))
		z.Add2(c.Add(fixed.Point26_6{X: r, Y: t}), c.Add(fixed.Point26_6{X: s, Y: s}))
		z.Add2(c.Add(fixed.Point26_6{X: t, Y: r}), c.Add(fixed.Point26_6{X: 0, Y: r}))
		// Add another quadratic segment whose angle ranges between 0 and 90
		// degrees. For an explanation of the magic constants 128, 150, 181 and
		// 256, read the comments in the freetype/raster package.
		dot := 256 * pDot(d, fixed.Point26_6{X: 0, Y: r}) / (r * r)
		multiple := fixed.Int26_6(150-(150-128)*(dot-181)/(256-181)) >> 2
		z.Add2(c.Add(fixed.Point26_6{X: dx, Y: r + dy}.Mul(multiple)), c.Add(d))
		// Close the curve.
		z.Add1(c)
	}
	z.Rasterize(mp)

	for i := 0; i < n; i++ {
		cx := fixed.Int26_6(6400 + 12800*(i%4))
		cy := fixed.Int26_6(640 + 8000*(i/4))
		for j := 0; j < n; j++ {
			theta := math.Pi * float64(j) / (n - 1)
			dx := fixed.Int26_6(r * math.Cos(theta))
			dy := fixed.Int26_6(r * math.Sin(theta))
			m.Set(int((cx+dx)/64), int((cy+dy)/64), color.RGBA{255, 255, 0, 255})
		}
	}

	// Save that RGBA image to disk.
	outFile, err := os.Create("out.png")
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	defer outFile.Close()
	b := bufio.NewWriter(outFile)
	err = png.Encode(b, m)
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	err = b.Flush()
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	fmt.Println("Wrote out.png OK.")
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:70,代码来源:main.go



注:本文中的github.com/c-darwin/dcoin-go/vendor/src/golang.org/x/image/math/fixed.Point26_6类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang seq.Buffer类代码示例发布时间:2022-05-24
下一篇:
Golang fixed.Int26_6函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap