Pt2

Struct Pt2 

Source
pub struct Pt2 {
    pub x: f64,
    pub y: f64,
}
Expand description

A 2D point.

Fields§

§x: f64§y: f64

Implementations§

Source§

impl Pt2

Source

pub fn new(x: f64, y: f64) -> Pt2

Examples found in repository?
examples/view_cubic_bezier_chain.rs (line 34)
32fn main() {
33    let mut curve = dim2::CubicBezierChain2D::new(
34        Pt2::new(0.0, 0.0),
35        Pt2::new(40.0, -20.0),
36        Pt2::new(40.0, 80.0),
37        Pt2::new(0.0, 40.0),
38        24,
39    );
40    curve.add(20.0, Pt2::new(-30.0, 50.0), Pt2::new(-50.0, 40.0), 12);
41
42    let mut viewer = Viewer::new(0.5, 0.25, 6);
43    viewer.add_cubic_bezier_chain2d(&curve);
44    scad_file!(32, "output/view_cubic_bezier_chain.scad",
45        viewer.into_scad();
46    );
47}
More examples
Hide additional examples
examples/bottle.rs (line 43)
41fn make_bottle() {
42    let mut outside_profile = Pt2s::new();
43    outside_profile.push(Pt2::new(0.0, 125.0));
44    outside_profile.append(&mut dim2::cubic_bezier(
45        Pt2::new(19.0, 125.0),
46        Pt2::new(22.5, 110.0),
47        Pt2::new(32.5, 105.0),
48        Pt2::new(32.5, 100.0),
49        6,
50    ));
51    outside_profile.append(&mut dim2::quadratic_bezier(
52        Pt2::new(32.5, 5.0),
53        Pt2::new(32.5, 0.0),
54        Pt2::new(27.5, 0.0),
55        6,
56    ));
57    outside_profile.push(Pt2::new(0.0, 0.0));
58
59    let mut inside_profile = Pt2s::new();
60    inside_profile.push(Pt2::new(0.0, 140.0));
61    inside_profile.push(Pt2::new(16.0, 140.0));
62    inside_profile.append(&mut dim2::cubic_bezier(
63        Pt2::new(16.0, 125.0),
64        Pt2::new(20.5, 110.0),
65        Pt2::new(30.5, 105.0),
66        Pt2::new(30.5, 100.0),
67        6,
68    ));
69    inside_profile.append(&mut dim2::quadratic_bezier(
70        Pt2::new(30.5, 7.0),
71        Pt2::new(30.5, 2.0),
72        Pt2::new(25.5, 2.0),
73        6,
74    ));
75    inside_profile.push(Pt2::new(0.0, 2.0));
76
77    let outside = rotate_extrude!(angle=360.0, convexity=10, fn=128, polygon!(outside_profile););
78    let inside = rotate_extrude!(angle=360.0, convexity=10, fn=128, polygon!(inside_profile););
79
80    let threaded_rod = translate!([0.0,0.0,120.0], metric_thread::threaded_rod(40, 15.0, 128, 0.0, 180.0, false, false););
81
82    let bottle = outside + threaded_rod - inside;
83
84    bottle.save("output/bottle.scad");
85}
examples/cup.rs (line 33)
27fn main() {
28    let segments: u64 = 72;
29    let cup_segments: u64 = 144;
30    let slices: u64 = 48;
31
32    let mut cup_blank_profile = Pt2s::new();
33    cup_blank_profile.push(Pt2::new(0.0, 0.0));
34    cup_blank_profile.append(&mut dim2::cubic_bezier(
35        Pt2::new(40.0, 0.0),
36        Pt2::new(40.0, 33.0),
37        Pt2::new(60.0, 66.0),
38        Pt2::new(60.0, 100.0),
39        slices,
40    ));
41    cup_blank_profile.push(Pt2::new(0.0, 100.0));
42
43    let cup_blank = rotate_extrude!(angle=360.0, convexity=2, fn=cup_segments,
44        polygon!(cup_blank_profile);
45    );
46
47    let mut cup_inner_profile = Pt2s::new();
48    cup_inner_profile.push(Pt2::new(0.0, 3.0));
49    cup_inner_profile.append(&mut dim2::cubic_bezier(
50        Pt2::new(37.0, 3.0),
51        Pt2::new(37.0, 33.0),
52        Pt2::new(57.0, 66.0),
53        Pt2::new(57.0, 103.0),
54        slices,
55    ));
56    cup_inner_profile.push(Pt2::new(0.0, 103.0));
57
58    let cup_inner = rotate_extrude!(angle=360.0, convexity=1, fn=cup_segments,
59        polygon!(cup_inner_profile);
60    );
61
62    let handle_path = dim3::cubic_bezier(
63        Pt3::new(37.0, 20.0, 0.0),
64        Pt3::new(70.0, 30.0, 0.0),
65        Pt3::new(120.0, 90.0, 0.0),
66        Pt3::new(57.0, 90.0, 0.0),
67        segments,
68    );
69
70    let handle_profile = dim2::rounded_rect(8.0, 20.0, 2.5, segments, true);
71    let mut handle = Polyhedron::sweep(&handle_profile, &handle_path, 0.0, false);
72    handle.rotate_x(90.0);
73
74    let cup = cup_blank + handle.into_scad_with_convexity(2) - cup_inner;
75
76    cup.save("output/cup.scad");
77}
Source

