<commit_before>use std::intrinsics::TypeId;
use std::any::AnyRefExt;
use std::default::Default;
use na::{Translate, Rotation, Cross};
use geometry::{Contact, contact, contacts};
use shape::{Shape, Ball, Plane, Cuboid, Capsule, Cone, Cylinder, Convex, Compound, Mesh, Segment,
            Triangle};
use math::{Scalar, Point, Vect, Isometry, HasInertiaMatrix};


macro_rules! dispatch_part(
    ($fname2: ident,
     $m1: ident, $g1: ident, $id1: ident,
     $m2: ident, $g2: ident, $id2: ident
     $(, $args: ident)*
     | $tg1: ty, $tg2: ty) => {
        if $id1 == TypeId::of::<$tg1>() && $id2 == TypeId::of::<$tg2>() {
            let exact_g1: &$tg1 = $g1.downcast_ref::<$tg1>().unwrap();
            let exact_g2: &$tg2 = $g2.downcast_ref::<$tg2>().unwrap();

            return $fname2($m1, exact_g1, $m2, exact_g2 $(, $args)*);
        }
    }
)

macro_rules! dispatch(
    ($dispatcher_name: ident, $fname: ident $(, $args: ident: $types: ty)* -> $result: ty) => {
        /// FIXME
        #[inline]
        pub fn $dispatcher_name<N, P, V, AV, M, I>(m1: &M, g1: &Shape<N, P, V, M>,
                                                   m2: &M, g2: &Shape<N, P, V, M>
                                                   $(, $args: $types)*)
                                                   -> $result
            where N:  Scalar,
                  P:  Point<N, V>,
                  V:  Vect<N> + Translate<P> + HasInertiaMatrix<I> + Cross<AV>,
                  AV: Vect<N>,
                  M:  Isometry<N, P, V> + Rotation<AV>,
                  I:  Send + Sync + Clone {
            let tg1 = g1.get_type_id();
            let tg2 = g2.get_type_id();

            // FIXME: use a hash-map instead of if-elses ?


            apply_to_all_shape_pair!(dispatch_part, $fname, m1, g1, tg1, m2, g2, tg2$(, $args)*)

            Default::default()
        }
    }
)

dispatch!(shape_against_shape, contact, prediction: N -> Option<Contact<N, P, V>>)
dispatch!(manifold_shape_against_shape, contacts, prediction: N, out: &mut Vec<Contact<N, P, V>> -> ())<commit_msg>Fix comments for `shapes_against_shapes` and `manifold_shapes_against_shapes`.<commit_after>use std::intrinsics::TypeId;
use std::any::AnyRefExt;
use na::{Translate, Rotation, Cross};
use geometry::{Contact, contact, contacts};
use shape::{Shape, Ball, Plane, Cuboid, Capsule, Cone, Cylinder, Convex, Compound, Mesh, Segment,
            Triangle};
use math::{Scalar, Point, Vect, Isometry, HasInertiaMatrix};


macro_rules! dispatch_part(
    ($fname2: ident,
     $m1: ident, $g1: ident, $id1: ident,
     $m2: ident, $g2: ident, $id2: ident
     $(, $args: ident)*
     | $tg1: ty, $tg2: ty) => {
        if $id1 == TypeId::of::<$tg1>() && $id2 == TypeId::of::<$tg2>() {
            let exact_g1: &$tg1 = $g1.downcast_ref::<$tg1>().unwrap();
            let exact_g2: &$tg2 = $g2.downcast_ref::<$tg2>().unwrap();

            return $fname2($m1, exact_g1, $m2, exact_g2 $(, $args)*);
        }
    }
)

/// Best contact between two shapes (trait objects).
#[inline]
pub fn shape_against_shape<N, P, V, AV, M, I>(m1: &M, g1: &Shape<N, P, V, M>,
                                              m2: &M, g2: &Shape<N, P, V, M>,
                                              prediction: N)
                                              -> Option<Contact<N, P, V>>
    where N:  Scalar,
          P:  Point<N, V>,
          V:  Vect<N> + Translate<P> + HasInertiaMatrix<I> + Cross<AV>,
          AV: Vect<N>,
          M:  Isometry<N, P, V> + Rotation<AV>,
          I:  Send + Sync + Clone {
    let tg1 = g1.get_type_id();
    let tg2 = g2.get_type_id();

    // FIXME: use a hash-map instead of if-elses ?
    apply_to_all_shape_pair!(dispatch_part, contact, m1, g1, tg1, m2, g2, tg2, prediction)

    None
}



/// Contacts between two shapes (trait objects).
#[inline]
pub fn manifold_shape_against_shape<N, P, V, AV, M, I>(m1: &M, g1: &Shape<N, P, V, M>,
                                                       m2: &M, g2: &Shape<N, P, V, M>,
                                                       prediction: N,
                                                       out: &mut Vec<Contact<N, P, V>>)
    where N:  Scalar,
          P:  Point<N, V>,
          V:  Vect<N> + Translate<P> + HasInertiaMatrix<I> + Cross<AV>,
          AV: Vect<N>,
          M:  Isometry<N, P, V> + Rotation<AV>,
          I:  Send + Sync + Clone {
    let tg1 = g1.get_type_id();
    let tg2 = g2.get_type_id();

    // FIXME: use a hash-map instead of if-elses ?
    apply_to_all_shape_pair!(dispatch_part, contacts, m1, g1, tg1, m2, g2, tg2, prediction, out)
}
{'fraction_non_alphanumeric': 0.16590859865713667, 'fraction_numerical': 0.020359540827377086, 'mean_word_length': 1.9793548387096773, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6956158', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1654, 'n_words': 409}