Public
Edited
Dec 3, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// https://github.com/CGAL/cgal/blob/master/Kernel_23/include/CGAL/Segment_2.h
class Segment_2 {
constructor(sp, ep) {
this._sp = sp;
this._ep = ep;
}
source() { return this._sp; }
target() { return this._ep; }
start() { return this.source(); }
end() { return this.target(); }
Segment_2() {}

// conversion from implementation class object to interface class object
Segment_2(const RSegment_2& s)
: RSegment_2(s) {}

Segment_2(RSegment_2&& s)
: RSegment_2(std::move(s)) {}

Segment_2(const Point_2 &sp, const Point_2 &ep)
: RSegment_2(typename R::Construct_segment_2()(Return_base_tag(), sp,ep)) {}

decltype(auto)
source() const
{
return R_().construct_source_2_object()(*this);
}

decltype(auto)
target() const
{
return R_().construct_target_2_object()(*this);
}

decltype(auto)
start() const
{
return source();
}

decltype(auto)
end() const
{
return target();
}

decltype(auto)
min BOOST_PREVENT_MACRO_SUBSTITUTION() const {
typename R_::Less_xy_2 less_xy;
return less_xy(source(), target()) ? source() : target();
}

decltype(auto)
max BOOST_PREVENT_MACRO_SUBSTITUTION() const {
typename R_::Less_xy_2 less_xy;
return less_xy(source(), target()) ? target() : source();
}

decltype(auto)
vertex(int i) const
{ return (i%2 == 0) ? source() : target(); }

decltype(auto)
point(int i) const
{ return vertex(i); }

decltype(auto)
operator[](int i) const
{ return vertex(i); }

bool is_horizontal() const;
bool is_vertical() const;
bool has_on(const Point_2 &p) const;
bool collinear_has_on(const Point_2 &p) const;
FT squared_length() const;

bool is_degenerate() const;

Bbox_2 bbox() const
{
return R().construct_bbox_2_object()(*this);
}

bool
operator==(const Segment_2 &s) const
{
return R().equal_2_object()(*this, s);
}

bool
operator!=(const Segment_2 &s) const
{
return !(*this == s);
}


Direction_2
direction() const
{
typename R::Construct_vector_2 construct_vector;
return Direction_2( construct_vector( source(), target()));
}

Vector_2
to_vector() const
{
typename R::Construct_vector_2 construct_vector;
return construct_vector( source(), target());
}

Line_2
supporting_line() const
{
typename R::Construct_line_2 construct_line;
return construct_line(*this);
}

Segment_2
opposite() const
{
return R().construct_opposite_segment_2_object()(*this);
}

Segment_2
transform(const Aff_transformation_2 &t) const
{
return Segment_2(t.transform(source()), t.transform(target()));
}
};


template < class R_ >
CGAL_KERNEL_INLINE
bool
Segment_2<R_>::is_horizontal() const
{
return R_().equal_y_2_object()(source(), target());
}


template < class R_ >
CGAL_KERNEL_INLINE
bool
Segment_2<R_>::is_vertical() const
{
return R_().equal_x_2_object()(source(), target());
}


template < class R_ >
CGAL_KERNEL_INLINE
bool
Segment_2<R_>::
has_on(const typename R_::Point_2 &p) const
{
return R_().are_ordered_along_line_2_object()(source(),
p,
target());
}


template < class R_ >
inline
bool
Segment_2<R_>::
collinear_has_on(const typename R_::Point_2 &p) const
{
return R_().collinear_has_on_2_object()
(*this, p);
}


template < class R_ >
CGAL_KERNEL_INLINE
typename Segment_2<R_>::FT
Segment_2<R_>::squared_length() const
{
return R_().compute_squared_length_2_object()(*this);
}


template < class R_ >
inline
bool
Segment_2<R_>::is_degenerate() const
{
return R().is_degenerate_2_object()(*this);
}



