source: trunk/Point.php

Last change on this file was 95, checked in by chronos, 3 years ago
  • Modified: Updated Common package.
  • Added: Explicit types for better type checking.
  • Fixed: Support for php 8.0.
File size: 427 bytes
Line 
1<?php
2
3class Point
4{
5 public int $X;
6 public int $Y;
7
8 function __construct(int $X, int $Y)
9 {
10 $this->X = $X;
11 $this->Y = $Y;
12 }
13}
14
15function NewPoint(int $X, int $Y): Point
16{
17 $Point = new Point($X, $Y);
18 return $Point;
19}
20
21/* Linear interpolation between two points */
22function Interpolation(Point $P1, Point $P2, $X): float
23{
24 $Y = ($P2->Y - $P1->Y) / ($P2->X - $P1->X) * ($X - $P1->X) + $P1->Y;
25 return $Y;
26}
Note: See TracBrowser for help on using the repository browser.