pub fn dot(self, rhs: Pt2) -> f64

Source

pub fn len2(self) -> f64

Source

pub fn len(self) -> f64

Source

pub fn normalize(&mut self)

Source

pub fn normalized(self) -> Pt2

Source

pub fn rotate(&mut self, degrees: f64)

Source

pub fn rotated(self, degrees: f64) -> Pt2

Source

pub fn lerp(self, b: Pt2, t: f64) -> Pt2

Source

pub fn to_xz(self) -> Pt3

Source

pub fn as_pt3(self, z: f64) -> Pt3

Examples found in repository?
examples/bezier_star_sweep.rs (line 52)
38fn main() {
39    let output_viewer = false;
40    let path = BezierStar::new(7, 20.0, 9.0, 40.0, 15.0, 12);
41    let profile = BezierStar::new(7, 2.0, 0.9, 4.0, 1.5, 12);
42
43    if output_viewer {
44        let mut viewer = Viewer::new(0.5, 0.25, 6);
45        viewer.add_bezier_star(&path);
46        let mut small_viewer = Viewer::new(0.05, 0.025, 6);
47        small_viewer.add_bezier_star(&profile);
48        scad_file!(32, "output/bezier_star_sweep.scad",
49            small_viewer.into_scad() + viewer.into_scad();
50        );
51    } else {
52        let path = Pt3s::from_pt3s(path.gen_points().iter().map(|p| p.as_pt3(0.0)).collect());
53        let profile = profile.gen_points();
54        let star_swept = Polyhedron::sweep(&profile, &path, 7.0 * 360.0, true);
55        scad_file!(32, "output/bezier_star_sweep.scad",
56            star_swept.into_scad();
57        );
58    }
59}

Trait Implementations§

Source§

impl Add for Pt2

Source§

type Output = Pt2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Pt2) -> <Pt2 as Add>::Output

Performs the + operation. Read more
Source§

impl AddAssign for Pt2

Source§

fn add_assign(&mut self, rhs: Pt2)

Performs the += operation. Read more
Source§

impl Clone for Pt2

Source§

fn clone(&self) -> Pt2

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pt2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Pt2

Source§

fn default() -> Pt2

Returns the “default value” for a type. Read more
Source§

impl Display for Pt2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Div<f64> for Pt2

Source§

type Output = Pt2

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> <Pt2 as Div<f64>>::Output

Performs the / operation. Read more
Source§

impl DivAssign<f64> for Pt2

Source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl Index<usize> for Pt2

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &<Pt2 as Index<usize>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Pt2

Source§

fn index_mut(&mut self, index: usize) -> &mut <Pt2 as Index<usize>>::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Mul<f64> for Pt2

Source§

type Output = Pt2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> <Pt2 as Mul<f64>>::Output

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Pt2

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl Neg for Pt2

Source§

type Output = Pt2

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Pt2 as Neg>::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Pt2

Source§

fn eq(&self, other: &Pt2) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for Pt2

Source§

type Output = Pt2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Pt2) -> <Pt2 as Sub>::Output

Performs the - operation. Read more
Source§

impl SubAssign for Pt2

Source§

fn sub_assign(&mut self, rhs: Pt2)

Performs the -= operation. Read more
Source§

impl Copy for Pt2

Source§

impl StructuralPartialEq for Pt2

Auto Trait Implementations§

§

impl Freeze for Pt2

§

impl RefUnwindSafe for Pt2

§

impl Send for Pt2

§

impl Sync for Pt2

§

impl Unpin for Pt2

§

impl UnwindSafe for Pt2

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.