All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.dragonfly.mesh.shape.package.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2023 dragonfly.ai
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ai.dragonfly.mesh

import slash.vector.*
import narr.*

package object shape {

  def addQuad(a: Int, b: Int, c: Int, d: Int, triangles: NArray[Triangle], t: Int): Int = if (t < triangles.length) {
    triangles(t) = Triangle(a, b, c)
    triangles(t + 1) = Triangle(a, d, b)
    t + 2
  } else t

  inline def validateVertex(v:Int, vertices:NArray[Vec[3]]): Boolean = vertices.length > v

  inline def addQuad(a: Int, b: Int, c: Int, d: Int, triangles: NArray[Triangle], t: Int, vertices:NArray[Vec[3]]): Int = {

    if (
      t < triangles.length &&
      validateVertex(a, vertices) &&
      validateVertex(b, vertices) &&
      validateVertex(c, vertices)
    ) {
      triangles(t) = Triangle(a, b, c)
      t + 1 + (if (validateVertex(d, vertices)) {
        triangles(t + 1) = Triangle(a, d, b)
        1
      } else 0)
    } else t
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy