From 97fb33103656f600d5282a1f21a6a3ba4611dbeb Mon Sep 17 00:00:00 2001 From: Kai O'Reilly Date: Mon, 19 Aug 2024 14:47:14 -0700 Subject: [PATCH 1/2] update to rename of math32.Vector2FromPoint to math32.FromPoint --- canvas/align.go | 22 +++++++++++----------- canvas/manip.go | 14 +++++++------- canvas/path.go | 12 ++++++------ canvas/select.go | 12 ++++++------ canvas/svg.go | 26 +++++++++++++------------- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/canvas/align.go b/canvas/align.go index 15a14325..ff6ba9ef 100644 --- a/canvas/align.go +++ b/canvas/align.go @@ -149,9 +149,9 @@ func (vv *Canvas) AlignMin(aa AlignAnchors, dim math32.Dims, act string) { } sng := sn.AsNodeBase() bb := sng.BBox.Sub(svoff) - del := math32.Vector2FromPoint(abb.Min.Sub(bb.Min)) + del := math32.FromPoint(abb.Min.Sub(bb.Min)) del.SetDim(odim, 0) - sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.Vector2FromPoint(bb.Min)) + sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.FromPoint(bb.Min)) } sv.UpdateView(true) vv.ChangeMade() @@ -174,9 +174,9 @@ func (vv *Canvas) AlignMinAnchor(aa AlignAnchors, dim math32.Dims, act string) { } sng := sn.AsNodeBase() bb := sng.BBox.Sub(svoff) - del := math32.Vector2FromPoint(abb.Max.Sub(bb.Min)) + del := math32.FromPoint(abb.Max.Sub(bb.Min)) del.SetDim(odim, 0) - sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.Vector2FromPoint(bb.Min)) + sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.FromPoint(bb.Min)) } sv.UpdateView(true) vv.ChangeMade() @@ -199,9 +199,9 @@ func (vv *Canvas) AlignMax(aa AlignAnchors, dim math32.Dims, act string) { } sng := sn.AsNodeBase() bb := sng.BBox.Sub(svoff) - del := math32.Vector2FromPoint(abb.Max.Sub(bb.Max)) + del := math32.FromPoint(abb.Max.Sub(bb.Max)) del.SetDim(odim, 0) - sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.Vector2FromPoint(bb.Min)) + sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.FromPoint(bb.Min)) } sv.UpdateView(true) vv.ChangeMade() @@ -224,9 +224,9 @@ func (vv *Canvas) AlignMaxAnchor(aa AlignAnchors, dim math32.Dims, act string) { } sng := sn.AsNodeBase() bb := sng.BBox.Sub(svoff) - del := math32.Vector2FromPoint(abb.Min.Sub(bb.Max)) + del := math32.FromPoint(abb.Min.Sub(bb.Max)) del.SetDim(odim, 0) - sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.Vector2FromPoint(bb.Min)) + sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.FromPoint(bb.Min)) } sv.UpdateView(true) vv.ChangeMade() @@ -241,7 +241,7 @@ func (vv *Canvas) AlignCenter(aa AlignAnchors, dim math32.Dims, act string) { svoff := sv.Root().BBox.Min sv.UndoSave(act, es.SelectedNamesString()) abb, an := vv.AlignAnchorBBox(aa) - ctr := math32.Vector2FromPoint(abb.Min.Add(abb.Max)).MulScalar(0.5) + ctr := math32.FromPoint(abb.Min.Add(abb.Max)).MulScalar(0.5) sc := math32.Vec2(1, 1) odim := math32.OtherDim(dim) for sn := range es.Selected { @@ -250,10 +250,10 @@ func (vv *Canvas) AlignCenter(aa AlignAnchors, dim math32.Dims, act string) { } sng := sn.AsNodeBase() bb := sng.BBox.Sub(svoff) - nctr := math32.Vector2FromPoint(bb.Min.Add(bb.Max)).MulScalar(0.5) + nctr := math32.FromPoint(bb.Min.Add(bb.Max)).MulScalar(0.5) del := ctr.Sub(nctr) del.SetDim(odim, 0) - sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.Vector2FromPoint(bb.Min)) + sn.ApplyDeltaTransform(vv.SSVG(), del, sc, 0, math32.FromPoint(bb.Min)) } sv.UpdateView(true) vv.ChangeMade() diff --git a/canvas/manip.go b/canvas/manip.go index d85214d4..46c44b5d 100644 --- a/canvas/manip.go +++ b/canvas/manip.go @@ -54,7 +54,7 @@ func (sv *SVG) ManipDone() { // GridDots returns the current grid spacing and offsets in dots. func (sv *SVG) GridDots() (float32, math32.Vector2) { - svoff := math32.Vector2FromPoint(sv.Geom.ContentBBox.Min) + svoff := math32.FromPoint(sv.Geom.ContentBBox.Min) grid := sv.GridEff if grid <= 0 { grid = 12 @@ -303,9 +303,9 @@ func (sv *SVG) DragMove(e events.Event) { sv.GatherAlignPoints() } - svoff := math32.Vector2FromPoint(sv.Geom.ContentBBox.Min) - spt := math32.Vector2FromPoint(es.DragStartPos) - mpt := math32.Vector2FromPoint(e.Pos()) + svoff := math32.FromPoint(sv.Geom.ContentBBox.Min) + spt := math32.FromPoint(es.DragStartPos) + mpt := math32.FromPoint(e.Pos()) if e.HasAnyModifier(key.Control) { mpt, _ = sv.ConstrainPoint(spt, mpt) } @@ -372,8 +372,8 @@ func (sv *SVG) SpriteReshapeDrag(sp Sprites, e events.Event) { stpos := es.DragSelectStartBBox.Min bbX, bbY := ReshapeBBoxPoints(sp) - spt := math32.Vector2FromPoint(es.DragStartPos) - mpt := math32.Vector2FromPoint(e.Pos()) + spt := math32.FromPoint(es.DragStartPos) + mpt := math32.FromPoint(e.Pos()) diag := false if e.HasAnyModifier(key.Control) && (bbX != BBCenter && bbY != BBMiddle) { mpt, diag = sv.ConstrainPoint(spt, mpt) @@ -458,7 +458,7 @@ func (sv *SVG) SpriteRotateDrag(sp Sprites, delta image.Point) { if !es.InAction() { sv.ManipStart(Rotate, es.SelectedNamesString()) } - dv := math32.Vector2FromPoint(delta) + dv := math32.FromPoint(delta) pt := es.DragSelectStartBBox.Min ctr := es.DragSelectStartBBox.Min.Add(es.DragSelectStartBBox.Max).MulScalar(.5) var dx, dy float32 diff --git a/canvas/path.go b/canvas/path.go index d0391f43..2e336f33 100644 --- a/canvas/path.go +++ b/canvas/path.go @@ -128,7 +128,7 @@ type PathNode struct { // PathNodes returns the PathNode data for given path data, and a list of indexes where commands start func (sv *SVG) PathNodes(path *svg.Path) ([]*PathNode, []int) { - svoff := math32.Vector2FromPoint(sv.Geom.ContentBBox.Min) + svoff := math32.FromPoint(sv.Geom.ContentBBox.Min) pxf := path.ParTransform(true) // include self lstCmdIndex := 0 @@ -229,7 +229,7 @@ func (sv *SVG) NodeSpriteEvent(idx int, et events.Type, d any) { func (sv *SVG) PathNodeSetOnePoint(path *svg.Path, pts []*PathNode, pidx int, dv math32.Vector2, svoff math32.Vector2) { for i := pidx; i < len(pts); i++ { pn := pts[i] - wbmin := math32.Vector2FromPoint(path.BBox.Min) + wbmin := math32.FromPoint(path.BBox.Min) pt := wbmin.Sub(svoff) xf, lpt := path.DeltaTransform(dv, math32.Vec2(1, 1), 0, pt, true) // include self npt := xf.MulVector2AsPointCenter(pn.Cp, lpt) // transform point to new abs coords @@ -280,13 +280,13 @@ func (sv *SVG) SpriteNodeDrag(idx int, win *core.Window, me *mouse.DragEvent) { sv.GatherAlignPoints() } - svoff := math32.Vector2FromPoint(sv.Geom.ContentBBox.Min) + svoff := math32.FromPoint(sv.Geom.ContentBBox.Min) pn := es.PathNodes[idx] InactivateSprites(sv, SpAlignMatch) - spt := math32.Vector2FromPoint(es.DragStartPos) - mpt := math32.Vector2FromPoint(me.Where) + spt := math32.FromPoint(es.DragStartPos) + mpt := math32.FromPoint(me.Where) if me.HasAnyModifier(key.Control) { mpt, _ = sv.ConstrainPoint(spt, mpt) @@ -297,7 +297,7 @@ func (sv *SVG) SpriteNodeDrag(idx int, win *core.Window, me *mouse.DragEvent) { es.DragCurPos = mpt.ToPoint() mdel := es.DragCurPos.Sub(es.DragStartPos) - dv := math32.Vector2FromPoint(mdel) + dv := math32.FromPoint(mdel) nwc := pn.WinPt.Add(dv) // new window coord sv.PathNodeSetOnePoint(es.ActivePath, es.PathNodes, idx, dv, svoff) diff --git a/canvas/select.go b/canvas/select.go index 8e743df0..5ce09ed4 100644 --- a/canvas/select.go +++ b/canvas/select.go @@ -215,8 +215,8 @@ func (sv *SVG) SetSelSpritePos() { // SetBBoxSpritePos sets positions of given type of sprites func (sv *SVG) SetBBoxSpritePos(typ Sprites, idx int, bbox math32.Box2) { - bbox.Min.SetAdd(math32.Vector2FromPoint(sv.Geom.ContentBBox.Min)) - bbox.Max.SetAdd(math32.Vector2FromPoint(sv.Geom.ContentBBox.Min)) + bbox.Min.SetAdd(math32.FromPoint(sv.Geom.ContentBBox.Min)) + bbox.Max.SetAdd(math32.FromPoint(sv.Geom.ContentBBox.Min)) _, spsz := HandleSpriteSize(1) midX := int(0.5 * (bbox.Min.X + bbox.Max.X - float32(spsz.X))) @@ -385,8 +385,8 @@ func (gv *Canvas) SelectRotate(deg float32) { rot := math32.DegToRad(deg) for sn := range es.Selected { sng := sn.AsNodeBase() - sz := math32.Vector2FromPoint(sng.BBox.Size()) - mn := math32.Vector2FromPoint(sng.BBox.Min.Sub(svoff)) + sz := math32.FromPoint(sng.BBox.Size()) + mn := math32.FromPoint(sng.BBox.Min.Sub(svoff)) ctr := mn.Add(sz.MulScalar(.5)) sn.ApplyDeltaTransform(sv.SVG, del, sc, rot, ctr) } @@ -407,8 +407,8 @@ func (gv *Canvas) SelectScale(scx, scy float32) { sc := math32.Vec2(scx, scy) for sn := range es.Selected { sng := sn.AsNodeBase() - sz := math32.Vector2FromPoint(sng.BBox.Size()) - mn := math32.Vector2FromPoint(sng.BBox.Min.Sub(svoff)) + sz := math32.FromPoint(sng.BBox.Size()) + mn := math32.FromPoint(sng.BBox.Min.Sub(svoff)) ctr := mn.Add(sz.MulScalar(.5)) sn.ApplyDeltaTransform(sv.SVG, del, sc, 0, ctr) } diff --git a/canvas/svg.go b/canvas/svg.go index c9a926ff..11f6f21f 100644 --- a/canvas/svg.go +++ b/canvas/svg.go @@ -131,7 +131,7 @@ func (sv *SVG) Init() { es.SelectNoDrag = false switch { - case es.HasSelected() && es.SelectBBox.ContainsPoint(math32.Vector2FromPoint(e.Pos())): + case es.HasSelected() && es.SelectBBox.ContainsPoint(math32.FromPoint(e.Pos())): // note: this absorbs potential secondary selections within selection -- handled // on release below, if nothing else happened es.SelectNoDrag = true @@ -401,7 +401,7 @@ func (sv *SVG) TransformAllLeaves(trans math32.Vector2, scale math32.Vector2, ro // ZoomToPage sets the scale to fit the current viewbox func (sv *SVG) ZoomToPage(width bool) { - vb := math32.Vector2FromPoint(sv.Root().BBox.Size()) + vb := math32.FromPoint(sv.Root().BBox.Size()) if vb == (math32.Vector2{}) { return } @@ -420,7 +420,7 @@ func (sv *SVG) ZoomToPage(width bool) { // ZoomToContents sets the scale to fit the current contents into view func (sv *SVG) ZoomToContents(width bool) { - vb := math32.Vector2FromPoint(sv.Root().BBox.Size()) + vb := math32.FromPoint(sv.Root().BBox.Size()) if vb == (math32.Vector2{}) { return } @@ -485,7 +485,7 @@ func (sv *SVG) ZoomAt(pt image.Point, delta float32) { nsc := sv.SVG.Scale * sc - mpt := math32.Vector2FromPoint(pt) + mpt := math32.FromPoint(pt) lpt := mpt.DivScalar(sv.SVG.Scale).Sub(sv.SVG.Translate) // point in drawing coords dt := lpt.Add(sv.SVG.Translate).MulScalar((nsc - sv.SVG.Scale) / nsc) // delta from zooming @@ -757,7 +757,7 @@ func NewSVGElement[T tree.NodeValue](sv *SVG) *T { func NewSVGElementDrag[T tree.NodeValue](sv *SVG, start, end image.Point) *T { minsz := float32(10) es := sv.EditState() - dv := math32.Vector2FromPoint(end.Sub(start)) + dv := math32.FromPoint(end.Sub(start)) if !es.InAction() && math32.Abs(dv.X) < minsz && math32.Abs(dv.Y) < minsz { // fmt.Println("dv under min:", dv, minsz) return nil @@ -766,8 +766,8 @@ func NewSVGElementDrag[T tree.NodeValue](sv *SVG, start, end image.Point) *T { n := NewSVGElement[T](sv) sn := any(n).(svg.Node) xfi := sv.Root().Paint.Transform.Inverse() - svoff := math32.Vector2FromPoint(sv.Geom.ContentBBox.Min) - pos := math32.Vector2FromPoint(start).Sub(svoff) + svoff := math32.FromPoint(sv.Geom.ContentBBox.Min) + pos := math32.FromPoint(start).Sub(svoff) pos = xfi.MulVector2AsPoint(pos) sn.SetNodePos(pos) sz := dv.Abs().Max(math32.Vector2Scalar(minsz / 2)) @@ -792,15 +792,15 @@ func (sv *SVG) NewText(start, end image.Point) svg.Node { tspan.Text = "Text" tspan.Width = 200 xfi := sv.Root().Paint.Transform.Inverse() - svoff := math32.Vector2FromPoint(sv.Geom.ContentBBox.Min) - pos := math32.Vector2FromPoint(start).Sub(svoff) + svoff := math32.FromPoint(sv.Geom.ContentBBox.Min) + pos := math32.FromPoint(start).Sub(svoff) // minsz := float32(20) pos.Y += 20 // todo: need the font size.. pos = xfi.MulVector2AsPoint(pos) sv.Canvas.SetTextPropertiesNode(n, es.Text.TextProperties()) // nr.Pos = pos // tspan.Pos = pos - // // dv := math32.Vector2FromPoint(end.Sub(start)) + // // dv := math32.FromPoint(end.Sub(start)) // // sz := dv.Abs().Max(math32.NewVector2Scalar(minsz / 2)) // nr.Width = 100 // tspan.Width = 100 @@ -814,7 +814,7 @@ func (sv *SVG) NewText(start, end image.Point) svg.Node { func (sv *SVG) NewPath(start, end image.Point) *svg.Path { minsz := float32(10) es := sv.EditState() - dv := math32.Vector2FromPoint(end.Sub(start)) + dv := math32.FromPoint(end.Sub(start)) if !es.InAction() && math32.Abs(dv.X) < minsz && math32.Abs(dv.Y) < minsz { return nil } @@ -823,8 +823,8 @@ func (sv *SVG) NewPath(start, end image.Point) *svg.Path { // sv.SetFullReRender() n := NewSVGElement[svg.Path](sv) xfi := sv.Root().Paint.Transform.Inverse() - // svoff := math32.Vector2FromPoint(sv.Geom.ContentBBox.Min) - pos := math32.Vector2FromPoint(start) + // svoff := math32.FromPoint(sv.Geom.ContentBBox.Min) + pos := math32.FromPoint(start) pos = xfi.MulVector2AsPoint(pos) sz := dv // sz := dv.Abs().Max(math32.NewVector2Scalar(minsz / 2)) From 7cccf50864c61b87519ff10d9c7faa89fcf9351e Mon Sep 17 00:00:00 2001 From: Kai O'Reilly Date: Mon, 19 Aug 2024 14:53:31 -0700 Subject: [PATCH 2/2] update core --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7366ff65..9e4050a8 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module cogentcore.org/cogent go 1.22 require ( - cogentcore.org/core v0.3.3-0.20240819015726-be2a0d3e4f3c + cogentcore.org/core v0.3.3-0.20240819215147-49698295dd89 github.com/aandrew-me/tgpt/v2 v2.7.2 github.com/alecthomas/chroma/v2 v2.13.0 github.com/bogdanfinn/fhttp v0.5.27 diff --git a/go.sum b/go.sum index 3516b1c4..86f98976 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -cogentcore.org/core v0.3.3-0.20240819015726-be2a0d3e4f3c h1:KekH9PHfhGXV31mwVxU8CCT1GQC+CpgoZH0gU5tP0kY= -cogentcore.org/core v0.3.3-0.20240819015726-be2a0d3e4f3c/go.mod h1:dg3uRsPcd8S1ZYvRD2TztCtjopRkrB5V/lbl54xsQd4= +cogentcore.org/core v0.3.3-0.20240819215147-49698295dd89 h1:ZSHm3pLiuptj1g7s7oobNNFDbwysVo1bxFiYZVIrU60= +cogentcore.org/core v0.3.3-0.20240819215147-49698295dd89/go.mod h1:dg3uRsPcd8S1ZYvRD2TztCtjopRkrB5V/lbl54xsQd4= github.com/Bios-Marcel/wastebasket v0.0.4-0.20240213135800-f26f1ae0a7c4 h1:6lx9xzJAhdjq0LvVfbITeC3IH9Fzvo1aBahyPu2FuG8= github.com/Bios-Marcel/wastebasket v0.0.4-0.20240213135800-f26f1ae0a7c4/go.mod h1:FChzXi1izqzdPb6BiNZmcZLGyTYiT61iGx9Rxx9GNeI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=