Skip to content

Commit

Permalink
Merge pull request #338 from cogentcore/math32-from-point
Browse files Browse the repository at this point in the history
Update to core rename of math32.Vector2FromPoint to math32.FromPoint
  • Loading branch information
rcoreilly authored Aug 19, 2024
2 parents ec4d4c9 + 7cccf50 commit d8c6b6e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
22 changes: 11 additions & 11 deletions canvas/align.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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 {
Expand All @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions canvas/manip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions canvas/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions canvas/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
26 changes: 13 additions & 13 deletions canvas/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit d8c6b6e

Please sign in to comment.