Comments (3)
Found quick non-duplicating solution, seems like it works. Needs testing thought.
template opDispatch(string s) if (valid(s))
{
static if (s.length == 1)
{
enum i = ["x":0, "y":1, "z":2, "w":3,
"r":0, "g":1, "b":2, "a":3,
"s":0, "t":1, "p":2, "q":3][s];
@property auto ref opDispatch(this X)()
{
return arrayof[i];
}
@property auto ref opDispatch(this X, V)(auto ref V v)
{
return arrayof[i] = v;
}
}
else
static if (s.length <= 4)
{
@property auto ref opDispatch(this X)()
{
auto extend(string s)
{
while (s.length < 4)
s ~= s[$-1];
return s;
}
enum p = extend(s);
enum i = (char c) => ['x':0, 'y':1, 'z':2, 'w':3,
'r':0, 'g':1, 'b':2, 'a':3,
's':0, 't':1, 'p':2, 'q':3][c];
enum i0 = i(p[0]),
i1 = i(p[1]),
i2 = i(p[2]),
i3 = i(p[3]);
static if (s.length == 4)
return Vector!(T,4)(arrayof[i0], arrayof[i1], arrayof[i2], arrayof[i3]);
else static if (s.length == 3)
return Vector!(T,3)(arrayof[i0], arrayof[i1], arrayof[i2]);
else static if (s.length == 2)
return Vector!(T,2)(arrayof[i0], arrayof[i1]);
}
}
}
from dlib.
Works for me as well, though my code is nowhere near being a stress-test. I'll check if any other methods have this problem.
from dlib.
OK, did some tests, compiled my current projects with this, seems fine. Committing.
from dlib.
Related Issues (20)
- Quaternion!T.rotationAxis is incorrect.
- Iterating over dictionary HOT 1
- Make dlib entirely GC-free
- dlib error messages on dub build HOT 3
- HTTP client HOT 1
- DMD 2.088.0 deprecations
- dlib.text.unmanagedstring.String should be always null-terminated
- Rendering text on canvas HOT 1
- Audio module HOT 7
- Thread synchronization HOT 1
- Unable to build a project with the dlib dependency HOT 2
- Get rid of toStringz in dlib.filesystem.stdfs
- Build error on Windows HOT 1
- Base64 to image HOT 2
- linker error with BigInt.toHash() HOT 4
- image.d(288): Range violation HOT 2
- Increase coverage
- File-based image decoding functions should use ArrayStream internally
- Can't open jpg images with "Progressive DCT, Huffman coding" encoding HOT 1
- 1D and 3D textures support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dlib.