Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
eliminate usage of deprecated r3/r2 Vec methods
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Nov 8, 2022
1 parent ea867bb commit 1f8a536
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 94 deletions.
2 changes: 1 addition & 1 deletion form2/must2/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion form2/must2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
50 changes: 25 additions & 25 deletions form2/must2/poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
12 changes: 6 additions & 6 deletions form3/must3/cylinders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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
}
Expand All @@ -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..
Expand Down
2 changes: 1 addition & 1 deletion form3/must3/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
16 changes: 6 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -96,17 +93,18 @@ 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=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
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=
Expand All @@ -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=
Expand All @@ -134,16 +132,14 @@ 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=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
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=
Expand Down
10 changes: 5 additions & 5 deletions internal/d2/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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))
}

Expand All @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions internal/d2/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/d3/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand All @@ -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}
}

Expand Down
Loading

0 comments on commit 1f8a536

Please sign in to comment.