pixel
pixel copied to clipboard
Optimize design of Target/Triangles/Picture pattern
The current core pattern of Pixel has a few weak points.
-
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. - Triangles properties interfaces, such as
TrianglesPosition
andTrianglesColor
are completely useless, because using them directly is insanely slow (because they operate on indices). Only fast paths withTrianglesData
and so on are used in real situations. - 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 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? :)