template < class R >
std::ostream &
operator<<(std::ostream &os, const Segment_2<R> &s)
{
switch(IO::get_mode(os)) {
case IO::ASCII :
return os << s.source() << ' ' << s.target();
case IO::BINARY :
return os << s.source() << s.target();
default:
return os << "Segment_2(" << s.source() << ", " << s.target() << ")";
}
}

template < class R >
std::istream &
operator>>(std::istream &is, Segment_2<R> &s)
{
typename R::Point_2 p, q;

is >> p >> q;

if (is)
s = Segment_2<R>(p, q);
return is;
}

} //namespace CGAL

#endif // CGAL_SEGMENT_2_H
Insert cell
Insert cell
Triedge.equals.toString()
Insert cell
{
const te = new Triedge();
return te.equals.toString()
}
Insert cell
Insert cell
Insert cell
// Copyright (c) 2005-2008 Fernando Luis Cacciola Carballal.
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL$
// $Id$
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Fernando Cacciola <fernando_cacciola@ciudad.com.ar>
//
class Trisegment_2 {
using Trisegment_2_ptr = std::shared_ptr<Trisegment>;

template<class K, typename Segment>
class Trisegment_2
{
typedef Trisegment_2<K, Segment> Self;

public:
typedef Trisegment_2_ptr<Self> Self_ptr ;
typedef typename K::FT FT ;

Trisegment_2 ( Segment const& aE0
, FT const& aW0
, Segment const& aE1
, FT const& aW1
, Segment const& aE2
, FT const& aW2
, Trisegment_collinearity aCollinearity
, std::size_t aID
)
: mID(aID)
{
mCollinearity = aCollinearity ;

mE[0] = aE0 ;
mE[1] = aE1 ;
mE[2] = aE2 ;

mW[0] = aW0 ;
mW[1] = aW1 ;
mW[2] = aW2 ;

switch ( mCollinearity )
{
case TRISEGMENT_COLLINEARITY_01:
mCSIdx=0; mNCSIdx=2; break ;

case TRISEGMENT_COLLINEARITY_12:
mCSIdx=1; mNCSIdx=0; break ;

case TRISEGMENT_COLLINEARITY_02:
mCSIdx=0; mNCSIdx=1; break ;

case TRISEGMENT_COLLINEARITY_ALL:
mCSIdx = mNCSIdx = (std::numeric_limits<unsigned>::max)(); break ;

case TRISEGMENT_COLLINEARITY_NONE:
mCSIdx = mNCSIdx = (std::numeric_limits<unsigned>::max)(); break ;
}
}

std::size_t& id() { return mID; }
const std::size_t& id() const { return mID; }

static Trisegment_2 null() { return Self_ptr() ; }

Trisegment_collinearity collinearity() const { return mCollinearity ; }

Segment const& e( unsigned idx ) const { CGAL_precondition(idx<3) ; return mE[idx] ; }

Segment const& e0() const { return e(0) ; }
Segment const& e1() const { return e(1) ; }
Segment const& e2() const { return e(2) ; }

FT const& w( unsigned idx ) const { CGAL_precondition(idx<3) ; return mW[idx] ; }

FT const& w0() const { return w(0) ; }
FT const& w1() const { return w(1) ; }
FT const& w2() const { return w(2) ; }

// If 2 out of the 3 edges are collinear they can be reclassified as 1 collinear edge (any of the 2) and 1 non-collinear.
// These methods returns the edges according to that classification.
// PRECONDITION: Exactly 2 out of 3 edges are collinear
Segment const& collinear_edge () const { return e(mCSIdx) ; }
Segment const& non_collinear_edge() const { return e(mNCSIdx) ; }
Segment const& other_collinear_edge() const
{
switch ( mCollinearity )
{
case TRISEGMENT_COLLINEARITY_01:
return e(1);
case TRISEGMENT_COLLINEARITY_12:
return e(2);
case TRISEGMENT_COLLINEARITY_02:
return e(2);
default:
CGAL_assertion(false);
return e(0); // arbitrary, meaningless value because a const& is expected
}
}

FT const& collinear_edge_weight() const { return w(mCSIdx) ; }
FT const& non_collinear_edge_weight() const { return w(mNCSIdx) ; }
FT const& other_collinear_edge_weight() const
{
switch ( mCollinearity )
{
case TRISEGMENT_COLLINEARITY_01:
return w(1);
case TRISEGMENT_COLLINEARITY_12:
return w(2);
case TRISEGMENT_COLLINEARITY_02:
return w(2);
default:
CGAL_assertion(false);
return w(0); // arbitrary, meaningless value because a const& is expected
}
}

Self_ptr const& child_l() const { return mChildL ; }
Self_ptr const& child_r() const { return mChildR ; }
Self_ptr const& child_t() const { return mChildT ; }

void set_child_l( Self_ptr const& aChild ) { mChildL = aChild ; }
void set_child_r( Self_ptr const& aChild ) { mChildR = aChild ; }
void set_child_t( Self_ptr const& aChild ) { mChildT = aChild ; }

enum SEED_ID { LEFT, RIGHT, THIRD } ;

// Indicates which of the seeds is collinear for a normal collinearity case.
// PRECONDITION: The collinearity is normal.
SEED_ID degenerate_seed_id() const
{
Trisegment_collinearity c = collinearity();

return c == TRISEGMENT_COLLINEARITY_01 ? LEFT : c == TRISEGMENT_COLLINEARITY_12 ? RIGHT : THIRD ;
}

static void print ( std::ostream& os, Self const& aTri, int aDepth )
{
const std::string lPadding = std::string(2 * aDepth, ' ');

os << lPadding << "[&: " << &aTri << " ID: " << aTri.id() << "\n"
<< lPadding << "\tE" << aTri.e0().mID << " E" << aTri.e1().mID << " E" << aTri.e2().mID << "\n"
<< lPadding << "\t" << s2str(aTri.e0()) << " w = " << n2str(aTri.w0()) << ";" << "\n"
<< lPadding << "\t" << s2str(aTri.e1()) << " w = " << n2str(aTri.w1()) << ";" << "\n"
<< lPadding << "\t" << s2str(aTri.e2()) << " w = " << n2str(aTri.w2()) << ";" << "\n"
<< lPadding << "\tCollinearity: " << trisegment_collinearity_to_string(aTri.collinearity()) << "\n"
<< lPadding << "]\n" << std::flush;
}

static void recursive_print ( std::ostream& os, Self_ptr const& aTriPtr, int aDepth )
{
const std::string lPadding = std::string(2 * aDepth, ' ');

os << "\n" ;

if ( aTriPtr )
{
print(os, *aTriPtr, aDepth);

if ( aTriPtr->child_l() )
{
os << lPadding << "left child:" ;
recursive_print(os,aTriPtr->child_l(),aDepth+1);
}

if ( aTriPtr->child_r() )
{
os << lPadding << "right child:" ;
recursive_print(os,aTriPtr->child_r(),aDepth+1);
}

if ( aTriPtr->child_t() )
{
os << lPadding << "third child:" ;
recursive_print(os,aTriPtr->child_t(),aDepth+1);
}
}
else
{
os << "{null}" ;
}
}

friend std::ostream& operator << ( std::ostream& os, Self const& aTrisegment )
{
print(os, aTrisegment, 0);
return os ;
}

friend std::ostream& operator << ( std::ostream& os, Self_ptr const& aTriPtr )
{
if(aTriPtr)
print(os, *aTriPtr, 0);
else
os << "{null}" ;
return os ;
}

private :
std::size_t mID;
Segment mE[3];
FT mW[3];
Trisegment_collinearity mCollinearity ;
unsigned mCSIdx, mNCSIdx ;

Self_ptr mChildL ;
Self_ptr mChildR ;

// this is the potential child of e2-e0, if it exists. It is used only in the configuration
// of e0 and e2 collinear as the common child gives where the bisector starts (as it is not
// necessarily the middle of the gap between e2 and e0).
Self_ptr mChildT ;
} ;

} // end namespace CGAL

#endif // CGAL_SLS_TRISEGMENT_H
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more