DFU Codecs for various libraries
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(joml): codecs for read-only views

kokirigla.de cd6158d9 7e3e481a

verified
+145 -5
+145 -5
grimoire-joml/src/main/java/com/nayrid/grimoire/joml/JomlCodecs.java
··· 29 29 import org.joml.AxisAngle4d; 30 30 import org.joml.AxisAngle4f; 31 31 import org.joml.Matrix2d; 32 + import org.joml.Matrix2dc; 32 33 import org.joml.Matrix2f; 34 + import org.joml.Matrix2fc; 33 35 import org.joml.Matrix3d; 36 + import org.joml.Matrix3dc; 34 37 import org.joml.Matrix3f; 38 + import org.joml.Matrix3fc; 35 39 import org.joml.Matrix4d; 40 + import org.joml.Matrix4dc; 36 41 import org.joml.Matrix4f; 42 + import org.joml.Matrix4fc; 37 43 import org.joml.Quaterniond; 44 + import org.joml.Quaterniondc; 38 45 import org.joml.Quaternionf; 46 + import org.joml.Quaternionfc; 39 47 import org.joml.Vector2L; 48 + import org.joml.Vector2Lc; 40 49 import org.joml.Vector2d; 50 + import org.joml.Vector2dc; 41 51 import org.joml.Vector2f; 52 + import org.joml.Vector2fc; 42 53 import org.joml.Vector2i; 54 + import org.joml.Vector2ic; 43 55 import org.joml.Vector3L; 56 + import org.joml.Vector3Lc; 44 57 import org.joml.Vector3d; 58 + import org.joml.Vector3dc; 45 59 import org.joml.Vector3f; 60 + import org.joml.Vector3fc; 46 61 import org.joml.Vector3i; 62 + import org.joml.Vector3ic; 47 63 48 64 import java.util.List; 65 + import java.util.function.Function; 49 66 50 67 /** 51 68 * Codecs for JOML types. ··· 65 82 vector2d -> List.of(vector2d.x(), vector2d.y())); 66 83 67 84 /** 68 - * Stores a {@link Vector2f} as a list of 2 doubles. 85 + * Stores a {@link Vector2dc} as a list of 2 doubles. 86 + * 87 + * @since 1.0.0 88 + */ 89 + public static final Codec<Vector2dc> VECTOR2DC = VECTOR2D.xmap(Function.identity(), Vector2d::new); 90 + 91 + /** 92 + * Stores a {@link Vector2f} as a list of 2 floats. 69 93 * 70 94 * @since 1.0.0 71 95 */ 72 96 public static final Codec<Vector2f> VECTOR2F = VECTOR2D.xmap(Vector2f::new, Vector2d::new); 73 97 74 98 /** 99 + * Stores a {@link Vector2fc} as a list of 2 floats. 100 + * 101 + * @since 1.0.0 102 + */ 103 + public static final Codec<Vector2fc> VECTOR2FC = VECTOR2F.xmap(Function.identity(), Vector2f::new); 104 + /** 75 105 * Stores a {@link Vector2L} as a list of 2 longs. 76 106 * 77 107 * @since 1.0.0 ··· 80 110 .comapFlatMap(longs -> Grimoire.fixedLength(longs, 2) 81 111 .map(list -> new Vector2L(list.getFirst(), list.getLast())), 82 112 vector2l -> List.of(vector2l.x(), vector2l.y())); 113 + /** 114 + * Stores a {@link Vector2Lc} as a list of 2 longs. 115 + * 116 + * @since 1.0.0 117 + */ 118 + public static final Codec<Vector2Lc> VECTOR2LC = VECTOR2L.xmap(Function.identity(), Vector2L::new); 83 119 84 120 /** 85 121 * Stores a {@link Vector2i} as a list of 2 integers. ··· 90 126 .comapFlatMap(ints -> Grimoire.fixedLength(ints, 2) 91 127 .map(list -> new Vector2i(list.getFirst(), list.getLast())), 92 128 vector2i -> List.of(vector2i.x(), vector2i.y())); 129 + /** 130 + * Stores a {@link Vector2ic} as a list of 2 integers. 131 + * 132 + * @since 1.0.0 133 + */ 134 + public static final Codec<Vector2ic> VECTOR2IC = VECTOR2I.xmap(Function.identity(), Vector2i::new); 93 135 94 136 /** 95 137 * Stores a {@link Vector3d} as a list of 3 doubles. ··· 102 144 vector3d -> List.of(vector3d.x(), vector3d.y(), vector3d.z())); 103 145 104 146 /** 105 - * Stores a {@link Vector3f} as a list of 3 doubles. 147 + * Stores a {@link Vector3dc} as a list of 3 doubles. 148 + * 149 + * @since 1.0.0 150 + */ 151 + public static final Codec<Vector3dc> VECTOR3DC = VECTOR3D.xmap(Function.identity(), Vector3d::new); 152 + 153 + /** 154 + * Stores a {@link Vector3f} as a list of 3 floats. 106 155 * 107 156 * @since 1.0.0 108 157 */ 109 158 public static final Codec<Vector3f> VECTOR3F = VECTOR3D.xmap(Vector3f::new, Vector3d::new); 110 159 111 160 /** 161 + * Stores a {@link Vector3fc} as a list of 3 floats. 162 + * 163 + * @since 1.0.0 164 + */ 165 + public static final Codec<Vector3fc> VECTOR3FC = VECTOR3F.xmap(Function.identity(), Vector3f::new); 166 + 167 + /** 112 168 * Stores a {@link Vector3L} as a list of 3 longs. 113 169 * 114 170 * @since 1.0.0 ··· 119 175 vector3l -> List.of(vector3l.x(), vector3l.y(), vector3l.z())); 120 176 121 177 /** 178 + * Stores a {@link Vector3Lc} as a list of 3 longs. 179 + * 180 + * @since 1.0.0 181 + */ 182 + public static final Codec<Vector3Lc> VECTOR3LC = VECTOR3L.xmap(Function.identity(), Vector3L::new); 183 + 184 + /** 122 185 * Stores a {@link Vector3i} as a list of 3 integers. 123 186 * 124 187 * @since 1.0.0 ··· 127 190 .comapFlatMap(ints -> Grimoire.fixedLength(ints, 3) 128 191 .map(list -> new Vector3i(list.getFirst(), list.get(1), list.getLast())), 129 192 vector3i -> List.of(vector3i.x(), vector3i.y(), vector3i.z())); 193 + 194 + /** 195 + * Stores a {@link Vector3ic} as a list of 3 integers. 196 + * 197 + * @since 1.0.0 198 + */ 199 + public static final Codec<Vector3ic> VECTOR3IC = VECTOR3I.xmap(Function.identity(), Vector3i::new); 130 200 131 201 /** 132 202 * Stores an {@link AxisAngle4d} as an object with {@code angle} and {@code axis} fields. ··· 172 242 }), matrix2d -> List.of(matrix2d.m00, matrix2d.m01, matrix2d.m10, matrix2d.m11)); 173 243 174 244 /** 245 + * Stores a {@link Matrix2d} as a list of 4 doubles in m00, m01, m10, m11 order. 246 + * 247 + * @since 1.0.0 248 + */ 249 + public static final Codec<Matrix2dc> MATRIX2DC = MATRIX2D.xmap(Function.identity(), Matrix2d::new); 250 + 251 + /** 175 252 * Stores a {@link Matrix3d} as a list of 9 doubles in row-major order. 176 253 * 177 254 * @since 1.0.0 ··· 204 281 ); 205 282 206 283 /** 284 + * Stores a {@link Matrix3dc} as a list of 9 doubles in row-major order. 285 + * 286 + * @since 1.0.0 287 + */ 288 + public static final Codec<Matrix3dc> MATRIX3DC = MATRIX3D.xmap(Function.identity(), Matrix3d::new); 289 + 290 + /** 207 291 * Stores a {@link Matrix4d} as a list of 16 doubles in row-major order. 208 292 * 209 293 * @since 1.0.0 ··· 250 334 ); 251 335 252 336 /** 253 - * Stores a {@link Matrix2f} as a list of 4 doubles in m00, m01, m10, m11 order. 337 + * Stores a {@link Matrix4dc} as a list of 16 doubles in row-major order. 338 + * 339 + * @since 1.0.0 340 + */ 341 + public static final Codec<Matrix4dc> MATRIX4DC = MATRIX4D.xmap(Function.identity(), Matrix4d::new); 342 + 343 + /** 344 + * Stores a {@link Matrix2f} as a list of 4 floats in m00, m01, m10, m11 order. 254 345 * 255 346 * @since 1.0.0 256 347 */ ··· 262 353 ), matrix2f -> new Matrix2d(matrix2f.m00, matrix2f.m01, matrix2f.m10, matrix2f.m11)); 263 354 264 355 /** 265 - * Stores a {@link Matrix3f} as a list of 9 doubles in row-major order. 356 + * Stores a {@link Matrix2fc} as a list of 4 floats in m00, m01, m10, m11 order. 357 + * 358 + * @since 1.0.0 359 + */ 360 + public static final Codec<Matrix2fc> MATRIX2FC = MATRIX2F.xmap(Function.identity(), Matrix2f::new); 361 + 362 + /** 363 + * Stores a {@link Matrix3f} as a list of 9 floats in row-major order. 266 364 * 267 365 * @since 1.0.0 268 366 */ ··· 290 388 ); 291 389 292 390 /** 293 - * Stores a {@link Matrix4f} as a list of 16 doubles in row-major order. 391 + * Stores a {@link Matrix3fc} as a list of 9 floats in row-major order. 392 + * 393 + * @since 1.0.0 394 + */ 395 + public static final Codec<Matrix3fc> MATRIX3FC = MATRIX3F.xmap(Function.identity(), Matrix3f::new); 396 + 397 + /** 398 + * Stores a {@link Matrix4f} as a list of 16 floats in row-major order. 294 399 * 295 400 * @since 1.0.0 296 401 */ ··· 332 437 ); 333 438 334 439 /** 440 + * Stores a {@link Matrix4fc} as a list of 16 floats in row-major order. 441 + * 442 + * @since 1.0.0 443 + */ 444 + public static final Codec<Matrix4fc> MATRIX4FC = MATRIX4F.xmap(Function.identity(), Matrix4f::new); 445 + 446 + /** 335 447 * Stores a normalized {@link Quaterniond} as a list of 4 doubles in x, y, z, w order. 336 448 * 337 449 * @since 1.0.0 ··· 351 463 ); 352 464 353 465 /** 466 + * Stores a normalized {@link Quaterniondc} as a list of 4 doubles in x, y, z, w order. 467 + * 468 + * @since 1.0.0 469 + */ 470 + public static final Codec<Quaterniondc> QUATERNIONDC_NORMALIZED = QUATERNIOND_NORMALIZED.xmap(Function.identity(), Quaterniond::new); 471 + 472 + /** 354 473 * Stores a normalized {@link Quaternionf} as a list of 4 floats in x, y, z, w order. 355 474 * 356 475 * @since 1.0.0 ··· 370 489 ); 371 490 372 491 /** 492 + * Stores a normalized {@link Quaternionfc} as a list of 4 floats in x, y, z, w order. 493 + * 494 + * @since 1.0.0 495 + */ 496 + public static final Codec<Quaternionfc> QUATERNIONFC_NORMALIZED = QUATERNIONF_NORMALIZED.xmap(Function.identity(), Quaternionf::new); 497 + 498 + /** 373 499 * Stores a {@link Quaternionf} as either a normalized quaternion list or an axis-angle object. 374 500 * 375 501 * @since 1.0.0 ··· 380 506 ); 381 507 382 508 /** 509 + * Stores a {@link Quaternionfc} as either a normalized quaternion list or an axis-angle object. 510 + * 511 + * @since 1.0.0 512 + */ 513 + public static final Codec<Quaternionfc> QUATERNIONFC = QUATERNIONF.xmap(Function.identity(), Quaternionf::new); 514 + 515 + /** 383 516 * Stores a {@link Quaterniond} as either a normalized quaternion list or an axis-angle object. 384 517 * 385 518 * @since 1.0.0 ··· 388 521 QUATERNIOND_NORMALIZED, 389 522 AXISANGLE4D.xmap(Quaterniond::new, AxisAngle4d::new) 390 523 ); 524 + 525 + /** 526 + * Stores a {@link Quaterniondc} as either a normalized quaternion list or an axis-angle object. 527 + * 528 + * @since 1.0.0 529 + */ 530 + public static final Codec<Quaterniondc> QUATERNIONDC = QUATERNIOND.xmap(Function.identity(), Quaterniond::new); 391 531 392 532 private JomlCodecs() { 393 533 throw new IllegalStateException("Utility class");