pixel icon indicating copy to clipboard operation
pixel copied to clipboard

Optimize design of Target/Triangles/Picture pattern

Open faiface opened this issue 6 years ago • 1 comments

The current core pattern of Pixel has a few weak points.

  1. Triangles interface method set is not optimal. SetLen is only used to either clear the triangles, or when appending. Appending must consist of three steps: set length, slice and update, which is way too much.
  2. Triangles properties interfaces, such as TrianglesPosition and TrianglesColor are completely useless, because using them directly is insanely slow (because they operate on indices). Only fast paths with TrianglesData and so on are used in real situations.
  3. Naming is a bit unclear.

To address all of these issues, I propose to change the core interfaces as follows:

type Triangles interface {
	Len() int
	Slice(i, j int) Triangles
	Append(src Triangles)
	Copy(src Triangles) (n int)
	Clone() Triangles
}

type TrianglesDrawer interface {
	Triangles
	Draw()
}

type TrianglesPosition2D interface {
	CopyPosition2D(dst []float64, stride int) (n int)
}

type TrianglesColorRGBA interface {
	CopyColorRGBA(dst []float64, stride int) (n int)
}

type TrianglesPicture2D interface {
	CopyPicture2D(dst []float64, stride int) (n int)
}

These are changes regarding triangles, Picture interface needs to be rethought too, I need to figure it out.

faiface avatar Jul 16 '17 20:07 faiface

@faiface how close are you to releasing this feature? I was reading through the code for TrianglesData and it does not look too good from the performance point of view (too many potential heap allocations). I cannot suggest anything else than the rewrite you propose here.

Can you share some good news? :)

ysmolski avatar Sep 05 '18 19:09 ysmolski