~eliasnaur/gio-patches

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4 3

[PATCH gio] io/router: use f32.Rectangle in areaOp

~pierrec
Details
Message ID
<161411539567.28528.8411493416571596383-0@git.sr.ht>
DKIM signature
missing
Download raw message
Patch: +17 -19
From: pierre <pierre.curto@gmail.com>

Also introduce a function to decode a float32 from ops.

Signed-off-by: pierre <pierre.curto@gmail.com>
---
 io/router/pointer.go | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/io/router/pointer.go b/io/router/pointer.go
index ab9348b..ef56841 100644
--- a/io/router/pointer.go
+++ b/io/router/pointer.go
@@ -4,7 +4,6 @@ package router

import (
	"encoding/binary"
	"image"

	"gioui.org/f32"
	"gioui.org/internal/opconst"
@@ -64,7 +63,7 @@ type pointerHandler struct {

type areaOp struct {
	kind areaKind
	rect image.Rectangle
	rect f32.Rectangle
}

type areaNode struct {
@@ -409,19 +408,22 @@ func searchTag(tags []event.Tag, tag event.Tag) (int, bool) {
	return 0, false
}

func opDecodeFloat32(d []byte) float32 {
	return float32(binary.LittleEndian.Uint32(d))
}

func (op *areaOp) Decode(d []byte) {
	if opconst.OpType(d[0]) != opconst.TypeArea {
		panic("invalid op")
	}
	bo := binary.LittleEndian
	rect := image.Rectangle{
		Min: image.Point{
			X: int(int32(bo.Uint32(d[2:]))),
			Y: int(int32(bo.Uint32(d[6:]))),
	rect := f32.Rectangle{
		Min: f32.Point{
			X: opDecodeFloat32(d[2:]),
			Y: opDecodeFloat32(d[6:]),
		},
		Max: image.Point{
			X: int(int32(bo.Uint32(d[10:]))),
			Y: int(int32(bo.Uint32(d[14:]))),
		Max: f32.Point{
			X: opDecodeFloat32(d[10:]),
			Y: opDecodeFloat32(d[14:]),
		},
	}
	*op = areaOp{
@@ -431,19 +433,15 @@ func (op *areaOp) Decode(d []byte) {
}

func (op *areaOp) Hit(pos f32.Point) bool {
	min := f32.Point{
		X: float32(op.rect.Min.X),
		Y: float32(op.rect.Min.Y),
	}
	pos = pos.Sub(min)
	pos = pos.Sub(op.rect.Min)
	size := op.rect.Size()
	switch op.kind {
	case areaRect:
		return 0 <= pos.X && pos.X < float32(size.X) &&
			0 <= pos.Y && pos.Y < float32(size.Y)
		return 0 <= pos.X && pos.X < size.X &&
			0 <= pos.Y && pos.Y < size.Y
	case areaEllipse:
		rx := float32(size.X) / 2
		ry := float32(size.Y) / 2
		rx := size.X / 2
		ry := size.Y / 2
		xh := pos.X - rx
		yk := pos.Y - ry
		// The ellipse function works in all cases because
-- 
2.30.1

[gio/patches] build success

builds.sr.ht
Details
Message ID
<C9H8M0JCFVXE.3KPG3EGMDLE46@cirno>
In-Reply-To
<161411539567.28528.8411493416571596383-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
gio/patches: SUCCESS in 21m27s

[io/router: use f32.Rectangle in areaOp][0] from [~pierrec][1]

[0]: https://lists.sr.ht/~eliasnaur/gio-patches/patches/20486
[1]: mailto:pierre.curto@gmail.com

✓ #436720 SUCCESS gio/patches/freebsd.yml https://builds.sr.ht/~eliasnaur/job/436720
✓ #436721 SUCCESS gio/patches/linux.yml   https://builds.sr.ht/~eliasnaur/job/436721
✓ #436719 SUCCESS gio/patches/apple.yml   https://builds.sr.ht/~eliasnaur/job/436719
✓ #436722 SUCCESS gio/patches/openbsd.yml https://builds.sr.ht/~eliasnaur/job/436722
Details
Message ID
<C9HNEJWKN9XG.2R5H38IJ1R6SR@themachine>
In-Reply-To
<161411539567.28528.8411493416571596383-0@git.sr.ht> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
What's the point? If it is performance, please mention it in the commit
message, preferably with a benchmark.

On Tue Feb 23, 2021 at 22:22, ~pierrec wrote:
> From: pierre <pierre.curto@gmail.com>
>
> Also introduce a function to decode a float32 from ops.
>
> Signed-off-by: pierre <pierre.curto@gmail.com>
> ---
>  io/router/pointer.go | 36 +++++++++++++++++-------------------
>  1 file changed, 17 insertions(+), 19 deletions(-)
>
> diff --git a/io/router/pointer.go b/io/router/pointer.go
> index ab9348b..ef56841 100644
> --- a/io/router/pointer.go
> +++ b/io/router/pointer.go
> @@ -4,7 +4,6 @@ package router
>  
>  import (
>  	"encoding/binary"
> -	"image"
>  
>  	"gioui.org/f32"
>  	"gioui.org/internal/opconst"
> @@ -64,7 +63,7 @@ type pointerHandler struct {
>  
>  type areaOp struct {
>  	kind areaKind
> -	rect image.Rectangle
> +	rect f32.Rectangle
>  }
>  
>  type areaNode struct {
> @@ -409,19 +408,22 @@ func searchTag(tags []event.Tag, tag event.Tag) (int, bool) {
>  	return 0, false
>  }
>  
> +func opDecodeFloat32(d []byte) float32 {
> +	return float32(binary.LittleEndian.Uint32(d))
> +}
> +
>  func (op *areaOp) Decode(d []byte) {
>  	if opconst.OpType(d[0]) != opconst.TypeArea {
>  		panic("invalid op")
>  	}
> -	bo := binary.LittleEndian
> -	rect := image.Rectangle{
> -		Min: image.Point{
> -			X: int(int32(bo.Uint32(d[2:]))),
> -			Y: int(int32(bo.Uint32(d[6:]))),
> +	rect := f32.Rectangle{
> +		Min: f32.Point{
> +			X: opDecodeFloat32(d[2:]),
> +			Y: opDecodeFloat32(d[6:]),
>  		},
> -		Max: image.Point{
> -			X: int(int32(bo.Uint32(d[10:]))),
> -			Y: int(int32(bo.Uint32(d[14:]))),
> +		Max: f32.Point{
> +			X: opDecodeFloat32(d[10:]),
> +			Y: opDecodeFloat32(d[14:]),
>  		},
>  	}
>  	*op = areaOp{
> @@ -431,19 +433,15 @@ func (op *areaOp) Decode(d []byte) {
>  }
>  
>  func (op *areaOp) Hit(pos f32.Point) bool {
> -	min := f32.Point{
> -		X: float32(op.rect.Min.X),
> -		Y: float32(op.rect.Min.Y),
> -	}
> -	pos = pos.Sub(min)
> +	pos = pos.Sub(op.rect.Min)
>  	size := op.rect.Size()
>  	switch op.kind {
>  	case areaRect:
> -		return 0 <= pos.X && pos.X < float32(size.X) &&
> -			0 <= pos.Y && pos.Y < float32(size.Y)
> +		return 0 <= pos.X && pos.X < size.X &&
> +			0 <= pos.Y && pos.Y < size.Y
>  	case areaEllipse:
> -		rx := float32(size.X) / 2
> -		ry := float32(size.Y) / 2
> +		rx := size.X / 2
> +		ry := size.Y / 2
>  		xh := pos.X - rx
>  		yk := pos.Y - ry
>  		// The ellipse function works in all cases because
> -- 
> 2.30.1
Details
Message ID
<CAG3idSfGR4=R7D9ic4RV6BsWz5dp03CsPLSpbRZZ6LHnd+HWSA@mail.gmail.com>
In-Reply-To
<C9HNEJWKN9XG.2R5H38IJ1R6SR@themachine> (view parent)
DKIM signature
pass
Download raw message
Le mer. 24 févr. 2021 à 10:20, Elias Naur <mail@eliasnaur.com> a écrit :
>
> What's the point? If it is performance, please mention it in the commit
> message, preferably with a benchmark.

This is indirectly related to the preparation of the ScrollRange patch.
Will add benchmarks though and resend if they are conclusive (also
slightly less memory footprint for very common struct).


>
> On Tue Feb 23, 2021 at 22:22, ~pierrec wrote:
> > From: pierre <pierre.curto@gmail.com>
> >
> > Also introduce a function to decode a float32 from ops.
> >
> > Signed-off-by: pierre <pierre.curto@gmail.com>
> > ---
> >  io/router/pointer.go | 36 +++++++++++++++++-------------------
> >  1 file changed, 17 insertions(+), 19 deletions(-)
> >
> > diff --git a/io/router/pointer.go b/io/router/pointer.go
> > index ab9348b..ef56841 100644
> > --- a/io/router/pointer.go
> > +++ b/io/router/pointer.go
> > @@ -4,7 +4,6 @@ package router
> >
> >  import (
> >       "encoding/binary"
> > -     "image"
> >
> >       "gioui.org/f32"
> >       "gioui.org/internal/opconst"
> > @@ -64,7 +63,7 @@ type pointerHandler struct {
> >
> >  type areaOp struct {
> >       kind areaKind
> > -     rect image.Rectangle
> > +     rect f32.Rectangle
> >  }
> >
> >  type areaNode struct {
> > @@ -409,19 +408,22 @@ func searchTag(tags []event.Tag, tag event.Tag) (int, bool) {
> >       return 0, false
> >  }
> >
> > +func opDecodeFloat32(d []byte) float32 {
> > +     return float32(binary.LittleEndian.Uint32(d))
> > +}
> > +
> >  func (op *areaOp) Decode(d []byte) {
> >       if opconst.OpType(d[0]) != opconst.TypeArea {
> >               panic("invalid op")
> >       }
> > -     bo := binary.LittleEndian
> > -     rect := image.Rectangle{
> > -             Min: image.Point{
> > -                     X: int(int32(bo.Uint32(d[2:]))),
> > -                     Y: int(int32(bo.Uint32(d[6:]))),
> > +     rect := f32.Rectangle{
> > +             Min: f32.Point{
> > +                     X: opDecodeFloat32(d[2:]),
> > +                     Y: opDecodeFloat32(d[6:]),
> >               },
> > -             Max: image.Point{
> > -                     X: int(int32(bo.Uint32(d[10:]))),
> > -                     Y: int(int32(bo.Uint32(d[14:]))),
> > +             Max: f32.Point{
> > +                     X: opDecodeFloat32(d[10:]),
> > +                     Y: opDecodeFloat32(d[14:]),
> >               },
> >       }
> >       *op = areaOp{
> > @@ -431,19 +433,15 @@ func (op *areaOp) Decode(d []byte) {
> >  }
> >
> >  func (op *areaOp) Hit(pos f32.Point) bool {
> > -     min := f32.Point{
> > -             X: float32(op.rect.Min.X),
> > -             Y: float32(op.rect.Min.Y),
> > -     }
> > -     pos = pos.Sub(min)
> > +     pos = pos.Sub(op.rect.Min)
> >       size := op.rect.Size()
> >       switch op.kind {
> >       case areaRect:
> > -             return 0 <= pos.X && pos.X < float32(size.X) &&
> > -                     0 <= pos.Y && pos.Y < float32(size.Y)
> > +             return 0 <= pos.X && pos.X < size.X &&
> > +                     0 <= pos.Y && pos.Y < size.Y
> >       case areaEllipse:
> > -             rx := float32(size.X) / 2
> > -             ry := float32(size.Y) / 2
> > +             rx := size.X / 2
> > +             ry := size.Y / 2
> >               xh := pos.X - rx
> >               yk := pos.Y - ry
> >               // The ellipse function works in all cases because
> > --
> > 2.30.1
>
Details
Message ID
<C9HQ5SGET7JX.3BRWF0MWQNKUQ@themachine>
In-Reply-To
<CAG3idSfGR4=R7D9ic4RV6BsWz5dp03CsPLSpbRZZ6LHnd+HWSA@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Wed Feb 24, 2021 at 11:00, Pierre Curto wrote:
> Le mer. 24 févr. 2021 à 10:20, Elias Naur <mail@eliasnaur.com> a écrit :
> >
> > What's the point? If it is performance, please mention it in the commit
> > message, preferably with a benchmark.
>
> This is indirectly related to the preparation of the ScrollRange patch.
> Will add benchmarks though and resend if they are conclusive (also
> slightly less memory footprint for very common struct).
>

Smaller footprint how? Isn't image.Rectangle the same size as
f32.Rectangle?

Elias
Reply to thread Export thread (mbox)