diff --git a/form2/must2/basic.go b/form2/must2/basic.go index 1e1abcc..92366e9 100644 --- a/form2/must2/basic.go +++ b/form2/must2/basic.go @@ -88,7 +88,7 @@ func (s *line) Evaluate(p r2.Vec) float64 { if p.X <= s.l { return p.Y - s.round } - return r2.Norm(p.Sub(r2.Vec{s.l, 0})) - s.round + return r2.Norm(r2.Sub(p, r2.Vec{s.l, 0})) - s.round } // BoundingBox returns the bounding box for a 2d line. diff --git a/form2/must2/errors.go b/form2/must2/errors.go index e8c6202..5de7f53 100644 --- a/form2/must2/errors.go +++ b/form2/must2/errors.go @@ -20,7 +20,7 @@ func ErrMsg(msg string) error { func sdfBox2d(p, s r2.Vec) float64 { p = d2.AbsElem(p) - d := p.Sub(s) + d := r2.Sub(p, s) k := s.Y - s.X if d.X > 0 && d.Y > 0 { return r2.Norm(d) //d.Length() diff --git a/form2/must2/poly.go b/form2/must2/poly.go index bc80389..9d79db0 100644 --- a/form2/must2/poly.go +++ b/form2/must2/poly.go @@ -41,7 +41,7 @@ func Polygon(vertex []r2.Vec) sdf.SDF2 { vmax := s.vertex[0] for i := 0; i < nsegs; i++ { - l := s.vertex[i+1].Sub(s.vertex[i]) + l := r2.Sub(s.vertex[i+1], s.vertex[i]) s.length[i] = r2.Norm(l) s.vector[i] = r2.Unit(l) vmin = d2.MinElem(vmin, s.vertex[i]) @@ -59,17 +59,17 @@ func (s *polygon) Evaluate(p r2.Vec) float64 { // iterate over the line segments nsegs := len(s.vertex) - 1 - pb := p.Sub(s.vertex[0]) + pb := r2.Sub(p, s.vertex[0]) for i := 0; i < nsegs; i++ { a := s.vertex[i] b := s.vertex[i+1] pa := pb - pb = p.Sub(b) + pb = r2.Sub(p, b) - t := pa.Dot(s.vector[i]) // t-parameter of projection onto line - dn := pa.Dot(r2.Vec{s.vector[i].Y, -s.vector[i].X}) // normal distance from p to line + t := r2.Dot(pa, s.vector[i]) // t-parameter of projection onto line + dn := r2.Dot(pa, r2.Vec{s.vector[i].Y, -s.vector[i].X}) // normal distance from p to line // Distance to line segment if t < 0 { @@ -230,28 +230,28 @@ func (p *PolygonBuilder) arcVertex(i int) bool { a := pv.vertex b := v.vertex // Normal to chord - ba := r2.Unit(b.Sub(a)) //.Normalize() + ba := r2.Unit(r2.Sub(b, a)) //.Normalize() n := r2.Scale(side, r2.Vec{ba.Y, -ba.X}) // midpoint - mid := r2.Scale(0.5, a.Add(b)) + mid := r2.Scale(0.5, r2.Add(a, b)) // distance from a to midpoint - dMid := r2.Norm(mid.Sub(a)) + dMid := r2.Norm(r2.Sub(mid, a)) // distance from midpoint to center of arc dCenter := math.Sqrt((radius * radius) - (dMid * dMid)) // center of arc - c := mid.Add(r2.Scale(dCenter, n)) + c := r2.Add(mid, r2.Scale(dCenter, n)) // work out the angle - ac := r2.Unit(a.Sub(c)) - bc := r2.Unit(b.Sub(c)) - dtheta := -side * math.Acos(ac.Dot(bc)) / float64(v.facets) + ac := r2.Unit(r2.Sub(a, c)) + bc := r2.Unit(r2.Sub(b, c)) + dtheta := -side * math.Acos(r2.Dot(ac, bc)) / float64(v.facets) // rotation matrix m := sdf.Rotate(dtheta) // radius vector - rv := m.MulPosition(a.Sub(c)) + rv := m.MulPosition(r2.Sub(a, c)) // work out the new vertices vlist := make([]polygonVertex, v.facets-1) for j := range vlist { - vlist[j] = polygonVertex{vertex: c.Add(rv)} + vlist[j] = polygonVertex{vertex: r2.Add(c, rv)} rv = m.MulPosition(rv) } // insert the new vertices between the arc endpoints @@ -290,32 +290,32 @@ func (p *PolygonBuilder) smoothVertex(i int) bool { return false } // work out the angle - v0 := r2.Unit(vp.vertex.Sub(v.vertex)) - v1 := r2.Unit(vn.vertex.Sub(v.vertex)) - theta := math.Acos(v0.Dot(v1)) + v0 := r2.Unit(r2.Sub(vp.vertex, v.vertex)) + v1 := r2.Unit(r2.Sub(vn.vertex, v.vertex)) + theta := math.Acos(r2.Dot(v0, v1)) // distance from vertex to circle tangent d1 := v.radius / math.Tan(theta/2.0) - if d1 > r2.Norm(vp.vertex.Sub(v.vertex)) || d1 > r2.Norm(vn.vertex.Sub(v.vertex)) { + if d1 > r2.Norm(r2.Sub(vp.vertex, v.vertex)) || d1 > r2.Norm(r2.Sub(vn.vertex, v.vertex)) { // unable to smooth - radius is too large return false } // tangent points - p0 := v.vertex.Add(r2.Scale(d1, v0)) + p0 := r2.Add(v.vertex, r2.Scale(d1, v0)) // distance from vertex to circle center d2 := v.radius / math.Sin(theta/2.0) // center of circle - vc := r2.Unit(v0.Add(v1)) - c := v.vertex.Add(r2.Scale(d2, vc)) + vc := r2.Unit(r2.Add(v0, v1)) + c := r2.Add(v.vertex, r2.Scale(d2, vc)) // rotation angle - dtheta := Sign(v1.Cross(v0)) * (math.Pi - theta) / float64(v.facets) + dtheta := Sign(r2.Cross(v1, v0)) * (math.Pi - theta) / float64(v.facets) // rotation matrix rm := sdf.Rotate(dtheta) // radius vector - rv := p0.Sub(c) + rv := r2.Sub(p0, c) // work out the new points points := make([]polygonVertex, v.facets+1) for j := range points { - points[j] = polygonVertex{vertex: c.Add(rv)} + points[j] = polygonVertex{vertex: r2.Add(c, rv)} rv = rm.MulPosition(rv) } // replace the old point with the new points @@ -345,7 +345,7 @@ func (p *PolygonBuilder) relToAbs() error { if pv.relative { return fmt.Errorf("relative vertex needs an absolute reference") } - v.vertex = v.vertex.Add(pv.vertex) + v.vertex = r2.Add(v.vertex, pv.vertex) v.relative = false } } diff --git a/form3/must3/cylinders.go b/form3/must3/cylinders.go index f80a810..8ff27d7 100644 --- a/form3/must3/cylinders.go +++ b/form3/must3/cylinders.go @@ -149,14 +149,14 @@ func Cone(height, r0, r1, round float64) *cone { s.height = (height / 2) - round s.round = round // cone slope vector and normal - s.u = r2.Unit(r2.Vec{r1, height / 2}.Sub(r2.Vec{r0, -height / 2})) + s.u = r2.Unit(r2.Sub(r2.Vec{r1, height / 2}, r2.Vec{r0, -height / 2})) s.n = r2.Vec{s.u.Y, -s.u.X} // inset the radii for the rounding ofs := round / s.n.X s.r0 = r0 - (1+s.n.Y)*ofs s.r1 = r1 - (1-s.n.Y)*ofs // cone slope length - s.l = r2.Norm(r2.Vec{s.r1, s.height}.Sub(r2.Vec{s.r0, -s.height})) + s.l = r2.Norm(r2.Sub(r2.Vec{s.r1, s.height}, r2.Vec{s.r0, -s.height})) // work out the bounding box r := math.Max(s.r0+round, s.r1+round) s.bb = r3.Box{r3.Vec{-r, -r, -height / 2}, r3.Vec{r, r, height / 2}} @@ -176,14 +176,14 @@ func (s *cone) Evaluate(p r3.Vec) float64 { return -p2.Y - s.height - s.round } // distance to slope line - v := p2.Sub(r2.Vec{s.r0, -s.height}) - dSlope := v.Dot(s.n) + v := r2.Sub(p2, r2.Vec{s.r0, -s.height}) + dSlope := r2.Dot(v, s.n) // is p2 inside the cone? if dSlope < 0 && math.Abs(p2.Y) < s.height { return -math.Min(-dSlope, s.height-math.Abs(p2.Y)) - s.round } // is p2 closest to the slope line? - t := v.Dot(s.u) + t := r2.Dot(v, s.u) if t >= 0 && t <= s.l { return dSlope - s.round } @@ -192,7 +192,7 @@ func (s *cone) Evaluate(p r3.Vec) float64 { return r2.Norm(v) - s.round } // p2 is closest to the top radius vertex - return r2.Norm(p2.Sub(r2.Vec{s.r1, s.height})) - s.round + return r2.Norm(r2.Sub(p2, r2.Vec{s.r1, s.height})) - s.round } // BoundingBox return the bounding box for the trucated cone.. diff --git a/form3/must3/errors.go b/form3/must3/errors.go index ed9ab98..52289cd 100644 --- a/form3/must3/errors.go +++ b/form3/must3/errors.go @@ -7,7 +7,7 @@ import ( func sdfBox2d(p, s r2.Vec) float64 { p = d2.AbsElem(p) - d := p.Sub(s) + d := r2.Sub(p, s) k := s.Y - s.X if d.X > 0 && d.Y > 0 { return r2.Norm(d) //d.Length() diff --git a/go.mod b/go.mod index f5e360f..200df8c 100644 --- a/go.mod +++ b/go.mod @@ -12,20 +12,14 @@ require ( ) require ( - git.sr.ht/~sbinet/gg v0.3.1 // indirect github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect github.com/dhconnelly/rtreego v1.1.0 // indirect github.com/fogleman/simplify v0.0.0-20170216171241-d32f302d5046 // indirect - github.com/go-fonts/liberation v0.2.0 // indirect - github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 // indirect - github.com/go-pdf/fpdf v0.6.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/hschendel/stl v1.0.4 // indirect github.com/llgcode/draw2d v0.0.0-20200930101115-bfaf5d914d1e // indirect github.com/yofu/dxf v0.0.0-20190710012328-5a6d1e83f16c // indirect golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d // indirect golang.org/x/image v0.0.0-20220617043117-41969df76e82 // indirect - golang.org/x/text v0.3.7 // indirect - golang.org/x/tools v0.1.11 // indirect rsc.io/pdf v0.1.1 // indirect ) diff --git a/go.sum b/go.sum index bb15cb7..98a77ec 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,5 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8= -git.sr.ht/~sbinet/gg v0.3.1 h1:LNhjNn8DerC8f9DHLz6lS0YYul/b602DUxDgGkd/Aik= git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= @@ -29,21 +28,19 @@ github.com/fogleman/simplify v0.0.0-20170216171241-d32f302d5046/go.mod h1:KDwyDq github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g= github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks= github.com/go-fonts/liberation v0.1.1/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY= -github.com/go-fonts/liberation v0.2.0 h1:jAkAWJP4S+OsrPLZM4/eC9iW7CtHy+HBXrEwZXWo5VM= github.com/go-fonts/liberation v0.2.0/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY= github.com/go-fonts/stix v0.1.0/go.mod h1:w/c1f0ldAUlJmLBvlbkvVXLAD+tAMqobIIQpmnUIzUY= github.com/go-gl/gl v0.0.0-20180407155706-68e253793080/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= github.com/go-gl/glfw v0.0.0-20180426074136-46a8d530c326/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U= -github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 h1:6zl3BbBhdnMkpSj2YY30qV3gDcVBGtFgVsV3+/i+mKQ= github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk= github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= -github.com/go-pdf/fpdf v0.6.0 h1:MlgtGIfsdMEEQJr2le6b/HNr1ZlQwxyWr77r2aj2U/8= github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/hschendel/stl v1.0.4 h1:DXT5rkiXMUkbKw4Ndi1OYZ/a5SLR35TzxGj46p5Qyf8= github.com/hschendel/stl v1.0.4/go.mod h1:XQFFLKrq9YTaBpmouDui4JSaxMyAYkpD7elGSSj/y3M= github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= @@ -76,11 +73,11 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3 h1:n9HxLrNxWWtEb1cA950nuEEj3QnKbtsCJ6KjcgisNUs= golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE= golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d h1:vtUKgx8dahOomfFzLREU8nSv25YHnTgLBn4rDnWZdU0= golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= @@ -96,7 +93,6 @@ golang.org/x/image v0.0.0-20210216034530-4410531fe030/go.mod h1:FeLwcggjj3mMvU+o golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/image v0.0.0-20220302094943-723b81ca9867 h1:TcHcE0vrmgzNH1v3ppjcMGbhG5+9fMuvOmUYwNEF4q4= golang.org/x/image v0.0.0-20220302094943-723b81ca9867/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/image v0.0.0-20220617043117-41969df76e82 h1:KpZB5pUSBvrHltNEdK/tw0xlPeD13M6M6aGP32gKqiw= golang.org/x/image v0.0.0-20220617043117-41969df76e82/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= @@ -104,9 +100,11 @@ golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCc golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -119,13 +117,13 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210304124612-50617c2ba197/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -134,8 +132,7 @@ golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= -golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY= -golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= +golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -143,7 +140,6 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= gonum.org/v1/gonum v0.9.3/go.mod h1:TZumC3NeyVQskjXqmyWt4S3bINhy7B4eYwW69EbyX+0= -gonum.org/v1/gonum v0.11.0 h1:f1IJhK4Km5tBJmaiJXtk/PkL4cdVX6J+tGiM187uT5E= gonum.org/v1/gonum v0.11.0/go.mod h1:fSG4YDCxxUZQJ7rKsQrj0gMOg00Il0Z96/qMA4bVQhA= gonum.org/v1/gonum v0.11.1-0.20220625074215-67f3e1dbfccc h1:ADX7LJ8SknE89dXBcPhZGGV60cMUzqB9XcaNKuHZxy4= gonum.org/v1/gonum v0.11.1-0.20220625074215-67f3e1dbfccc/go.mod h1:fSG4YDCxxUZQJ7rKsQrj0gMOg00Il0Z96/qMA4bVQhA= diff --git a/internal/d2/box.go b/internal/d2/box.go index b2660a6..132bac8 100644 --- a/internal/d2/box.go +++ b/internal/d2/box.go @@ -13,7 +13,7 @@ type Box r2.Box // NewBox2 creates a 2d box with a given center and size. func NewBox2(center, size r2.Vec) Box { half := r2.Scale(0.5, size) - return Box{center.Sub(half), center.Add(half)} + return Box{r2.Sub(center, half), r2.Add(center, half)} } // Equals test the equality of 2d boxes. @@ -36,17 +36,17 @@ func (a Box) Include(v r2.Vec) Box { // Translate translates a 2d box. func (a Box) Translate(v r2.Vec) Box { - return Box{a.Min.Add(v), a.Max.Add(v)} + return Box{r2.Add(a.Min, v), r2.Add(a.Max, v)} } // Size returns the size of a 2d box. func (a Box) Size() r2.Vec { - return a.Max.Sub(a.Min) + return r2.Sub(a.Max, a.Min) } // Center returns the center of a 2d box. func (a Box) Center() r2.Vec { - return a.Min.Add(r2.Scale(0.5, a.Size())) + return r2.Add(a.Min, r2.Scale(0.5, a.Size())) // return a.Min.Add(a.Size().MulScalar(0.5)) } @@ -59,7 +59,7 @@ func (a Box) ScaleAboutCenter(k float64) Box { // Enlarge returns a new 2d box enlarged by a size vector. func (a Box) Enlarge(v r2.Vec) Box { v = r2.Scale(0.5, v) - return Box{a.Min.Sub(v), a.Max.Add(v)} + return Box{r2.Sub(a.Min, v), r2.Add(a.Max, v)} } // Contains checks if the 2d box contains the given vector (considering bounds as inside). diff --git a/internal/d2/transform.go b/internal/d2/transform.go index 5cbb026..09562b2 100644 --- a/internal/d2/transform.go +++ b/internal/d2/transform.go @@ -103,8 +103,8 @@ func (a Transform) ApplyBox(box Box) Box { yb := r2.Scale(box.Max.Y, u) xa, xb = MinElem(xa, xb), MaxElem(xa, xb) ya, yb = MinElem(ya, yb), MaxElem(ya, yb) - min := xa.Add(ya).Add(t) - max := xb.Add(yb).Add(t) + min := r2.Add(t, r2.Add(xa, ya)) + max := r2.Add(t, r2.Add(xb, yb)) return Box{min, max} } diff --git a/internal/d3/box.go b/internal/d3/box.go index fa99274..0767ded 100644 --- a/internal/d3/box.go +++ b/internal/d3/box.go @@ -47,12 +47,12 @@ func (a Box) Include(v r3.Vec) Box { // Translate translates a 3d box. func (a Box) Translate(v r3.Vec) Box { - return Box{a.Min.Add(v), a.Max.Add(v)} + return Box{r3.Add(a.Min, v), r3.Add(a.Max, v)} } // Size returns the size of a 3d box. func (a Box) Size() r3.Vec { - return a.Max.Sub(a.Min) + return r3.Sub(a.Max, a.Min) } // Center returns the center of a 3d box. diff --git a/matrix.go b/matrix.go index 3bb1566..3efb58a 100644 --- a/matrix.go +++ b/matrix.go @@ -398,8 +398,8 @@ func (a m44) MulBox(box r3.Box) r3.Box { xa, xb = d3.MinElem(xa, xb), d3.MaxElem(xa, xb) ya, yb = d3.MinElem(ya, yb), d3.MaxElem(ya, yb) za, zb = d3.MinElem(za, zb), d3.MaxElem(za, zb) - min := xa.Add(ya).Add(za).Add(t) - max := xb.Add(yb).Add(zb).Add(t) + min := r3.Add(xa, r3.Add(ya, r3.Add(za, t))) + max := r3.Add(xb, r3.Add(yb, r3.Add(zb, t))) return r3.Box{Min: min, Max: max} } @@ -414,8 +414,10 @@ func (a m33) MulBox(box r2.Box) r2.Box { yb := r2.Scale(box.Max.Y, u) xa, xb = d2.MinElem(xa, xb), d2.MaxElem(xa, xb) ya, yb = d2.MinElem(ya, yb), d2.MaxElem(ya, yb) - min := xa.Add(ya).Add(t) - max := xb.Add(yb).Add(t) + min := r2.Add(xa, r2.Add(ya, t)) + max := r2.Add(xb, r2.Add(yb, t)) + // min := xa.Add(ya).Add(t) + // max := xb.Add(yb).Add(t) return r2.Box{Min: min, Max: max} } diff --git a/render/stl.go b/render/stl.go index 949f760..f1c5230 100644 --- a/render/stl.go +++ b/render/stl.go @@ -302,8 +302,8 @@ func (t stlTriangle) normalFromVertices() [3]float32 { v1 := r3.Scale(10, r3From3F32(t.Vertex1)) v2 := r3.Scale(10, r3From3F32(t.Vertex2)) v3 := r3.Scale(10, r3From3F32(t.Vertex3)) - e1 := v2.Sub(v1) - e2 := v3.Sub(v1) + e1 := r3.Sub(v2, v1) + e2 := r3.Sub(v3, v1) n := r3.Unit(r3.Cross(e1, e2)) n32 := [3]float32{float32(n.X), float32(n.Y), float32(n.Z)} return n32 diff --git a/sdf2.go b/sdf2.go index b43c39b..900ae78 100644 --- a/sdf2.go +++ b/sdf2.go @@ -40,7 +40,7 @@ type MinFunc func(a, b float64) float64 func sdfBox2d(p, s r2.Vec) float64 { p = d2.AbsElem(p) - d := p.Sub(s) + d := r2.Sub(p, s) k := s.Y - s.X if d.X > 0 && d.Y > 0 { return r2.Norm(d) @@ -76,7 +76,7 @@ func Cut2D(sdf SDF2, a, v r2.Vec) SDF2 { // Evaluate returns the minimum distance to cut SDF2. func (s *CutSDF2) Evaluate(p r2.Vec) float64 { - return math.Max(p.Sub(s.a).Dot(s.n), s.sdf.Evaluate(p)) + return math.Max(r2.Dot(s.n, r2.Sub(p, s.a)), s.sdf.Evaluate(p)) } // BoundingBox returns the bounding box for the cut SDF2. @@ -201,7 +201,7 @@ func (s *array2) Evaluate(p r2.Vec) float64 { d := math.MaxFloat64 for j := 0; j < s.num[0]; j++ { for k := 0; k < s.num[1]; k++ { - x := p.Sub(r2.Vec{X: float64(j) * s.step.X, Y: float64(k) * s.step.Y}) + x := r2.Sub(p, r2.Vec{X: float64(j) * s.step.X, Y: float64(k) * s.step.Y}) d = s.min(d, s.sdf.Evaluate(x)) } } @@ -337,7 +337,7 @@ func Slice2D(sdf SDF3, a, n r3.Vec) SDF2 { } else { s.u = r3.Vec{X: n.Y, Y: -n.X, Z: 0} } - s.v = n.Cross(s.u) + s.v = r3.Cross(n, s.u) s.u = r3.Unit(s.u) s.v = r3.Unit(s.v) // work out the bounding box @@ -349,10 +349,10 @@ func Slice2D(sdf SDF3, a, n r3.Vec) SDF2 { n = r3.Unit(n) for i, v := range v3 { // project the 3d bounding box vertex onto the plane - va := v.Sub(s.a) - pa := va.Sub(r3.Scale(r3.Dot(n, va), n)) + va := r3.Sub(v, s.a) + pa := r3.Sub(va, r3.Scale(r3.Dot(n, va), n)) // work out the 3d point in terms of the 2d unit vectors - vec[i] = r2.Vec{X: pa.Dot(s.u), Y: pa.Dot(s.v)} + vec[i] = r2.Vec{X: r3.Dot(pa, s.u), Y: r3.Dot(pa, s.v)} } s.bb = r2.Box{Min: vec.Min(), Max: vec.Max()} return &s @@ -516,7 +516,7 @@ func Elongate2D(sdf SDF2, h r2.Vec) SDF2 { // Evaluate returns the minimum distance to an elongated SDF2. func (s *elongate2) Evaluate(p r2.Vec) float64 { - q := p.Sub(d2.Clamp(p, s.hn, s.hp)) + q := r2.Sub(p, d2.Clamp(p, s.hn, s.hp)) return s.sdf.Evaluate(q) } @@ -561,7 +561,7 @@ func LineOf2D(s SDF2, p0, p1 r2.Vec, pattern string) SDF2 { if c == 'x' { objects = append(objects, Transform2D(s, Translate2D(x))) } - x = x.Add(dx) + x = r2.Add(x, dx) } } if len(objects) == 1 { diff --git a/sdf3.go b/sdf3.go index e4638dc..ac49676 100644 --- a/sdf3.go +++ b/sdf3.go @@ -43,7 +43,8 @@ type revolution3 struct { // Revolve3D returns an SDF3 for a solid of revolution. // theta is in radians. For a full revolution call -// Revolve3D(s0, 2*math.Pi) +// +// Revolve3D(s0, 2*math.Pi) func Revolve3D(sdf SDF2, theta float64) SDF3 { if sdf == nil { panic("nil SDF2 argument") @@ -93,7 +94,7 @@ func (s *revolution3) Evaluate(p r3.Vec) float64 { b := a if s.theta != 0 { // combine two vertical planes to give an intersection wedge - d := s.norm.Dot(r2.Vec{X: p.X, Y: p.Y}) + d := r2.Dot(s.norm, r2.Vec{X: p.X, Y: p.Y}) if s.theta < pi { b = math.Max(-p.Y, d) // intersect } else { @@ -522,7 +523,7 @@ func Elongate3D(sdf SDF3, h r3.Vec) SDF3 { // Evaluate returns the minimum distance to a elongated SDF2. func (s *elongate3) Evaluate(p r3.Vec) float64 { - q := p.Sub(d3.Clamp(p, s.hn, s.hp)) + q := r3.Sub(p, d3.Clamp(p, s.hn, s.hp)) return s.sdf.Evaluate(q) } @@ -591,7 +592,7 @@ func Cut3D(sdf SDF3, a, n r3.Vec) SDF3 { // Evaluate returns the minimum distance to the cut SDF3. func (s *cut3) Evaluate(p r3.Vec) float64 { - return math.Max(p.Sub(s.a).Dot(s.n), s.sdf.Evaluate(p)) + return math.Max(r3.Dot(s.n, r3.Sub(p, s.a)), s.sdf.Evaluate(p)) } // BoundingBox returns the bounding box of the cut SDF3. @@ -637,7 +638,7 @@ func (s *array3) Evaluate(p r3.Vec) float64 { for j := 0; j < s.num[0]; j++ { for k := 0; k < s.num[1]; k++ { for l := 0; l < s.num[2]; l++ { - x := p.Sub(r3.Vec{X: float64(j) * s.step.X, Y: float64(k) * s.step.Y, Z: float64(l) * s.step.Z}) + x := r3.Sub(p, r3.Vec{X: float64(j) * s.step.X, Y: float64(k) * s.step.Y, Z: float64(l) * s.step.Z}) d = s.min(d, s.sdf.Evaluate(x)) } } @@ -867,7 +868,7 @@ func LineOf3D(s SDF3, p0, p1 r3.Vec, pattern string) SDF3 { if c == 'x' { objects = append(objects, Transform3D(s, Translate3D(x))) } - x = x.Add(dx) + x = r3.Add(x, dx) } } return Union3D(objects...) diff --git a/utils.go b/utils.go index 4b710b9..7303faf 100644 --- a/utils.go +++ b/utils.go @@ -47,7 +47,7 @@ func R3ToI(a r3.Vec) V3i { // R3FromI temporary home for this function. // -//Deprecated: R3FromI is deprecated. +// Deprecated: R3FromI is deprecated. func R3FromI(a V3i) r3.Vec { return r3.Vec{X: float64(a[0]), Y: float64(a[1]), Z: float64(a[2])} } @@ -142,9 +142,9 @@ func minPoly(n int, k float64) MinFunc { // MinPoly creates a n-degree polynomial MinFunc with // parameter k that controls radius of the smoothing function. -// - n<0 or k<=0 undefined output -// - n=0 returns a chamfer-like MinFunc -// - n=1 returns math.Min +// - n<0 or k<=0 undefined output +// - n=0 returns a chamfer-like MinFunc +// - n=1 returns math.Min func MinPoly(n int, k float64) MinFunc { if n < 0 || k <= 0 { // Let users go crazy? @@ -221,11 +221,11 @@ func TwistExtrude(height, twist float64) ExtrudeFunc { func ScaleExtrude(height float64, scale r2.Vec) ExtrudeFunc { inv := r2.Vec{X: 1 / scale.X, Y: 1 / scale.Y} // TODO verify - m := d2.DivElem(inv.Sub(r2.Vec{X: 1, Y: 1}), d2.Elem(height)) // slope + m := d2.DivElem(r2.Sub(inv, r2.Vec{X: 1, Y: 1}), d2.Elem(height)) // slope b := r2.Add(d2.DivElem(inv, d2.Elem(2)), d2.Elem(0.5)) // b := inv.DivScalar(2).AddScalar(0.5) // intercept return func(p r3.Vec) r2.Vec { - return d2.MulElem(r2.Vec{X: p.X, Y: p.Y}, r2.Scale(p.Z, m).Add(b)) + return d2.MulElem(r2.Vec{X: p.X, Y: p.Y}, r2.Add(b, r2.Scale(p.Z, m))) } } @@ -305,9 +305,9 @@ func raycast2(s SDF2, from, dir r2.Vec, scaleAndSigmoid, stepScale, epsilon, max // Computed by sampling it several times inside a box of side 2*eps centered on p. func normal3(s SDF3, p r3.Vec, eps float64) r3.Vec { return r3.Unit(r3.Vec{ - X: s.Evaluate(p.Add(r3.Vec{X: eps})) - s.Evaluate(p.Add(r3.Vec{X: -eps})), - Y: s.Evaluate(p.Add(r3.Vec{Y: eps})) - s.Evaluate(p.Add(r3.Vec{Y: -eps})), - Z: s.Evaluate(p.Add(r3.Vec{Z: eps})) - s.Evaluate(p.Add(r3.Vec{Z: -eps})), + X: s.Evaluate(r3.Add(p, r3.Vec{X: eps})) - s.Evaluate(r3.Add(p, r3.Vec{X: -eps})), + Y: s.Evaluate(r3.Add(p, r3.Vec{Y: eps})) - s.Evaluate(r3.Add(p, r3.Vec{Y: -eps})), + Z: s.Evaluate(r3.Add(p, r3.Vec{Z: eps})) - s.Evaluate(r3.Add(p, r3.Vec{Z: -eps})), }) } @@ -315,8 +315,8 @@ func normal3(s SDF3, p r3.Vec, eps float64) r3.Vec { // Computed by sampling it several times inside a box of side 2*eps centered on p. func normal2(s SDF2, p r2.Vec, eps float64) r2.Vec { return r2.Unit(r2.Vec{ - X: s.Evaluate(p.Add(r2.Vec{X: eps})) - s.Evaluate(p.Add(r2.Vec{X: -eps})), - Y: s.Evaluate(p.Add(r2.Vec{Y: eps})) - s.Evaluate(p.Add(r2.Vec{Y: -eps})), + X: s.Evaluate(r2.Add(p, r2.Vec{X: eps})) - s.Evaluate(r2.Add(p, r2.Vec{X: -eps})), + Y: s.Evaluate(r2.Add(p, r2.Vec{Y: eps})) - s.Evaluate(r2.Add(p, r2.Vec{Y: -eps})), }) } @@ -377,17 +377,17 @@ func (m *map2) ToV2(p V2i) r2.Vec { } else { origin = m.bb.BottomLeft() } - return origin.Add(ofs) + return r2.Add(origin, ofs) } // ToV2i converts 2d region float coordinates to grid integer coordinates. func (m *map2) ToV2i(p r2.Vec) V2i { var v r2.Vec if m.flipy { - v = p.Sub(m.bb.TopLeft()) + v = r2.Sub(p, m.bb.TopLeft()) v.Y = -v.Y } else { - v = p.Sub(m.bb.BottomLeft()) + v = r2.Sub(p, m.bb.BottomLeft()) } return R2ToI(d2.DivElem(v, m.delta)) // v.Div(m.delta).ToV2i() }