MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / byFixingEndpointsTo

Method byFixingEndpointsTo

src/main/java/field/graphics/FLine.java:1509–1535  ·  view source on GitHub ↗

returns a new FLine by translating, rotating and scaling this line such that it's endpoints are 'start' and 'end'

(Vec3 start, Vec3 end)

Source from the content-addressed store, hash-verified

1507 Vec3 center = new Vec3().lerp(cStart, cEnd, 0.5);
1508 Vec3 center2 = new Vec3().lerp(start, end, 0.5);
1509
1510 Vec3 t = new Vec3(center2).sub(center);
1511
1512 Vec3 cD = new Vec3(cEnd).sub(cStart).normalize();
1513 Vec3 d = new Vec3(end).sub(start);
1514
1515 Quat q = cD.isNaN() || d.isNaN() ? new Quat() : new Quat().rotateTo(d, cD);
1516
1517 double s = end.distance(start) / cEnd.distance(cStart);
1518
1519 if (Double.isNaN(s)) s = 1;
1520
1521 double fs = s;
1522
1523 return byTransforming(x -> q.transform(new Vec3(x).sub(center))
1524 .mul(fs)
1525 .add(center)
1526 .add(t));
1527
1528 }
1529
1530 /**
1531 * handy method that sets the z coordinate of all the nodes in this FLine to be the `depth` of this box (or 0)
1532 *
1533 * @param of
1534 */
1535 public void depthTo(Box of) {
1536 float d = of.properties.getFloat(depth, 0f);
1537 for (Node n : nodes)
1538 n.setZ(d);

Callers 1

extrudeMethod · 0.95

Calls 14

isNaNMethod · 0.95
distanceMethod · 0.95
byTransformingMethod · 0.95
transformMethod · 0.95
rotateToMethod · 0.80
getMethod · 0.65
sizeMethod · 0.45
lerpMethod · 0.45
subMethod · 0.45
normalizeMethod · 0.45
distanceMethod · 0.45
isNaNMethod · 0.45

Tested by

no test coverage detected