Skip to content

Commit

Permalink
Correct triangle size calculation for ByteBuffer cursors
Browse files Browse the repository at this point in the history
Fix #38
  • Loading branch information
io7m committed Jan 25, 2017
1 parent 73fe3a3 commit 9aaf72b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
9 changes: 8 additions & 1 deletion README-CHANGES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<c:project>io7m-smfj</c:project>

<c:release c:ticket-system="com.github.io7m.smf">
<c:date>2017-01-24</c:date>
<c:date>2017-01-25</c:date>
<c:version>0.8.0</c:version>

<c:item>
Expand All @@ -12,6 +12,13 @@
<c:ticket>37</c:ticket>
<c:summary>Change bytebuffer API to allow failures; introduce a codebase-wide general error type.</c:summary>
</c:item>

<c:item>
<c:date>2017-01-25</c:date>
<c:type-code-fix/>
<c:ticket>38</c:ticket>
<c:summary>Correct triangle size calculation for ByteBuffer cursors.</c:summary>
</c:item>
</c:release>

<c:release c:ticket-system="com.github.io7m.smf">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@ public interface SMFByteBufferPackedTrianglesType
int triangleIndexSizeBits();

/**
* @return The size in bits of a single triangle
* @return The size in octets of a single triangle index
*/

@Value.Lazy
default int triangleSizeBits()
default int triangleIndexSizeOctets()
{
return Math.multiplyExact(this.triangleIndexSizeBits(), 3);
return this.triangleIndexSizeBits() / 8;
}

/**
* @return The size in octets of a single triangle
* @return The size in bits of a single triangle
*/

@Value.Lazy
default int triangleSizeOctets()
default int triangleSizeBits()
{
return this.triangleSizeBits() / 8;
return Math.multiplyExact(this.triangleIndexSizeBits(), 3);
}

/**
* @return The size in octets of a single triangle index
* @return The size in octets of a single triangle
*/

@Value.Lazy
default int triangleIndexSizeOctets()
default int triangleSizeOctets()
{
return this.triangleIndexSizeBits() / 8;
return Math.multiplyExact(this.triangleIndexSizeOctets(), 3);
}

/**
Expand All @@ -101,7 +101,7 @@ default JPRACursor1DType<SMFByteBufferIntegerUnsigned3Type> cursor()
this.byteBuffer(),
this.triangleIndexSizeBits(),
0,
Math.multiplyExact(this.triangleSizeOctets(), 3));
this.triangleSizeOctets());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.io7m.jtensors.VectorM3L;
import com.io7m.jtensors.VectorM4D;
import com.io7m.jtensors.VectorM4L;
import com.io7m.jtensors.VectorWritable3LType;
import com.io7m.junreachable.UnreachableCodeException;
import com.io7m.smfj.bytebuffer.SMFByteBufferCursors;
import com.io7m.smfj.bytebuffer.SMFByteBufferFloat1Type;
Expand Down Expand Up @@ -2335,6 +2336,13 @@ public void testTriangle8()
Assert.assertEquals(0L, (long) b.get(0));
Assert.assertEquals(1L, (long) b.get(1));
Assert.assertEquals(2L, (long) b.get(2));

final JPRACursor1DType<SMFByteBufferIntegerUnsigned3Type> c = t.cursor();
final VectorM3L out = new VectorM3L();
c.getElementView().get3UL(out);
Assert.assertEquals(0L, out.getXL());
Assert.assertEquals(1L, out.getYL());
Assert.assertEquals(2L, out.getZL());
}

@Test
Expand All @@ -2347,6 +2355,13 @@ public void testTriangle16()
Assert.assertEquals(0L, (long) b.getChar(0));
Assert.assertEquals(1L, (long) b.getChar(2));
Assert.assertEquals(2L, (long) b.getChar(4));

final JPRACursor1DType<SMFByteBufferIntegerUnsigned3Type> c = t.cursor();
final VectorM3L out = new VectorM3L();
c.getElementView().get3UL(out);
Assert.assertEquals(0L, out.getXL());
Assert.assertEquals(1L, out.getYL());
Assert.assertEquals(2L, out.getZL());
}

@Test
Expand All @@ -2359,6 +2374,13 @@ public void testTriangle32()
Assert.assertEquals(0L, (long) b.getInt(0));
Assert.assertEquals(1L, (long) b.getInt(4));
Assert.assertEquals(2L, (long) b.getInt(8));

final JPRACursor1DType<SMFByteBufferIntegerUnsigned3Type> c = t.cursor();
final VectorM3L out = new VectorM3L();
c.getElementView().get3UL(out);
Assert.assertEquals(0L, out.getXL());
Assert.assertEquals(1L, out.getYL());
Assert.assertEquals(2L, out.getZL());
}

@Test
Expand All @@ -2371,6 +2393,13 @@ public void testTriangle64()
Assert.assertEquals(0L, b.getLong(0));
Assert.assertEquals(1L, b.getLong(8));
Assert.assertEquals(2L, b.getLong(16));

final JPRACursor1DType<SMFByteBufferIntegerUnsigned3Type> c = t.cursor();
final VectorM3L out = new VectorM3L();
c.getElementView().get3UL(out);
Assert.assertEquals(0L, out.getXL());
Assert.assertEquals(1L, out.getYL());
Assert.assertEquals(2L, out.getZL());
}

@Test
Expand Down

0 comments on commit 9aaf72b

Please sign in to comment.