diff --git a/include/common/qvec.hh b/include/common/qvec.hh index c78a169a..9ccf2e2c 100644 --- a/include/common/qvec.hh +++ b/include/common/qvec.hh @@ -326,7 +326,7 @@ template -[[nodiscard]] qvec floor(const qvec &v1) +[[nodiscard]] inline qvec floor(const qvec &v1) { qvec res; for (size_t i = 0; i < N; i++) { @@ -336,7 +336,17 @@ template } template -[[nodiscard]] qvec pow(const qvec &v1, const qvec &v2) +[[nodiscard]] inline qvec ceil(const qvec &v1) +{ + qvec res; + for (size_t i = 0; i < N; i++) { + res[i] = std::ceil(v1[i]); + } + return res; +} + +template +[[nodiscard]] inline qvec pow(const qvec &v1, const qvec &v2) { qvec res; for (size_t i = 0; i < N; i++) { @@ -388,11 +398,7 @@ template template [[nodiscard]] constexpr T length2(const qvec &v1) { - T len2 = 0; - for (size_t i = 0; i < N; i++) { - len2 += (v1[i] * v1[i]); - } - return len2; + return qv::dot(v1, v1); } template @@ -873,29 +879,6 @@ namespace qv [[nodiscard]] qmat2x2f inverse(const qmat2x2f &input); }; // namespace qv -// "vec3" type. legacy; eventually will be replaced entirely -#define DEPRECATE_SNIFF [[deprecated]] - - -#undef DEPRECATE_SNIFF -#define DEPRECATE_SNIFF - -template -DEPRECATE_SNIFF constexpr void VectorCopy(const TFrom &in, TTo &out) -{ - out[0] = in[0]; - out[1] = in[1]; - out[2] = in[2]; -} - -template -DEPRECATE_SNIFF constexpr void VectorScale(const TFrom &v, TScale scale, TTo &out) -{ - out[0] = v[0] * scale; - out[1] = v[1] * scale; - out[2] = v[2] * scale; -} - // returns the normalized direction from `start` to `stop` in the `dir` param // returns the distance from `start` to `stop` template diff --git a/include/light/settings.hh b/include/light/settings.hh index 6a1ea018..54d4bbb1 100644 --- a/include/light/settings.hh +++ b/include/light/settings.hh @@ -259,8 +259,8 @@ private: { // apply transform switch (_transformer) { - case vec3_transformer_t::NONE: VectorCopy(val, out); break; - case vec3_transformer_t::MANGLE_TO_VEC: VectorCopy(vec_from_mangle(val), out); break; + case vec3_transformer_t::NONE: out = val; break; + case vec3_transformer_t::MANGLE_TO_VEC: out = vec_from_mangle(val); break; case vec3_transformer_t::NORMALIZE_COLOR_TO_255: out = val; normalize_color_format(out); diff --git a/light/bounce.cc b/light/bounce.cc index 2479c1f8..3b920289 100644 --- a/light/bounce.cc +++ b/light/bounce.cc @@ -65,7 +65,7 @@ static unique_ptr MakePatch(const mbsp_t *bsp, const globalconfig_t &cf p->w = std::move(w); // cache some stuff - VectorCopy(&p->w.center()[0], p->center); + p->center = p->w.center(); p->plane = p->w.plane(); // nudge the cernter point 1 unit off diff --git a/light/entities.cc b/light/entities.cc index e9107a0c..e5f1168d 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -432,7 +432,7 @@ static void SetupSun(const globalconfig_t &cfg, vec_t light, const qvec3d &color /* calculate sun direction */ if (i == 0) { - VectorCopy(sunvec, direction); + direction = sunvec; } else { vec_t da, de; vec_t d = sqrt(sunvec[0] * sunvec[0] + sunvec[1] * sunvec[1]); @@ -974,8 +974,7 @@ void LoadEntities(const globalconfig_t &cfg, const mbsp_t *bsp) entity.settings().setSettings(*entity.epairs, false); if (entity.mangle.isChanged()) { - const qvec3f temp = vec_from_mangle(entity.mangle.vec3Value()); - VectorCopy(temp, entity.spotvec); + entity.spotvec = vec_from_mangle(entity.mangle.vec3Value()); entity.spotlight = true; if (!entity.projangle.isChanged()) { @@ -1352,7 +1351,7 @@ static void SubdividePolygon(const mface_t *face, const modelinfo_t *face_modeli // wrap cases dist[j] = dist[0]; v -= i; - VectorCopy(verts, v); + v = verts; f = b = 0; v = verts; diff --git a/light/ltface.cc b/light/ltface.cc index 4e792051..99319675 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -677,11 +677,8 @@ static void CalcPoints( surf->occluded[i] = !res.m_unoccluded; *realfacenum = res.m_actualFace != nullptr ? Face_GetNum(bsp, res.m_actualFace) : -1; - VectorCopy(res.m_position, point); - VectorCopy(res.m_interpolatedNormal, norm); - - // apply model offset after calling CalcPointNormal - point += offset; + point = res.m_position + offset; + norm = res.m_interpolatedNormal; } } @@ -745,17 +742,17 @@ static bool Lightsurf_Init( } /* Set up the plane, not including model offset */ - qplane3d *plane = &lightsurf->plane; - VectorCopy(bsp->dplanes[face->planenum].normal, plane->normal); - plane->dist = bsp->dplanes[face->planenum].dist; + qplane3d &plane = lightsurf->plane; if (face->side) { - *plane = -*plane; + plane = -bsp->dplanes[face->planenum]; + } else { + plane = bsp->dplanes[face->planenum]; } /* Set up the texorg for coordinate transformation */ lightsurf->texorg.texSpaceToWorld = TexSpaceToWorld(bsp, face); lightsurf->texorg.texinfo = &bsp->texinfo[face->texinfo]; - lightsurf->texorg.planedist = plane->dist; + lightsurf->texorg.planedist = plane.dist; /* Check for invalid texture axes */ if (std::isnan(lightsurf->texorg.texSpaceToWorld.at(0, 0))) { @@ -774,8 +771,8 @@ static bool Lightsurf_Init( /* Correct the plane for the model offset (must be done last, calculation of face extents / points needs the uncorrected plane) */ - qvec3d planepoint = (plane->normal * plane->dist) + modelinfo->offset; - plane->dist = qv::dot(plane->normal, planepoint); + qvec3d planepoint = (plane.normal * plane.dist) + modelinfo->offset; + plane.dist = qv::dot(plane.normal, planepoint); /* Correct bounding sphere */ lightsurf->origin += modelinfo->offset; @@ -968,13 +965,13 @@ static void GetLightContrib(const globalconfig_t &cfg, const light_t *entity, co col[i] *= entcol[i] * (1.0f / 255.0f); } - VectorScale(col, add * (1.0f / 255.0f), color_out); + color_out = col * add * (1.0f / 255.0f); } else { - VectorScale(entity->color.vec3Value(), add * (1.0f / 255.0f), color_out); + color_out = entity->color.vec3Value() * add * (1.0f / 255.0f); } // write normalmap contrib - VectorScale(surfpointToLightDir_out, add, normalmap_addition_out); + normalmap_addition_out = surfpointToLightDir_out * add; *dist_out = dist; } @@ -1255,10 +1252,8 @@ std::map GetDirectLighting( continue; // Write out the final color - qvec3d color; - VectorScale( - vpl.color, add, color); // color_out is expected to be in [0..255] range, vpl->color is in [0..1] range. - VectorScale(color, cfg.surflightbouncescale.floatValue(), color); + // color_out is expected to be in [0..255] range, vpl->color is in [0..1] range. + qvec3d color = (vpl.color * add) * cfg.surflightbouncescale.floatValue(); // NOTE: Skip negative lights, which would make no sense to bounce! if (LightSample_Brightness(color) <= fadegate) @@ -1287,7 +1282,7 @@ std::map GetDirectLighting( GetLightContrib( cfg, &entity, normal, origin, false, color, surfpointToLightDir, normalcontrib, &surfpointToLightDist); - VectorScale(color, entity.bouncescale.floatValue(), color); + color *= entity.bouncescale.floatValue(); // NOTE: Skip negative lights, which would make no sense to bounce! if (LightSample_Brightness(color) <= fadegate) { @@ -1409,7 +1404,7 @@ static void LightFace_Entity( const float occlusion = Dirt_GetScaleFactor(cfg, lightsurf->occlusion[i], entity, surfpointToLightDist, lightsurf); - VectorScale(color, occlusion, color); + color *= occlusion; /* Quick distance check first */ if (fabs(LightSample_Brightness(color)) <= fadegate) { @@ -1515,15 +1510,15 @@ static void LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightm value *= Dirt_GetScaleFactor(cfg, lightsurf->occlusion[i], NULL, 0.0, lightsurf); } - qvec3d color, normalcontrib; - VectorScale(sun->sunlight_color, value / 255.0, color); - VectorScale(sun->sunvec, value, normalcontrib); + qvec3d color = sun->sunlight_color * (value / 255.0); /* Quick distance check first */ if (fabs(LightSample_Brightness(color)) <= fadegate) { continue; } + qvec3d normalcontrib = sun->sunvec * value; + rs->pushRay(i, surfpoint, incoming, MAX_SKY_DIST, &color, &normalcontrib); } @@ -1755,7 +1750,7 @@ static void LightFace_BounceLightsDebug(const lightsurf_t *lightsurf, lightmapdi lightmap_t *lightmap = Lightmap_ForStyle(lightmaps, styleColor.first, lightsurf); lightsample_t *sample = &lightmap->samples[i]; - VectorCopy(patch_color, sample->color); + sample->color = patch_color; Lightmap_Save(lightmaps, lightsurf, lightmap, styleColor.first); } } @@ -1950,18 +1945,13 @@ static void LightFace_Bounce( continue; // FIXME: nudge or something dir /= dist; - const qvec3f indirect = + const qvec3d indirect = GetIndirectLighting(cfg, &vpl, color, dir, dist, lightsurf->points[i], lightsurf->normals[i]); if (LightSample_Brightness(indirect) < 0.25) continue; - qvec3d vplPos, vplDir, vplColor; - VectorCopy(vpl.pos, vplPos); - VectorCopy(dir, vplDir); - VectorCopy(indirect, vplColor); - - rs->pushRay(i, vplPos, vplDir, dist, &vplColor); + rs->pushRay(i, vpl.pos, dir, dist, &indirect); } if (!rs->numPushedRays()) @@ -1987,7 +1977,7 @@ static void LightFace_Bounce( */ if (debugmode != debugmode_bounce) { const vec_t dirtscale = Dirt_GetScaleFactor(cfg, lightsurf->occlusion[i], NULL, 0.0, lightsurf); - VectorScale(indirect, dirtscale, indirect); + indirect *= dirtscale; } lightsample_t *sample = &lightmap->samples[i]; @@ -2094,10 +2084,7 @@ static void LightFace_Bounce( colorAvg /= Nhits; lightsample_t *sample = &lightmap->samples[i]; - - qvec3d indirectTmp; - VectorCopy(colorAvg, indirectTmp); - sample->color += indirectTmp; + sample->color += colorAvg; } } @@ -2138,7 +2125,7 @@ LightFace_SurfaceLight(const lightsurf_t *lightsurf, lightmapdict_t *lightmaps) else dir /= dist; - const qvec3f indirect = GetSurfaceLighting(cfg, &vpl, dir, dist, lightsurf_normal); + const qvec3d indirect = GetSurfaceLighting(cfg, &vpl, dir, dist, lightsurf_normal); if (LightSample_Brightness(indirect) < 0.01f) // Each point contributes very little to the final result continue; @@ -2152,12 +2139,7 @@ LightFace_SurfaceLight(const lightsurf_t *lightsurf, lightmapdict_t *lightmaps) else dir /= dist; - qvec3d vplPos, vplDir, vplColor; - VectorCopy(pos, vplPos); - VectorCopy(dir, vplDir); - VectorCopy(indirect, vplColor); - - rs->pushRay(i, vplPos, vplDir, dist, &vplColor); + rs->pushRay(i, pos, dir, dist, &indirect); } if (!rs->numPushedRays()) @@ -2182,7 +2164,7 @@ LightFace_SurfaceLight(const lightsurf_t *lightsurf, lightmapdict_t *lightmaps) // Use dirt scaling on the surface lighting. const vec_t dirtscale = Dirt_GetScaleFactor(cfg, lightsurf->occlusion[i], nullptr, 0.0, lightsurf); - VectorScale(indirect, dirtscale, indirect); + indirect *= dirtscale; lightsample_t *sample = &lightmap->samples[i]; sample->color += indirect; @@ -2209,9 +2191,9 @@ static void LightFace_OccludedDebug(lightsurf_t *lightsurf, lightmapdict_t *ligh for (int i = 0; i < lightsurf->numpoints; i++) { lightsample_t *sample = &lightmap->samples[i]; if (lightsurf->occluded[i]) { - VectorCopy(qvec3f(255, 0, 0), sample->color); + sample->color = { 255, 0, 0 }; } else { - VectorCopy(qvec3f(0, 255, 0), sample->color); + sample->color = { 0, 255, 0 }; } // N.B.: Mark it as un-occluded now, to disable special handling later in the -extra/-extra4 downscaling code lightsurf->occluded[i] = false; @@ -2248,12 +2230,12 @@ static void LightFace_DebugNeighbours(lightsurf_t *lightsurf, lightmapdict_t *li if (sample_face == dump_facenum) { /* Red - the sample is on the selected face */ - VectorCopy(qvec3f(255, 0, 0), sample->color); + sample->color = { 255, 0, 0 }; } else if (has_sample_on_dumpface) { /* Green - the face has some samples on the selected face */ - VectorCopy(qvec3f(0, 255, 0), sample->color); + sample->color = { 0, 255, 0 }; } else { - VectorCopy(qvec3f(0, 0, 0), sample->color); + sample->color = { }; } // N.B.: Mark it as un-occluded now, to disable special handling later in the -extra/-extra4 downscaling code lightsurf->occluded[i] = false; @@ -2508,7 +2490,7 @@ static void LightFace_ScaleAndClamp(const lightsurf_t *lightsurf, lightmapdict_t color = qv::max(color, {0}); /* Scale and clamp any out-of-range samples */ - VectorScale(color, cfg.rangescale.floatValue(), color); + color *= cfg.rangescale.floatValue(); for (auto &c : color) { c = pow(c / 255.0f, 1.0 / cfg.lightmapgamma.floatValue()) * 255.0f; @@ -2517,7 +2499,7 @@ static void LightFace_ScaleAndClamp(const lightsurf_t *lightsurf, lightmapdict_t vec_t maxcolor = qv::max(color); if (maxcolor > 255) { - VectorScale(color, 255.0f / maxcolor, color); + color *= (255.0f / maxcolor); } } } diff --git a/light/surflight.cc b/light/surflight.cc index dddc53bf..c67d096a 100644 --- a/light/surflight.cc +++ b/light/surflight.cc @@ -125,11 +125,11 @@ static void *MakeSurfaceLightsThread(void *arg) // There are other more complex variants we could handle documented in the link above. // FIXME: we require value to be nonzero, see the check above - not sure if this matches arghrad if (cfg.sky_surface.isChanged()) { - VectorCopy(cfg.sky_surface.vec3Value(), texturecolor); + texturecolor = cfg.sky_surface.vec3Value(); } } - VectorScale(texturecolor, info->value, texturecolor); // Scale by light value + texturecolor *= info->value; // Scale by light value // Calculate intensity... float intensity = qv::max(texturecolor); @@ -139,7 +139,7 @@ static void *MakeSurfaceLightsThread(void *arg) // Normalize color... if (intensity > 1.0f) - VectorScale(texturecolor, 1.0f / intensity, texturecolor); + texturecolor *= 1.0f / intensity; // Sanity checks... Q_assert(!points.empty()); @@ -149,12 +149,12 @@ static void *MakeSurfaceLightsThread(void *arg) l.surfnormal = facenormal; l.omnidirectional = (info->flags.native & Q2_SURF_SKY) ? true : false; l.points = points; - VectorCopy(facemidpoint, l.pos); + l.pos = facemidpoint; // Store surfacelight settings... l.totalintensity = intensity * facearea; l.intensity = l.totalintensity / points.size(); - VectorCopy(texturecolor, l.color); + l.color = texturecolor; // Init bbox... l.bounds = qvec3d(0); diff --git a/light/trace_embree.cc b/light/trace_embree.cc index 696eee2d..7c17381a 100644 --- a/light/trace_embree.cc +++ b/light/trace_embree.cc @@ -850,10 +850,10 @@ public: _rays_maxdist[_numrays] = dist; _point_indices[_numrays] = i; if (color) { - VectorCopy(*color, _ray_colors[_numrays]); + _ray_colors[_numrays] = *color; } if (normalcontrib) { - VectorCopy(*normalcontrib, _ray_normalcontribs[_numrays]); + _ray_normalcontribs[_numrays] = *normalcontrib; } _ray_dynamic_styles[_numrays] = 0; _numrays++; @@ -933,10 +933,10 @@ public: _rays_maxdist[_numrays] = dist; _point_indices[_numrays] = i; if (color) { - VectorCopy(*color, _ray_colors[_numrays]); + _ray_colors[_numrays] = *color; } if (normalcontrib) { - VectorCopy(*normalcontrib, _ray_normalcontribs[_numrays]); + _ray_normalcontribs[_numrays] = *normalcontrib; } _ray_dynamic_styles[_numrays] = 0; _numrays++; diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 75441748..ed2bf35e 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -107,7 +107,7 @@ static void CheckFace(face_t *face, const mapface_t &sourceface) LogPrint("WARNING: Line {}: Healing degenerate edge ({}) at ({:.3f} {:.3} {:.3})\n", sourceface.linenum, length, p1[0], p1[1], p1[2]); for (size_t j = i + 1; j < face->w.size(); j++) - VectorCopy(face->w[j], face->w[j - 1]); + face->w[j - 1] = face->w[j]; face->w.resize(face->w.size() - 1); CheckFace(face, sourceface); break; @@ -378,8 +378,8 @@ static face_t *CreateBrushFaces(const mapentity_t *src, hullbrush_t *hullbrush, mapface.texinfo = FindTexinfo(texInfoNew); } - VectorCopy(mapface.plane.normal, plane.normal); - VectorScale(mapface.plane.normal, mapface.plane.dist, point); + plane.normal = mapface.plane.normal; + point = mapface.plane.normal * mapface.plane.dist; point -= rotate_offset; plane.dist = qv::dot(plane.normal, point); diff --git a/qbsp/csg4.cc b/qbsp/csg4.cc index fa4f48dc..bf40b263 100644 --- a/qbsp/csg4.cc +++ b/qbsp/csg4.cc @@ -82,7 +82,7 @@ face_t *NewFaceFromFace(face_t *in) newf->lmshift[0] = in->lmshift[0]; newf->lmshift[1] = in->lmshift[1]; - VectorCopy(in->origin, newf->origin); + newf->origin = in->origin; newf->radius = in->radius; return newf; @@ -90,7 +90,7 @@ face_t *NewFaceFromFace(face_t *in) void UpdateFaceSphere(face_t *in) { - VectorCopy(in->w.center(), in->origin); + in->origin = in->w.center(); in->radius = 0; for (size_t i = 0; i < in->w.size(); i++) { in->radius = max(in->radius, qv::distance2(in->w[i], in->origin)); diff --git a/qbsp/map.cc b/qbsp/map.cc index 7e1233d8..84cc37f6 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -486,9 +486,9 @@ static void TextureAxisFromPlane(const qbsp_plane_t &plane, qvec3d &xv, qvec3d & } } - VectorCopy(baseaxis[bestaxis * 3 + 1], xv); - VectorCopy(baseaxis[bestaxis * 3 + 2], yv); - VectorCopy(baseaxis[bestaxis * 3], snapped_normal); + xv = baseaxis[bestaxis * 3 + 1]; + yv = baseaxis[bestaxis * 3 + 2]; + snapped_normal = baseaxis[bestaxis * 3]; } static quark_tx_info_t ParseExtendedTX(parser_t &parser) @@ -1634,10 +1634,7 @@ static void ScaleMapFace(mapface_t *face, const qvec3d &scale) std::array new_planepts; for (int i = 0; i < 3; i++) { - qvec3d oldpt = face->planepts[i]; - qvec3d newpt = scaleM * oldpt; - - VectorCopy(newpt, new_planepts[i]); + new_planepts[i] = scaleM * face->planepts[i]; } face->set_planepts(new_planepts); @@ -1671,10 +1668,7 @@ static void RotateMapFace(mapface_t *face, const qvec3d &angles) std::array new_planepts; for (int i = 0; i < 3; i++) { - qvec3d oldpt = face->planepts[i]; - qvec3d newpt = rotation * oldpt; - - VectorCopy(newpt, new_planepts[i]); + new_planepts[i] = rotation * face->planepts[i]; } face->set_planepts(new_planepts); diff --git a/qbsp/outside.cc b/qbsp/outside.cc index 0d407e05..99de2b6f 100644 --- a/qbsp/outside.cc +++ b/qbsp/outside.cc @@ -261,16 +261,15 @@ static void WriteLeakLine(const mapentity_t *leakentity, const std::vectororigin, prevpt); - + qvec3d prevpt = leakentity->origin; + for (portal_t *portal : leakline) { - VectorCopy(portal->winding->center(), currpt); + qvec3d currpt = portal->winding->center(); // draw dots from prevpt to currpt WriteLeakTrail(ptsfile, prevpt, currpt); - VectorCopy(currpt, prevpt); + prevpt = currpt; } LogPrint("Leak file written to {}\n", options.szBSPName); diff --git a/qbsp/tjunc.cc b/qbsp/tjunc.cc index aaaea7e2..4cb6d7cc 100644 --- a/qbsp/tjunc.cc +++ b/qbsp/tjunc.cc @@ -161,8 +161,8 @@ static wedge_t *FindEdge(const qvec3d &p1, const qvec3d &p2, vec_t &t1, vec_t &t edge->next = wedge_hash[h]; wedge_hash[h] = edge; - VectorCopy(origin, edge->origin); - VectorCopy(edgevec, edge->dir); + edge->origin = origin; + edge->dir = edgevec; edge->head.next = edge->head.prev = &edge->head; edge->head.t = VECT_MAX; @@ -289,8 +289,8 @@ restart: /* rotate the point winding */ qvec3d point0 = w[0]; for (i = 1; i < w.size(); i++) - VectorCopy(w[i], w[i - 1]); - VectorCopy(point0, w[w.size() - 1]); + w[i - 1] = w[i]; + w[w.size() - 1] = point0; goto restart; } @@ -358,7 +358,7 @@ restart: superface->w.push_back({}); for (int32_t k = superface->w.size() - 1; k > j; k--) - VectorCopy(superface->w[k - 1], superface->w[k]); + superface->w[k] = superface->w[k - 1]; superface->w[j] = edge->origin + (edge->dir * v->t); goto restart; diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index 8df7fb4e..578fe652 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -177,10 +177,8 @@ static void ExportLeaf(mapentity_t *entity, node_t *node) /* * write bounding box info */ - for (int32_t i = 0; i < 3; ++i) { - dleaf.mins[i] = floor(node->bounds.mins()[i]); - dleaf.maxs[i] = ceil(node->bounds.maxs()[i]); - } + dleaf.mins = qv::floor(node->bounds.mins()); + dleaf.maxs = qv::ceil(node->bounds.maxs()); dleaf.visofs = -1; // no vis info yet @@ -218,11 +216,8 @@ static void ExportDrawNodes(mapentity_t *entity, node_t *node) const size_t ourNodeIndex = map.bsp.dnodes.size(); bsp2_dnode_t *dnode = &map.bsp.dnodes.emplace_back(); - // VectorCopy doesn't work since dest are shorts - for (int32_t i = 0; i < 3; ++i) { - dnode->mins[i] = floor(node->bounds.mins()[i]); - dnode->maxs[i] = ceil(node->bounds.maxs()[i]); - } + dnode->mins = qv::floor(node->bounds.mins()); + dnode->maxs = qv::ceil(node->bounds.maxs()); dnode->planenum = ExportMapPlane(node->planenum); dnode->firstface = node->firstface; diff --git a/vis/flow.cc b/vis/flow.cc index 7db0e1db..f9024a94 100644 --- a/vis/flow.cc +++ b/vis/flow.cc @@ -63,13 +63,13 @@ static void ClipToSeparators(const std::shared_ptr &source, const qpl // Make a plane with the three points v2 = pass->at(j) - source->at(i); sep.normal = qv::cross(v1, v2); - len_sq = sep.normal[0] * sep.normal[0] + sep.normal[1] * sep.normal[1] + sep.normal[2] * sep.normal[2]; + len_sq = qv::length2(sep.normal); // If points don't make a valid plane, skip it. if (len_sq < ON_EPSILON) continue; - VectorScale(sep.normal, 1.0 / sqrt(len_sq), sep.normal); + sep.normal *= (1.0 / sqrt(len_sq)); sep.dist = qv::dot(pass->at(j), sep.normal); //