Vector3 ComputePosition(int segmentIndex) { Vector3 position; Vector3 offset = transform.position; Vector3 originalScale = transform.localScale; position = originalScale / NumberOfSegments; position *= (-.5f + segmentIndex); position += (-.5f * originalScale); position = VectorOps.Multiply(position, new Vector3(1f, 0f, 0f)); position += offset; return(position); }
void OnDrawGizmosSelected() { Vector3 offset = transform.position; Vector3 originalScale = transform.localScale; Vector3 segmentScale = VectorOps.Multiply(originalScale, new Vector3(1f / NumberOfSegments, 1f, 1f)); Gizmos.color = Color.yellow; for (int i = 0; i < NumberOfSegments; i++) { Vector3 position; position = originalScale / NumberOfSegments; position *= (.5f + i); position += -(.5f * originalScale); position = VectorOps.Multiply(position, new Vector3(1f, 0f, 0f)); position += offset; Gizmos.DrawWireCube(position, segmentScale); } }
public void Multiply() { // arrange var vectorCount = Vector <int> .Count; // Itentionally break the alignment for the Vector operation to test more code. var bufferSize = 10 + (vectorCount / 2); var targetData = new int[bufferSize]; var src1Data = Enumerable.Range(0, bufferSize).ToArray(); var src2Data = Enumerable.Range(0, bufferSize).ToArray(); var target = new DataAndLayout <int>(targetData, new FastAccess(new Layout(new int[] { bufferSize }, 0, new int[] { 1 }))); var src1 = new DataAndLayout <int>(src1Data, new FastAccess(new Layout(new int[] { bufferSize }, 0, new int[] { 1 }))); var src2 = new DataAndLayout <int>(src2Data, new FastAccess(new Layout(new int[] { bufferSize }, 0, new int[] { 1 }))); // action VectorOps.Multiply(target, src1, src2); // assert var expectedData = src1Data.Select(x => x * x).ToArray(); Assert.IsTrue(Enumerable.SequenceEqual(expectedData, targetData)); }
Vector3 ComputeSegmentScale() { return(VectorOps.Multiply(transform.localScale, new Vector3(1f / NumberOfSegments, 1f, 1f))); }